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 |
||
19 | class NoticesContainer implements NoticesContainerInterface |
||
20 | { |
||
21 | |||
22 | |||
23 | /** |
||
24 | * @var NoticeInterface[] $information |
||
25 | */ |
||
26 | private $information = array(); |
||
27 | |||
28 | |||
29 | /** |
||
30 | * @var NoticeInterface[] $attention |
||
31 | */ |
||
32 | private $attention = array(); |
||
33 | |||
34 | |||
35 | /** |
||
36 | * @var NoticeInterface[] $error |
||
37 | */ |
||
38 | private $error = array(); |
||
39 | |||
40 | |||
41 | /** |
||
42 | * @var NoticeInterface[] $success |
||
43 | */ |
||
44 | private $success = array(); |
||
45 | |||
46 | |||
47 | /** |
||
48 | * @param string $notice |
||
49 | * @param bool $dismissible |
||
50 | * @param string $file |
||
51 | * @param string $func |
||
52 | * @param string $line |
||
53 | * @throws InvalidDataTypeException |
||
54 | */ |
||
55 | public function addInformation($notice, $dismissible = true, $file = '', $func = '', $line = '') |
||
66 | |||
67 | |||
68 | |||
69 | /** |
||
70 | * @param string $notice |
||
71 | * @param bool $dismissible |
||
72 | * @param string $file |
||
73 | * @param string $func |
||
74 | * @param string $line |
||
75 | * @throws InvalidDataTypeException |
||
76 | */ |
||
77 | View Code Duplication | public function addAttention($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
88 | |||
89 | |||
90 | |||
91 | /** |
||
92 | * @param string $notice |
||
93 | * @param bool $dismissible |
||
94 | * @param string $file |
||
95 | * @param string $func |
||
96 | * @param string $line |
||
97 | * @throws InvalidDataTypeException |
||
98 | */ |
||
99 | public function addError($notice, $dismissible = true, $file, $func, $line) |
||
110 | |||
111 | |||
112 | |||
113 | /** |
||
114 | * @param string $notice |
||
115 | * @param bool $dismissible |
||
116 | * @param string $file |
||
117 | * @param string $func |
||
118 | * @param string $line |
||
119 | * @throws InvalidDataTypeException |
||
120 | */ |
||
121 | View Code Duplication | public function addSuccess($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
132 | |||
133 | |||
134 | /** |
||
135 | * @return boolean |
||
136 | */ |
||
137 | public function hasInformation() |
||
141 | |||
142 | |||
143 | |||
144 | /** |
||
145 | * @return boolean |
||
146 | */ |
||
147 | public function hasAttention() |
||
151 | |||
152 | |||
153 | |||
154 | /** |
||
155 | * @return boolean |
||
156 | */ |
||
157 | public function hasError() |
||
161 | |||
162 | |||
163 | |||
164 | /** |
||
165 | * @return boolean |
||
166 | */ |
||
167 | public function hasSuccess() |
||
171 | |||
172 | |||
173 | /** |
||
174 | * @return int |
||
175 | */ |
||
176 | public function countInformation() |
||
180 | |||
181 | |||
182 | |||
183 | /** |
||
184 | * @return int |
||
185 | */ |
||
186 | public function countAttention() |
||
190 | |||
191 | |||
192 | |||
193 | /** |
||
194 | * @return int |
||
195 | */ |
||
196 | public function countError() |
||
200 | |||
201 | |||
202 | |||
203 | /** |
||
204 | * @return int |
||
205 | */ |
||
206 | public function countSuccess() |
||
210 | |||
211 | |||
212 | /** |
||
213 | * @return NoticeInterface[] |
||
214 | */ |
||
215 | public function getInformation() |
||
219 | |||
220 | |||
221 | |||
222 | /** |
||
223 | * @return NoticeInterface[] |
||
224 | */ |
||
225 | public function getAttention() |
||
229 | |||
230 | |||
231 | |||
232 | /** |
||
233 | * @return NoticeInterface[] |
||
234 | */ |
||
235 | public function getError() |
||
239 | |||
240 | |||
241 | |||
242 | /** |
||
243 | * @return NoticeInterface[] |
||
244 | */ |
||
245 | public function getSuccess() |
||
249 | |||
250 | |||
251 | } |
||
252 |