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 |
||
8 | class ModelWithObject |
||
9 | { |
||
10 | /** |
||
11 | * ModelWithObject constructor. |
||
12 | * @param DB $db |
||
13 | * @param object $entity |
||
14 | * @param Cache $cache |
||
15 | */ |
||
16 | 4 | public function __construct(DB $db, $entity, Cache $cache) |
|
25 | /** |
||
26 | * @return void |
||
27 | */ |
||
28 | 1 | public function create() |
|
46 | |||
47 | /** |
||
48 | * @param array $columns columns to update. if columns is empty array, update all of the columns |
||
49 | * @return int rows updated |
||
50 | */ |
||
51 | 2 | public function update(array $columns=[]) |
|
73 | |||
74 | /** |
||
75 | * @return int rows deleted |
||
76 | */ |
||
77 | 1 | public function delete() |
|
84 | |||
85 | 3 | /** |
|
86 | * set entity table name |
||
87 | 3 | * @param string $tableName |
|
88 | 3 | * @return $this |
|
89 | 3 | */ |
|
90 | 3 | public function withTable($tableName) |
|
95 | |||
96 | protected function getColumns() |
||
104 | |||
105 | /** |
||
106 | * @var object |
||
107 | */ |
||
108 | protected $object; |
||
109 | |||
110 | /** |
||
111 | * @var ModelContainer |
||
112 | */ |
||
113 | protected $entity; |
||
114 | /** |
||
115 | * @var DB |
||
116 | */ |
||
117 | protected $db; |
||
118 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.