Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ValidatesInvitationId
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 parseInvitationId
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Trip\Infrastructure\Http;
6
7use App\Trip\Domain\ValueObject\InvitationId;
8use InvalidArgumentException;
9
10/**
11 * Parses a path {id} into an InvitationId. A malformed id is a 404, not a 400 —
12 * it cannot match any invitation (mirrors ValidatesTripId).
13 */
14trait ValidatesInvitationId
15{
16    private function parseInvitationId(string $id): ?InvitationId
17    {
18        try {
19            return new InvitationId($id);
20        } catch (InvalidArgumentException) {
21            return null;
22        }
23    }
24}