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 |
||
22 | abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff |
||
23 | { |
||
24 | |||
25 | /* The testVersion configuration variable may be in any of the following formats: |
||
26 | * 1) Omitted/empty, in which case no version is specified. This effectively |
||
27 | * disables all the checks provided by this standard. |
||
28 | * 2) A single PHP version number, e.g. "5.4" in which case the standard checks that |
||
29 | * the code will run on that version of PHP (no deprecated features or newer |
||
30 | * features being used). |
||
31 | * 3) A range, e.g. "5.0-5.5", in which case the standard checks the code will run |
||
32 | * on all PHP versions in that range, and that it doesn't use any features that |
||
33 | * were deprecated by the final version in the list, or which were not available |
||
34 | * for the first version in the list. |
||
35 | * PHP version numbers should always be in Major.Minor format. Both "5", "5.3.2" |
||
36 | * would be treated as invalid, and ignored. |
||
37 | * This standard doesn't support checking against PHP4, so the minimum version that |
||
38 | * is recognised is "5.0". |
||
39 | */ |
||
40 | |||
41 | private function getTestVersion() |
||
77 | |||
78 | View Code Duplication | public function supportsAbove($phpVersion) |
|
91 | |||
92 | View Code Duplication | public function supportsBelow($phpVersion) |
|
105 | |||
106 | }//end class |
||
107 |
This check marks calls to
isset(...)
orempty(...)
that are found before the variable itself is defined. These will always have the same result.This is likely the result of code being shifted around. Consider removing these calls.