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 |
||
11 | class DefaultHeaderParser implements HeaderParser |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $apiKeyHeaderKey; |
||
18 | |||
19 | /** |
||
20 | * DefaultHeaderParser constructor. |
||
21 | * @param string $apiKeyHeaderKey |
||
22 | */ |
||
23 | 7 | public function __construct($apiKeyHeaderKey = 'x-api-key') |
|
27 | |||
28 | /** |
||
29 | * @param array $headers |
||
30 | * @return ParsedHeaders |
||
31 | * @throws UnableToParseHeadersException |
||
32 | */ |
||
33 | 6 | public function parse(array $headers): ParsedHeaders |
|
41 | |||
42 | /** |
||
43 | * @param array $headers |
||
44 | * @return array |
||
45 | */ |
||
46 | 6 | protected function findAcceptableMIMETypes(array $headers): array |
|
64 | |||
65 | /** |
||
66 | * @param array $headers |
||
67 | * @return null |
||
68 | */ |
||
69 | 6 | View Code Duplication | protected function findAPIKey(array $headers) |
80 | |||
81 | /** |
||
82 | * @param array $headers |
||
83 | * @return null |
||
84 | */ |
||
85 | 6 | View Code Duplication | protected function getContentType(array $headers) |
96 | } |
||
97 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.