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 | 6 | public function getName() |
|
39 | |||
40 | |||
41 | /** |
||
42 | * @param $name |
||
43 | * @return $this |
||
44 | */ |
||
45 | 5 | public function setName($name) |
|
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | 5 | public function getLabel() |
|
59 | |||
60 | /** |
||
61 | * @param $label |
||
62 | * @return $this |
||
63 | */ |
||
64 | 5 | public function setLabel($label) |
|
70 | |||
71 | /** |
||
72 | * @param string $requester |
||
73 | * @return null |
||
74 | */ |
||
75 | 4 | public function getValue($requester = 'abstract') |
|
79 | |||
80 | /** |
||
81 | * @return bool |
||
82 | */ |
||
83 | 5 | public function hasValue() |
|
87 | |||
88 | /** |
||
89 | * @param $value |
||
90 | * @return static|self |
||
91 | */ |
||
92 | 4 | public function setValue($value) |
|
98 | |||
99 | /** |
||
100 | * @return $this |
||
101 | */ |
||
102 | 3 | View Code Duplication | public function addClass() |
113 | |||
114 | /** |
||
115 | * @return $this |
||
116 | */ |
||
117 | View Code Duplication | public function removeClass() |
|
133 | |||
134 | /** |
||
135 | * @param $key |
||
136 | * @param $value |
||
137 | * @return static |
||
138 | */ |
||
139 | 6 | public function setAttrib($key, $value) |
|
146 | |||
147 | /** |
||
148 | * @param string $key |
||
149 | * @return null |
||
150 | */ |
||
151 | 8 | View Code Duplication | public function getAttrib($key) |
160 | |||
161 | /** |
||
162 | * @param string $key |
||
163 | * @return bool |
||
164 | */ |
||
165 | public function delAttrib($key) |
||
172 | |||
173 | /** |
||
174 | * @return mixed |
||
175 | */ |
||
176 | 3 | public function getAttribs() |
|
180 | |||
181 | /** |
||
182 | * @param array $attribs |
||
183 | * @return static |
||
184 | */ |
||
185 | public function setAttribs(array $attribs) |
||
191 | |||
192 | /** |
||
193 | * @return static |
||
194 | */ |
||
195 | public function clearAttribs() |
||
201 | |||
202 | /** |
||
203 | * @param array $attribs |
||
204 | * @return static |
||
205 | */ |
||
206 | 3 | public function addAttribs(array $attribs) |
|
214 | |||
215 | /** |
||
216 | * @param $key |
||
217 | * @return bool |
||
218 | */ |
||
219 | View Code Duplication | public function removeAttrib($key) |
|
229 | } |
||
230 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.