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 |
||
18 | class Client |
||
19 | { |
||
20 | /** |
||
21 | * @var \GuzzleHttp\Client |
||
22 | */ |
||
23 | private $client; |
||
24 | |||
25 | /** |
||
26 | * @var Headers |
||
27 | */ |
||
28 | private $headers; |
||
29 | |||
30 | /** |
||
31 | * @param ClientInterface $client |
||
32 | */ |
||
33 | public function __construct(ClientInterface $client = null) |
||
40 | |||
41 | /** |
||
42 | * @param string $key |
||
43 | * @param string $value |
||
44 | * |
||
45 | * @return $this |
||
46 | */ |
||
47 | public function addHeader($key, $value) |
||
53 | |||
54 | /** |
||
55 | * @param string $url |
||
56 | * @param string $body |
||
57 | * @throws SiftScienceRequestException |
||
58 | * |
||
59 | * @return ResponseInterface |
||
60 | */ |
||
61 | View Code Duplication | public function post($url, $body) |
|
75 | |||
76 | /** |
||
77 | * @param string $url |
||
78 | * @throws SiftScienceRequestException |
||
79 | * |
||
80 | * @return ResponseInterface |
||
81 | */ |
||
82 | View Code Duplication | public function get($url) |
|
95 | } |
||
96 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.