Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DeleteTripHandler
100.00% covered (success)
100.00%
5 / 5
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%
4 / 4
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\Infrastructure\Storage\ImageStorage;
8use App\Trip\Application\TripAccess;
9use App\Trip\Domain\TripRepository;
10use App\Trip\Domain\ValueObject\TripId;
11
12final readonly class DeleteTripHandler
13{
14    public function __construct(
15        private TripAccess $access,
16        private TripRepository $trips,
17        private ImageStorage $storage,
18    ) {
19    }
20
21    public function handle(DeleteTripCommand $command): void
22    {
23        // Owner only: stranger → TripNotFound (404), non-owner member → TripAccessDenied (403).
24        $trip = $this->access->getForManage(new TripId($command->tripId), $command->userId);
25
26        $imageName = $trip->imageName();
27        $this->trips->remove($trip);
28        $this->storage->delete($imageName);
29    }
30}