Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php declare(strict_types=1); |
||
15 | final class MiddlewareRunner |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $options; |
||
21 | |||
22 | /** |
||
23 | * @var MiddlewareInterface[] |
||
24 | */ |
||
25 | private $middlewares; |
||
26 | |||
27 | /** |
||
28 | * @var AnnotationReader |
||
29 | 1 | */ |
|
30 | private $annotationReader; |
||
31 | 1 | ||
32 | 1 | /** |
|
33 | 1 | * @var string |
|
34 | */ |
||
35 | private $id; |
||
36 | |||
37 | /** |
||
38 | * MiddlewareRunner constructor. |
||
39 | * @param array $options |
||
40 | * @param MiddlewareInterface[] $middlewares |
||
41 | 1 | */ |
|
42 | public function __construct(array $options, MiddlewareInterface ...$middlewares) |
||
49 | |||
50 | /** |
||
51 | * @param RequestInterface $request |
||
52 | * @return CancellablePromiseInterface |
||
53 | */ |
||
54 | 1 | View Code Duplication | public function pre( |
71 | |||
72 | /** |
||
73 | 1 | * @param ResponseInterface $response |
|
74 | * @return CancellablePromiseInterface |
||
75 | */ |
||
76 | 1 | View Code Duplication | public function post( |
93 | |||
94 | 1 | /** |
|
95 | * @param Throwable $throwable |
||
96 | * @return CancellablePromiseInterface |
||
97 | */ |
||
98 | 1 | View Code Duplication | public function error( |
115 | |||
116 | /** |
||
117 | * Sort the middlewares by priority. |
||
118 | * |
||
119 | * @param string $method |
||
120 | * @param MiddlewareInterface[] $middlewares |
||
121 | * @return array |
||
122 | */ |
||
123 | protected function orderMiddlewares(string $method, MiddlewareInterface ...$middlewares): array |
||
131 | |||
132 | private function getPriority(string $method, MiddlewareInterface $middleware): int |
||
147 | } |
||
148 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..