Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CreateTripHandler | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Trip\Application\Command; |
| 6 | |
| 7 | use App\Shared\Domain\ValueObject\Currency; |
| 8 | use App\Shared\Domain\ValueObject\DateRange; |
| 9 | use App\Shared\Domain\ValueObject\Money; |
| 10 | use App\Trip\Domain\Trip; |
| 11 | use App\Trip\Domain\TripRepository; |
| 12 | use App\Trip\Domain\ValueObject\OwnerId; |
| 13 | use App\Trip\Domain\ValueObject\TripId; |
| 14 | |
| 15 | final readonly class CreateTripHandler |
| 16 | { |
| 17 | public function __construct(private TripRepository $trips) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | public function handle(CreateTripCommand $command): TripId |
| 22 | { |
| 23 | $currency = new Currency($command->currency); |
| 24 | |
| 25 | $trip = Trip::create( |
| 26 | TripId::generate(), |
| 27 | new OwnerId($command->ownerId), |
| 28 | $command->name, |
| 29 | $command->destination, |
| 30 | DateRange::fromIso($command->startDate, $command->endDate), |
| 31 | $currency, |
| 32 | new Money($command->budgetAmount, $currency), |
| 33 | ); |
| 34 | |
| 35 | $this->trips->save($trip); |
| 36 | |
| 37 | return $trip->id(); |
| 38 | } |
| 39 | } |