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 |
||
20 | class Row extends Nette\Object |
||
21 | 1 | { |
|
22 | |||
23 | 1 | /** |
|
24 | * @var DataGrid |
||
25 | */ |
||
26 | protected $datagrid; |
||
27 | |||
28 | /** |
||
29 | * @var mixed |
||
30 | */ |
||
31 | protected $item; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $primary_key; |
||
37 | |||
38 | /** |
||
39 | * @var mixed |
||
40 | */ |
||
41 | protected $id; |
||
42 | |||
43 | /** |
||
44 | * @var Html |
||
45 | */ |
||
46 | protected $control; |
||
47 | |||
48 | |||
49 | /** |
||
50 | * @param DataGrid $datagrid |
||
51 | * @param mixed $item |
||
52 | * @param string $primary_key |
||
53 | */ |
||
54 | public function __construct(DataGrid $datagrid, $item, $primary_key) |
||
66 | |||
67 | |||
68 | /** |
||
69 | * Get id value of item |
||
70 | * @return mixed |
||
71 | */ |
||
72 | public function getId() |
||
76 | |||
77 | |||
78 | /** |
||
79 | * Get item value of key |
||
80 | * @param mixed $key |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function getValue($key) |
||
124 | |||
125 | |||
126 | /** |
||
127 | * @return Html |
||
128 | */ |
||
129 | public function getControl() |
||
133 | |||
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | public function getControlClass() |
||
146 | |||
147 | |||
148 | /** |
||
149 | * LeanMapper: Access object properties to get a item value |
||
150 | * @param LeanMapper\Entity $item |
||
151 | * @param mixed $key |
||
152 | 1 | * @return mixed |
|
153 | */ |
||
154 | View Code Duplication | public function getLeanMapperEntityProperty(LeanMapper\Entity $item, $key) |
|
176 | |||
177 | |||
178 | /** |
||
179 | * Nextras: Access object properties to get a item value |
||
180 | * @param Nextras\Orm\Entity\Entity $item |
||
181 | * @param string $key |
||
182 | * @return mixed |
||
183 | */ |
||
184 | View Code Duplication | public function getNextrasEntityProperty(Nextras\Orm\Entity\Entity $item, $key) |
|
206 | |||
207 | |||
208 | /** |
||
209 | 1 | * Doctrine: Access object properties to get a item value |
|
210 | * @param mixed $item |
||
211 | * @param mixed $key |
||
212 | * @return mixed |
||
213 | */ |
||
214 | public function getDoctrineEntityProperty($item, $key) |
||
237 | |||
238 | |||
239 | /** |
||
240 | * Get original item |
||
241 | * @return mixed |
||
242 | */ |
||
243 | public function getItem() |
||
247 | |||
248 | |||
249 | /** |
||
250 | * Has particular row group actions allowed? |
||
251 | * @return bool |
||
252 | */ |
||
253 | public function hasGroupAction() |
||
259 | |||
260 | |||
261 | /** |
||
262 | * Has particular row a action allowed? |
||
263 | * @param mixed $key |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function hasAction($key) |
||
272 | |||
273 | |||
274 | /** |
||
275 | * Has particular row inlie edit allowed? |
||
276 | * @return bool |
||
277 | */ |
||
278 | public function hasInlineEdit() |
||
284 | |||
285 | |||
286 | /** |
||
287 | * @param string $key |
||
288 | * @param Column\Column $column |
||
289 | * @return void |
||
290 | */ |
||
291 | public function applyColumnCallback($key, Column\Column $column) |
||
301 | |||
302 | |||
303 | /** |
||
304 | * Key may contain ".", get rid of it (+ the table alias) |
||
305 | * |
||
306 | * @param string $key |
||
307 | * @return string |
||
308 | */ |
||
309 | private function formatDibiRowKey($key) |
||
317 | |||
318 | } |
||
319 |