Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ValidatesExpenseId | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| parseExpenseId | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Expense\Infrastructure\Http; |
| 6 | |
| 7 | use App\Expense\Domain\ValueObject\ExpenseId; |
| 8 | use InvalidArgumentException; |
| 9 | |
| 10 | /** |
| 11 | * Parses a path {id} into an ExpenseId. A malformed id is a 404, not a 400: it |
| 12 | * simply cannot match any expense, so controllers treat null as "not found". |
| 13 | */ |
| 14 | trait ValidatesExpenseId |
| 15 | { |
| 16 | private function parseExpenseId(string $id): ?ExpenseId |
| 17 | { |
| 18 | try { |
| 19 | return new ExpenseId($id); |
| 20 | } catch (InvalidArgumentException) { |
| 21 | return null; |
| 22 | } |
| 23 | } |
| 24 | } |