These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Chubbyphp\ApiHttp\ApiProblem\ClientError; |
||
6 | |||
7 | use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; |
||
8 | |||
9 | View Code Duplication | final class MethodNotAllowed extends AbstractApiProblem |
|
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $method; |
||
15 | |||
16 | /** |
||
17 | * @var string[] |
||
18 | */ |
||
19 | private $allowedMethods = []; |
||
20 | |||
21 | /** |
||
22 | * @param string $method, |
||
0 ignored issues
–
show
|
|||
23 | * @param string[] $allowedMethods |
||
24 | * @param string|null $detail |
||
25 | * @param string|null $instance |
||
26 | */ |
||
27 | 2 | public function __construct(string $method, array $allowedMethods, string $detail = null, string $instance = null) |
|
28 | { |
||
29 | 2 | parent::__construct( |
|
30 | 2 | 'https://tools.ietf.org/html/rfc2616#section-10.4.6', |
|
31 | 2 | 405, |
|
32 | 2 | 'Method Not Allowed', |
|
33 | $detail, |
||
34 | $instance |
||
35 | ); |
||
36 | |||
37 | 2 | $this->method = $method; |
|
38 | 2 | $this->allowedMethods = $allowedMethods; |
|
39 | 2 | } |
|
40 | |||
41 | /** |
||
42 | * @return array |
||
43 | */ |
||
44 | 2 | public function getHeaders(): array |
|
45 | { |
||
46 | 2 | if ([] === $this->allowedMethods) { |
|
47 | 1 | return []; |
|
48 | } |
||
49 | |||
50 | 1 | return ['Allow' => implode(',', $this->allowedMethods)]; |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | 2 | public function getMethod(): string |
|
57 | { |
||
58 | 2 | return $this->method; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return string[] |
||
63 | */ |
||
64 | 2 | public function getAllowedMethods(): array |
|
65 | { |
||
66 | 2 | return $this->allowedMethods; |
|
67 | } |
||
68 | } |
||
69 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.