1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Meraki\Route\Exception; |
||
5 | |||
6 | use RuntimeException; |
||
7 | use Meraki\Route\Exception as RouteException; |
||
8 | use LogicException; |
||
9 | |||
10 | /** |
||
11 | * Exception used when the method of a route could not be matched to the request. |
||
12 | * |
||
13 | * @author Nathan Bishop <[email protected]> (https://nathanbishop.name) |
||
14 | * @copyright 2019 Nathan Bishop |
||
15 | * @license The MIT license. |
||
16 | */ |
||
17 | final class MethodNotMatched extends RuntimeException implements RouteException |
||
18 | { |
||
19 | /** |
||
20 | * |
||
21 | */ |
||
22 | public const EQUIVALENT_STATUS_CODE = 405; |
||
23 | |||
24 | /** |
||
25 | * @var string [$failedMethod description] |
||
26 | */ |
||
27 | private $failedMethod; |
||
28 | |||
29 | /** |
||
30 | * @var string[] [$allowedMethods description] |
||
31 | */ |
||
32 | private $allowedMethods; |
||
33 | |||
34 | /** |
||
35 | * [__construct description] |
||
36 | * |
||
37 | * @param string $failedMethod [description] |
||
38 | * @param string[] $allowedMethods [description] |
||
39 | */ |
||
40 | public function __construct(string $failedMethod, array $allowedMethods = []) |
||
41 | { |
||
42 | $this->failedMethod = strtoupper($failedMethod); |
||
43 | $this->allowedMethods = array_map('strtoupper', $allowedMethods); |
||
44 | |||
45 | if (in_array($this->failedMethod, $this->allowedMethods)) { |
||
46 | throw new LogicException('The method that failed the match should not be in the allowed methods.'); |
||
47 | } |
||
48 | |||
49 | parent::__construct($this->generateMessage(), self::EQUIVALENT_STATUS_CODE); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * [getFailedMethod description] |
||
54 | * |
||
55 | * @return string [description] |
||
56 | */ |
||
57 | public function getFailedMethod(): string |
||
58 | { |
||
59 | return $this->failedMethod; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * [getAllowedMethods description] |
||
64 | * |
||
65 | * @return string[] [description] |
||
66 | */ |
||
67 | public function getAllowedMethods(): array |
||
68 | { |
||
69 | return $this->allowedMethods; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * [generateMessage description] |
||
74 | * |
||
75 | * @return strings [description] |
||
0 ignored issues
–
show
|
|||
76 | */ |
||
77 | private function generateMessage(): string |
||
78 | { |
||
79 | $message = sprintf('The "%s" method could not be matched.', $this->failedMethod); |
||
80 | |||
81 | if (!empty($this->allowedMethods)) { |
||
82 | $message .= sprintf(' Try one of the following: %s', implode(', ', $this->allowedMethods)); |
||
83 | } |
||
84 | |||
85 | return $message; |
||
0 ignored issues
–
show
|
|||
86 | } |
||
87 | } |
||
88 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths