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 |
||
| 9 | class DefaultHeaderParser implements HeaderParser |
||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | private $apiKeyHeaderKey; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * DefaultHeaderParser constructor. |
||
| 19 | * @param string $apiKeyHeaderKey |
||
| 20 | */ |
||
| 21 | 7 | public function __construct($apiKeyHeaderKey = 'x-api-key') |
|
| 25 | |||
| 26 | /** |
||
| 27 | * @param array $headers |
||
| 28 | * @return ParsedHeaders |
||
| 29 | */ |
||
| 30 | 6 | public function parse(array $headers): ParsedHeaders |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @param array $headers |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | 6 | protected function findAcceptableMIMETypes(array $headers): array |
|
| 61 | |||
| 62 | /** |
||
| 63 | * @param array $headers |
||
| 64 | * @return null |
||
| 65 | */ |
||
| 66 | 6 | View Code Duplication | protected function findAPIKey(array $headers) |
| 77 | |||
| 78 | /** |
||
| 79 | * @param array $headers |
||
| 80 | * @return null |
||
| 81 | */ |
||
| 82 | 6 | View Code Duplication | protected function getContentType(array $headers) |
| 93 | } |
||
| 94 |
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.