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 Plan implements EntityInterface |
||
19 | { |
||
20 | // public static function instantiate($row) |
||
|
|||
21 | // { |
||
22 | // return new static; |
||
23 | // } |
||
24 | |||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $id; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $name; |
||
34 | |||
35 | /** |
||
36 | * @var Plan|null |
||
37 | * XXX not sure to implement |
||
38 | */ |
||
39 | protected $parent; |
||
40 | |||
41 | /** |
||
42 | * @var CustomerInterface |
||
43 | */ |
||
44 | protected $seller; |
||
45 | |||
46 | /** |
||
47 | * @var Target |
||
48 | */ |
||
49 | protected $target; |
||
50 | |||
51 | /** |
||
52 | * @var PriceInterface[] |
||
53 | */ |
||
54 | protected $prices = []; |
||
55 | |||
56 | /** |
||
57 | * @param PriceInterface[] $prices |
||
58 | */ |
||
59 | public function __construct($id, $name, CustomerInterface $seller, array $prices = []) |
||
66 | |||
67 | /** |
||
68 | * @return PriceInterface[] |
||
69 | */ |
||
70 | public function getPrices() |
||
74 | |||
75 | /** |
||
76 | * Calculate charges for given action. |
||
77 | * @param ActionInterface $action |
||
78 | * @return Charge[] |
||
79 | */ |
||
80 | View Code Duplication | public function calculateCharges(ActionInterface $action) |
|
92 | |||
93 | public function jsonSerialize() |
||
97 | } |
||
98 |
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.