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 Table extends View |
||
10 | { |
||
11 | protected $perPage = 20; |
||
12 | |||
13 | protected $pageName = 'page'; |
||
14 | |||
15 | protected $columns; |
||
16 | |||
17 | public function __construct() |
||
21 | |||
22 | /** |
||
23 | * @param array $columns |
||
24 | * |
||
25 | * @return $this |
||
26 | */ |
||
27 | public function setColumns(array $columns) |
||
35 | |||
36 | public function getColumns() |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function paginate($perPage = 25, $pageName = 'page') |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function disablePagination() |
||
61 | |||
62 | /** |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function usePagination() |
||
69 | |||
70 | public function get() |
||
90 | |||
91 | public function toArray() |
||
97 | |||
98 | View Code Duplication | protected function parseRows(Collection $rows) |
|
115 | } |
||
116 |
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.