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
ValidatesTripId
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
 parseTripId
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\TripId;
8use InvalidArgumentException;
9
10/**
11 * Parses a path {id} into a TripId. A malformed id is not a 400 but a 404: it
12 * simply cannot match any trip, so controllers treat null as "not found".
13 */
14trait ValidatesTripId
15{
16    private function parseTripId(string $id): ?TripId
17    {
18        try {
19            return new TripId($id);
20        } catch (InvalidArgumentException) {
21            return null;
22        }
23    }
24}