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 | trait HasAttributesTrait |
||
10 | { |
||
11 | protected $_attribs; |
||
12 | |||
13 | /** |
||
14 | * @return mixed |
||
15 | */ |
||
16 | public function getId() |
||
20 | |||
21 | /** |
||
22 | * @param $id |
||
23 | * @return $this |
||
24 | */ |
||
25 | public function setId($id) |
||
31 | |||
32 | /** |
||
33 | * @return null |
||
34 | */ |
||
35 | 1 | public function getName() |
|
39 | |||
40 | |||
41 | /** |
||
42 | * @param $name |
||
43 | * @return $this |
||
44 | */ |
||
45 | 1 | public function setName($name) |
|
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | public function getLabel() |
|
59 | |||
60 | /** |
||
61 | * @param $label |
||
62 | * @return $this |
||
63 | */ |
||
64 | 1 | public function setLabel($label) |
|
70 | |||
71 | /** |
||
72 | * @param string $requester |
||
73 | * @return null |
||
74 | */ |
||
75 | 1 | public function getValue($requester = 'abstract') |
|
79 | |||
80 | /** |
||
81 | * @param $value |
||
82 | * @return $this |
||
83 | */ |
||
84 | 1 | public function setValue($value) |
|
90 | |||
91 | /** |
||
92 | * @return $this |
||
93 | */ |
||
94 | View Code Duplication | public function addClass() |
|
105 | |||
106 | /** |
||
107 | * @return $this |
||
108 | */ |
||
109 | View Code Duplication | public function removeClass() |
|
125 | |||
126 | /** |
||
127 | * @param $key |
||
128 | * @param $value |
||
129 | * @return static |
||
130 | */ |
||
131 | 2 | public function setAttrib($key, $value) |
|
138 | |||
139 | /** |
||
140 | * @param string $key |
||
141 | * @return null |
||
142 | */ |
||
143 | 2 | View Code Duplication | public function getAttrib($key) |
152 | |||
153 | /** |
||
154 | * @param string $key |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function delAttrib($key) |
||
164 | |||
165 | /** |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public function getAttribs() |
||
172 | |||
173 | /** |
||
174 | * @param array $attribs |
||
175 | * @return static |
||
176 | */ |
||
177 | public function setAttribs(array $attribs) |
||
183 | |||
184 | /** |
||
185 | * @return static |
||
186 | */ |
||
187 | public function clearAttribs() |
||
193 | |||
194 | /** |
||
195 | * @param array $attribs |
||
196 | * @return static |
||
197 | */ |
||
198 | public function addAttribs(array $attribs) |
||
206 | |||
207 | /** |
||
208 | * @return bool |
||
209 | */ |
||
210 | View Code Duplication | public function removeAttrib($key) |
|
220 | } |
||
221 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.