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 |
||
7 | class Comparison implements Expression |
||
8 | { |
||
9 | const EQUALS = 'eq'; |
||
10 | const NOT_EQUALS = 'neq'; |
||
11 | const GREATER_THAN = 'gt'; |
||
12 | const GREATER_THAN_EQUAL = 'gte'; |
||
13 | const LESS_THAN = 'lt'; |
||
14 | const LESS_THAN_EQUAL = 'lte'; |
||
15 | |||
16 | // TODO: Contains (like), NULL, NOT NULL, IN |
||
|
|||
17 | |||
18 | private static $validTypes = [ |
||
19 | self::EQUALS, |
||
20 | self::NOT_EQUALS, |
||
21 | self::GREATER_THAN, |
||
22 | self::GREATER_THAN_EQUAL, |
||
23 | self::LESS_THAN, |
||
24 | self::LESS_THAN_EQUAL, |
||
25 | ]; |
||
26 | |||
27 | private $comparator; |
||
28 | private $field; |
||
29 | private $value; |
||
30 | |||
31 | View Code Duplication | public function __construct(string $comparator, $field, $value) |
|
45 | |||
46 | public function getComparator() |
||
50 | |||
51 | public function getField() |
||
55 | |||
56 | public function getValue() |
||
60 | } |
||
61 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.