Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DeclineInvitationHandler
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
5
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%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace App\Trip\Application\Command;
6
7use App\Trip\Domain\Exceptions\InvitationNotFound;
8use App\Trip\Domain\TripInvitationRepository;
9use App\Trip\Domain\ValueObject\InvitationId;
10use App\Trip\Domain\ValueObject\MemberId;
11
12/**
13 * The invitee declines: the invitation is marked declined, no member row created.
14 */
15final readonly class DeclineInvitationHandler
16{
17    public function __construct(private TripInvitationRepository $invitations)
18    {
19    }
20
21    public function handle(DeclineInvitationCommand $command): void
22    {
23        $invitationId = new InvitationId($command->invitationId);
24        $invitation = $this->invitations->ofId($invitationId);
25
26        if ($invitation === null
27            || !$invitation->inviteeId()->equals(new MemberId($command->userId))
28            || !$invitation->isPending()) {
29            throw InvitationNotFound::withId($invitationId);
30        }
31
32        $invitation->decline();
33        $this->invitations->save($invitation);
34    }
35}