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 |
||
13 | class ValuesStatement extends Statement |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $insertValues = []; |
||
19 | |||
20 | /** |
||
21 | * Adds values to the statement. |
||
22 | * |
||
23 | * @return self |
||
24 | */ |
||
25 | public function addValues(array $values) |
||
31 | |||
32 | /** |
||
33 | * Gets the values being inserted. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | public function getInsertValues() |
||
41 | |||
42 | public function build() |
||
63 | } |
||
64 |
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.