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); |
||
30 | trait KitsuTrait { |
||
31 | |||
32 | /** |
||
33 | * The request builder for the MAL API |
||
34 | * @var MALRequestBuilder |
||
35 | */ |
||
36 | protected $requestBuilder; |
||
37 | |||
38 | /** |
||
39 | * Set the request builder object |
||
40 | * |
||
41 | * @param KitsuRequestBuilder $requestBuilder |
||
42 | * @return self |
||
43 | */ |
||
44 | public function setRequestBuilder($requestBuilder): self |
||
49 | |||
50 | /** |
||
51 | * Create a request object |
||
52 | * |
||
53 | * @param string $type |
||
54 | * @param string $url |
||
55 | * @param array $options |
||
56 | * @return \Amp\Artax\Response |
||
57 | */ |
||
58 | public function setUpRequest(string $type, string $url, array $options = []) |
||
92 | |||
93 | /** |
||
94 | * Make a request |
||
95 | * |
||
96 | * @param string $type |
||
97 | * @param string $url |
||
98 | * @param array $options |
||
99 | * @return Response |
||
100 | */ |
||
101 | private function getResponse(string $type, string $url, array $options = []) |
||
118 | |||
119 | /** |
||
120 | * Make a request |
||
121 | * |
||
122 | * @param string $type |
||
123 | * @param string $url |
||
124 | * @param array $options |
||
125 | * @return array |
||
126 | */ |
||
127 | View Code Duplication | private function request(string $type, string $url, array $options = []): array |
|
147 | |||
148 | /** |
||
149 | * Remove some boilerplate for get requests |
||
150 | * |
||
151 | * @param array $args |
||
152 | * @return array |
||
153 | */ |
||
154 | protected function getRequest(...$args): array |
||
158 | |||
159 | /** |
||
160 | * Remove some boilerplate for patch requests |
||
161 | * |
||
162 | * @param array $args |
||
163 | * @return array |
||
164 | */ |
||
165 | protected function patchRequest(...$args): array |
||
169 | |||
170 | /** |
||
171 | * Remove some boilerplate for post requests |
||
172 | * |
||
173 | * @param array $args |
||
174 | * @return array |
||
175 | */ |
||
176 | View Code Duplication | protected function postRequest(...$args): array |
|
197 | |||
198 | /** |
||
199 | * Remove some boilerplate for delete requests |
||
200 | * |
||
201 | * @param array $args |
||
202 | * @return bool |
||
203 | */ |
||
204 | protected function deleteRequest(...$args): bool |
||
209 | } |
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..