Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateTripHandler
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Trip\Application\Command;
6
7use App\Shared\Domain\ValueObject\Currency;
8use App\Shared\Domain\ValueObject\DateRange;
9use App\Shared\Domain\ValueObject\Money;
10use App\Trip\Domain\Trip;
11use App\Trip\Domain\TripRepository;
12use App\Trip\Domain\ValueObject\OwnerId;
13use App\Trip\Domain\ValueObject\TripId;
14
15final 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}