Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
6 / 6 |
|
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| MethodNotAllowedException | |
100.00% |
6 / 6 |
|
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
|
100.00% |
2 / 2 |
3.33 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
75.00% |
3 / 4 |
|
50.00% |
1 / 2 |
|
100.00% |
1 / 1 |
2.50 | |||
| allowedMethods | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Router\Exception; |
| 6 | |
| 7 | /** @psalm-api */ |
| 8 | final class MethodNotAllowedException extends RuntimeException |
| 9 | { |
| 10 | /** @var list<string> */ |
| 11 | private array $allowedMethods; |
| 12 | |
| 13 | /** @param list<string> $allowedMethods */ |
| 14 | public function __construct(array $allowedMethods, string $message = '') |
| 15 | { |
| 16 | $this->allowedMethods = array_values(array_unique(array_map( |
| 17 | static fn(string $method): string => strtoupper($method), |
| 18 | $allowedMethods, |
| 19 | ))); |
| 20 | |
| 21 | parent::__construct($message !== '' ? $message : 'Method not allowed'); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @psalm-api |
| 26 | * @return list<string> |
| 27 | */ |
| 28 | public function allowedMethods(): array |
| 29 | { |
| 30 | return $this->allowedMethods; |
| 31 | } |
| 32 | } |