Complex classes like AbstractColumn often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractColumn, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | abstract class AbstractColumn |
||
9 | { |
||
10 | protected $label = ''; |
||
11 | |||
12 | protected $uniqueId; |
||
13 | |||
14 | /** |
||
15 | * @var Type\AbstractType |
||
16 | */ |
||
17 | protected $type = null; |
||
18 | |||
19 | protected $styles = []; |
||
20 | |||
21 | protected $width = 5; |
||
22 | |||
23 | protected $isHidden = false; |
||
24 | |||
25 | protected $isIdentity = false; |
||
26 | |||
27 | protected $userSortEnabled = true; |
||
28 | |||
29 | protected $sortDefault = []; |
||
30 | |||
31 | protected $sortActive = null; |
||
32 | |||
33 | protected $filterDefaultValue = null; |
||
34 | |||
35 | protected $filterDefaultOperation = null; |
||
36 | |||
37 | /** |
||
38 | * @var null array |
||
39 | */ |
||
40 | protected $filterSelectOptions; |
||
41 | |||
42 | protected $filterActive = null; |
||
43 | |||
44 | protected $filterActiveValue = ''; |
||
45 | |||
46 | protected $userFilterEnabled = true; |
||
47 | |||
48 | protected $translationEnabled = false; |
||
49 | |||
50 | protected $replaceValues = []; |
||
51 | |||
52 | protected $notReplacedGetEmpty = true; |
||
53 | |||
54 | protected $rowClickEnabled = true; |
||
55 | |||
56 | protected $rendererParameter = []; |
||
57 | |||
58 | /** |
||
59 | * @var AbstractFormatter[] |
||
60 | */ |
||
61 | protected $formatters = []; |
||
62 | |||
63 | /** |
||
64 | * @param $name |
||
65 | */ |
||
66 | public function setLabel($name) |
||
70 | |||
71 | /** |
||
72 | * Get the label. |
||
73 | * |
||
74 | * @return string null |
||
75 | */ |
||
76 | public function getLabel() |
||
80 | |||
81 | /** |
||
82 | * @param $id |
||
83 | */ |
||
84 | public function setUniqueId($id) |
||
88 | |||
89 | /** |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function getUniqueId() |
||
96 | |||
97 | /** |
||
98 | * Set the width in "percent" |
||
99 | * It will be calculated to 100% dependend on what is displayed |
||
100 | * If it's a different output mode like Excel it's dependend on the papersize/orientation. |
||
101 | * |
||
102 | * @param number $percent |
||
103 | */ |
||
104 | public function setWidth($percent) |
||
108 | |||
109 | /** |
||
110 | * Get the width. |
||
111 | * |
||
112 | * @return number |
||
113 | */ |
||
114 | public function getWidth() |
||
118 | |||
119 | /** |
||
120 | * Hide or show the column. |
||
121 | * |
||
122 | * @param bool $mode |
||
123 | */ |
||
124 | public function setHidden($mode = true) |
||
128 | |||
129 | /** |
||
130 | * Is this column hidden? |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function isHidden() |
||
138 | |||
139 | /** |
||
140 | * Set this column as primaryKey column. |
||
141 | * |
||
142 | * @param bool $mode |
||
143 | */ |
||
144 | public function setIdentity($mode = true) |
||
151 | |||
152 | /** |
||
153 | * Is this a primaryKey column? |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function isIdentity() |
||
161 | |||
162 | /** |
||
163 | * Set the column type. |
||
164 | * |
||
165 | * @param Type\AbstractType $type |
||
166 | */ |
||
167 | public function setType(Type\AbstractType $type) |
||
176 | |||
177 | /** |
||
178 | * @return Type\AbstractType |
||
179 | */ |
||
180 | public function getType() |
||
188 | |||
189 | /** |
||
190 | * Set styles. |
||
191 | * |
||
192 | * @param array $styles |
||
193 | */ |
||
194 | public function setStyles(array $styles) |
||
202 | |||
203 | /** |
||
204 | * @param Style\AbstractStyle $style |
||
205 | */ |
||
206 | public function addStyle(Style\AbstractStyle $style) |
||
210 | |||
211 | /** |
||
212 | * @return Style\AbstractStyle[] |
||
213 | */ |
||
214 | public function getStyles() |
||
218 | |||
219 | /** |
||
220 | * @return bool |
||
221 | */ |
||
222 | public function hasStyles() |
||
230 | |||
231 | /** |
||
232 | * Is the user allowed to do sort on this column? |
||
233 | * |
||
234 | * @param bool $mode |
||
235 | */ |
||
236 | public function setUserSortDisabled($mode = true) |
||
240 | |||
241 | /** |
||
242 | * Is user sort enabled? |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | public function isUserSortEnabled() |
||
250 | |||
251 | /** |
||
252 | * The data will get sorted by this column (by default) |
||
253 | * If will be changed by the user per request (POST,GET....). |
||
254 | * |
||
255 | * @param int $priority |
||
256 | * @param string $direction |
||
257 | */ |
||
258 | public function setSortDefault($priority = 1, $direction = 'ASC') |
||
265 | |||
266 | /** |
||
267 | * Get the sort defaults. |
||
268 | * |
||
269 | * @return array |
||
270 | */ |
||
271 | public function getSortDefault() |
||
275 | |||
276 | /** |
||
277 | * Does this column has sort defaults? |
||
278 | * |
||
279 | * @return bool |
||
280 | */ |
||
281 | public function hasSortDefault() |
||
289 | |||
290 | /** |
||
291 | * Set that the data is getting sorted by this columns. |
||
292 | * |
||
293 | * @param string $direction |
||
294 | */ |
||
295 | public function setSortActive($direction = 'ASC') |
||
299 | |||
300 | /** |
||
301 | * @return bool |
||
302 | */ |
||
303 | public function isSortActive() |
||
311 | |||
312 | /** |
||
313 | * @return string |
||
314 | */ |
||
315 | public function getSortActiveDirection() |
||
319 | |||
320 | /** |
||
321 | * @param bool $mode |
||
322 | */ |
||
323 | public function setUserFilterDisabled($mode = true) |
||
327 | |||
328 | /** |
||
329 | * Set the default filterung value (used as long no user filtering getting applied) |
||
330 | * Examples |
||
331 | * $grid->setFilterDefaultValue('something'); |
||
332 | * $grid->setFilterDefaultValue('>20');. |
||
333 | * |
||
334 | * OPERATORS are ALLOWED (like for the user) |
||
335 | * |
||
336 | * @param string $value |
||
337 | */ |
||
338 | public function setFilterDefaultValue($value = null) |
||
344 | |||
345 | /** |
||
346 | * @return string |
||
347 | */ |
||
348 | public function getFilterDefaultValue() |
||
352 | |||
353 | /** |
||
354 | * @return bool |
||
355 | */ |
||
356 | public function hasFilterDefaultValue() |
||
364 | |||
365 | /** |
||
366 | * @param string $operation |
||
367 | */ |
||
368 | public function setFilterDefaultOperation($operation = Filter::LIKE) |
||
372 | |||
373 | /** |
||
374 | * @return string |
||
375 | */ |
||
376 | public function getFilterDefaultOperation() |
||
384 | |||
385 | /** |
||
386 | * @param array $options |
||
387 | * @param bool $noSelect |
||
388 | */ |
||
389 | public function setFilterSelectOptions(array $options = null, $noSelect = true) |
||
401 | |||
402 | /** |
||
403 | * Unset the filter select options (normal search). |
||
404 | */ |
||
405 | public function unsetFilterSelectOptions() |
||
409 | |||
410 | /** |
||
411 | * @return array null |
||
412 | */ |
||
413 | public function getFilterSelectOptions() |
||
417 | |||
418 | /** |
||
419 | * @return bool |
||
420 | */ |
||
421 | public function hasFilterSelectOptions() |
||
429 | |||
430 | /** |
||
431 | * @param mixed $value |
||
432 | */ |
||
433 | public function setFilterActive($value = '') |
||
438 | |||
439 | /** |
||
440 | * @return bool |
||
441 | */ |
||
442 | public function isFilterActive() |
||
446 | |||
447 | /** |
||
448 | * @return string |
||
449 | */ |
||
450 | public function getFilterActiveValue() |
||
454 | |||
455 | /** |
||
456 | * @return bool |
||
457 | */ |
||
458 | public function isUserFilterEnabled() |
||
462 | |||
463 | /** |
||
464 | * Enable data translation. |
||
465 | * |
||
466 | * @param bool $mode |
||
467 | */ |
||
468 | public function setTranslationEnabled($mode = true) |
||
472 | |||
473 | /** |
||
474 | * Is data translation enabled? |
||
475 | * |
||
476 | * @return bool |
||
477 | */ |
||
478 | public function isTranslationEnabled() |
||
482 | |||
483 | /** |
||
484 | * Replace the column values with the applied values. |
||
485 | * |
||
486 | * @param array $values |
||
487 | * @param bool $notReplacedGetEmpty |
||
488 | */ |
||
489 | public function setReplaceValues(array $values, $notReplacedGetEmpty = true) |
||
497 | |||
498 | /** |
||
499 | * @return bool |
||
500 | */ |
||
501 | public function hasReplaceValues() |
||
505 | |||
506 | /** |
||
507 | * @return array |
||
508 | */ |
||
509 | public function getReplaceValues() |
||
513 | |||
514 | /** |
||
515 | * @return bool |
||
516 | */ |
||
517 | public function notReplacedGetEmpty() |
||
521 | |||
522 | /** |
||
523 | * Set parameter for a specific renderer (currently only supported for jqGrid). |
||
524 | * |
||
525 | * @param string $name |
||
526 | * @param mixed $value |
||
527 | * @param string $rendererType |
||
528 | */ |
||
529 | public function setRendererParameter($name, $value, $rendererType = 'jqGrid') |
||
540 | |||
541 | /** |
||
542 | * @param string $rendererName |
||
543 | * |
||
544 | * @return array |
||
545 | */ |
||
546 | public function getRendererParameters($rendererName = 'jqGrid') |
||
554 | |||
555 | /** |
||
556 | * Set a template formatter and overwrite other formatter. |
||
557 | * |
||
558 | * @param AbstractFormatter[] $formatters |
||
559 | */ |
||
560 | public function setFormatters(array $formatters) |
||
564 | |||
565 | /** |
||
566 | * Set a template formatter and overwrite other formatter. |
||
567 | * |
||
568 | * @param AbstractFormatter $formatter |
||
569 | * |
||
570 | * @deprecated please use setFormatters |
||
571 | */ |
||
572 | public function setFormatter(AbstractFormatter $formatter) |
||
578 | |||
579 | /** |
||
580 | * add a template formatter in the list. |
||
581 | * |
||
582 | * @param AbstractFormatter $formatter |
||
583 | */ |
||
584 | public function addFormatter(AbstractFormatter $formatter) |
||
588 | |||
589 | /** |
||
590 | * return a list of different formatter. |
||
591 | * |
||
592 | * @return AbstractFormatter[] |
||
593 | */ |
||
594 | public function getFormatters() |
||
598 | |||
599 | /** |
||
600 | * return a list of different formatter. |
||
601 | * |
||
602 | * @return AbstractFormatter[] |
||
603 | * |
||
604 | * @deprecated please use getFormatters |
||
605 | */ |
||
606 | public function getFormatter() |
||
612 | |||
613 | /** |
||
614 | * @return bool |
||
615 | */ |
||
616 | public function hasFormatters() |
||
624 | |||
625 | public function hasFormatter() |
||
631 | |||
632 | /** |
||
633 | * @param bool $mode |
||
634 | */ |
||
635 | public function setRowClickDisabled($mode = true) |
||
639 | |||
640 | /** |
||
641 | * @return bool |
||
642 | */ |
||
643 | public function isRowClickEnabled() |
||
647 | } |
||
648 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.