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 |
||
14 | class Transport |
||
15 | { |
||
16 | const TOKEN_FUTUERSIMPLE_NAME = 'X-Futuresimple-Token'; |
||
17 | const TOKEN_PIPEJUMP_NAME = 'X-Pipejump-Auth'; |
||
18 | |||
19 | /** @var ClientInterface */ |
||
20 | private $client; |
||
21 | |||
22 | /** @var string */ |
||
23 | private $token; |
||
24 | |||
25 | /** @var ResponseInterface */ |
||
26 | protected $lastResponse; |
||
27 | |||
28 | /** |
||
29 | * @param string $token |
||
30 | * @param ClientInterface $client |
||
|
|||
31 | */ |
||
32 | public function __construct($token = '', ClientInterface $client = null) |
||
38 | |||
39 | /** |
||
40 | * @param string $uri |
||
41 | * @param string $key |
||
42 | * @param array $options |
||
43 | * |
||
44 | * @return array|bool |
||
45 | */ |
||
46 | View Code Duplication | public function get($uri, $key = null, array $options = []) |
|
54 | |||
55 | /** |
||
56 | * @param string $uri |
||
57 | * @param string $key |
||
58 | * @param array $options |
||
59 | * |
||
60 | * @return array|bool |
||
61 | */ |
||
62 | View Code Duplication | public function post($uri, $key = null, array $options = []) |
|
70 | |||
71 | /** |
||
72 | * @param string $uri |
||
73 | * @param string $key |
||
74 | * @param array $options |
||
75 | * |
||
76 | * @return array|bool |
||
77 | */ |
||
78 | View Code Duplication | public function put($uri, $key = null, array $options = []) |
|
86 | |||
87 | /** |
||
88 | * @param string $uri |
||
89 | * @param string $key |
||
90 | * @param array $options |
||
91 | * |
||
92 | * @return array|bool |
||
93 | */ |
||
94 | View Code Duplication | public function delete($uri, $key = null, array $options = []) |
|
102 | |||
103 | /** |
||
104 | * @param ResponseInterface $response |
||
105 | * @param string $key |
||
106 | * |
||
107 | * @throws RepresentationErrorException on 422 response |
||
108 | * @throws ClientException on 4xx errors |
||
109 | * @throws ServerException on 5xx errors |
||
110 | * @throws BadResponseException when key is not found in response data |
||
111 | * @return array|bool |
||
112 | */ |
||
113 | private function processResponse(ResponseInterface $response, $key = null) |
||
155 | |||
156 | /** |
||
157 | * @param string $uri |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | protected function getUri($uri) |
||
165 | |||
166 | /** |
||
167 | * @param array $options |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | private function getOptions(array $options) |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | public function getToken() |
||
190 | |||
191 | /** |
||
192 | * @param string $token |
||
193 | * |
||
194 | * @return $this |
||
195 | */ |
||
196 | public function setToken($token) |
||
202 | } |
||
203 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.