Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UpdateTripHandler
100.00% covered (success)
100.00%
10 / 10
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%
9 / 9
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\DateRange;
8use App\Shared\Domain\ValueObject\Money;
9use App\Shared\Infrastructure\Storage\SignedImageUrl;
10use App\Trip\Application\Query\TripView;
11use App\Trip\Application\TripAccess;
12use App\Trip\Domain\TripRepository;
13use App\Trip\Domain\ValueObject\TripId;
14use App\Trip\Domain\ValueObject\TripRole;
15
16final readonly class UpdateTripHandler
17{
18    public function __construct(
19        private TripAccess $access,
20        private TripRepository $trips,
21        private SignedImageUrl $imageUrls,
22    ) {
23    }
24
25    public function handle(UpdateTripCommand $command): TripView
26    {
27        // Owner only: a stranger gets TripNotFound (404), a non-owner member
28        // TripAccessDenied (403).
29        $trip = $this->access->getForManage(new TripId($command->tripId), $command->userId);
30
31        // Currency is fixed at creation; the budget stays in the trip currency.
32        $trip->update(
33            $command->name,
34            $command->destination,
35            DateRange::fromIso($command->startDate, $command->endDate),
36            new Money($command->budgetAmount, $trip->currency()),
37        );
38
39        $this->trips->save($trip);
40
41        return TripView::fromTrip($trip, TripRole::OWNER, $this->imageUrls->for($trip->imageName()));
42    }
43}