Complex classes like Column 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 Column, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Column |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $name; |
||
22 | |||
23 | /** |
||
24 | * @var bool |
||
25 | */ |
||
26 | protected $sortable = true; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $sortOn; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $sortType = 'default'; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $filterable = false; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $filterOn; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $dbType; |
||
52 | |||
53 | /** |
||
54 | * If set, formats field for scopes and filters. The formatting is a simple |
||
55 | * sprintf with one string argument (field name). |
||
56 | * |
||
57 | * Example: |
||
58 | * for field: "createdAt" |
||
59 | * dbFormat: "DATE(%s)"" |
||
60 | * the output will be "DATE(createdAt)" |
||
61 | * |
||
62 | * If undefined, the field will not be formatted. |
||
63 | * |
||
64 | * Since the functions may vary in different Database types, Admingenerator does not, |
||
65 | * by default, format fields in any way. It is up to developer to implement this for his fields. |
||
66 | * |
||
67 | * Note: this feature was created mainly for Date/DateTime fields. |
||
68 | */ |
||
69 | protected $dbFormat; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $customView = null; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $formType; |
||
80 | |||
81 | /** |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $filterType; |
||
85 | |||
86 | /** |
||
87 | * @var array |
||
88 | */ |
||
89 | protected $formOptions = array(); |
||
90 | |||
91 | /** |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $filterOptions = array(); |
||
95 | |||
96 | /** |
||
97 | * @var string |
||
98 | */ |
||
99 | protected $getter; |
||
100 | |||
101 | /** |
||
102 | * @var string |
||
103 | */ |
||
104 | protected $label = null; |
||
105 | |||
106 | /** |
||
107 | * @var string |
||
108 | */ |
||
109 | protected $help; |
||
110 | |||
111 | /** |
||
112 | * @var string |
||
113 | */ |
||
114 | protected $localizedDateFormat; |
||
115 | |||
116 | /** |
||
117 | * @var string |
||
118 | */ |
||
119 | protected $localizedTimeFormat; |
||
120 | |||
121 | /** |
||
122 | * @var string |
||
123 | */ |
||
124 | protected $primaryKey = null; |
||
125 | |||
126 | /** |
||
127 | * For special columns template |
||
128 | * |
||
129 | * @var array |
||
130 | */ |
||
131 | protected $extras = array(); |
||
132 | |||
133 | /** |
||
134 | * @var string |
||
135 | */ |
||
136 | protected $credentials = 'AdmingenAllowed'; |
||
137 | |||
138 | /** |
||
139 | * @var string |
||
140 | */ |
||
141 | protected $filtersCredentials = false; |
||
142 | |||
143 | /** |
||
144 | * @var string |
||
145 | */ |
||
146 | protected $gridClass = ''; |
||
147 | |||
148 | /* Used for more verbose error messages */ |
||
149 | protected $debug = array(); |
||
150 | |||
151 | protected $manyToMany = false; |
||
152 | |||
153 | /** |
||
154 | * @param string $name |
||
155 | * @param array $debug |
||
156 | */ |
||
157 | public function __construct($name, $debug) |
||
163 | |||
164 | public function setProperty($option, $value) |
||
174 | |||
175 | public function getName() |
||
179 | |||
180 | public function getGetter() |
||
184 | |||
185 | public function setGetter($getter) |
||
189 | |||
190 | public function getLabel() |
||
196 | |||
197 | public function setLabel($label) |
||
201 | |||
202 | public function getHelp() |
||
206 | |||
207 | public function setHelp($help) |
||
211 | |||
212 | public function isSortable() |
||
216 | |||
217 | public function isFilterable() |
||
221 | |||
222 | public function isReal() |
||
226 | |||
227 | public function getSortable() |
||
231 | |||
232 | public function setSortable($sortable) |
||
236 | |||
237 | public function getSortOn() |
||
241 | |||
242 | public function setSortOn($sort_on) |
||
246 | |||
247 | public function getFilterable() |
||
251 | |||
252 | public function setFilterable($filterable) |
||
256 | |||
257 | public function getFilterOn() |
||
261 | |||
262 | public function setFilterOn($filterOn) |
||
266 | |||
267 | /** |
||
268 | * @param string $text |
||
269 | */ |
||
270 | private function humanize($text) |
||
274 | |||
275 | public function setDbType($dbType) |
||
279 | |||
280 | public function getDbType() |
||
284 | |||
285 | public function setDbFormat($dbFormat) |
||
289 | |||
290 | public function getDbFormat() |
||
294 | |||
295 | public function setFormType($formType) |
||
299 | |||
300 | public function getFormType() |
||
304 | |||
305 | public function setFormOptions($formOptions) |
||
309 | |||
310 | public function getFormOptions() |
||
314 | |||
315 | public function setFilterType($filterType) |
||
319 | |||
320 | public function getFilterType() |
||
324 | |||
325 | public function setFilterOptions($filterOptions) |
||
329 | |||
330 | public function getFilterOptions() |
||
334 | |||
335 | public function setLocalizedDateFormat($localizedDateFormat) |
||
339 | |||
340 | public function getLocalizedDateFormat() |
||
344 | |||
345 | public function setLocalizedTimeFormat($localizedTimeFormat) |
||
349 | |||
350 | public function getLocalizedTimeFormat() |
||
354 | |||
355 | public function setAddFormOptions(array $additionalOptions = array()) |
||
361 | |||
362 | public function setAddFilterOptions(array $additionalOptions = array()) |
||
368 | |||
369 | public function setExtras(array $values) |
||
373 | |||
374 | public function getExtras() |
||
378 | |||
379 | public function setSortType($type) |
||
383 | |||
384 | public function getSortType() |
||
388 | |||
389 | public function getCustomView() |
||
393 | |||
394 | public function setCustomView($customView) |
||
398 | |||
399 | public function setPrimaryKey($primaryKey) |
||
403 | |||
404 | public function getPrimaryKey() |
||
408 | |||
409 | public function setCredentials($credentials = '') |
||
413 | |||
414 | public function getCredentials() |
||
418 | |||
419 | public function setFiltersCredentials($credentials = '') |
||
423 | |||
424 | public function getFiltersCredentials() |
||
432 | |||
433 | public function setGridClass($gridClass) |
||
437 | |||
438 | public function getGridClass() |
||
442 | |||
443 | public function setManyToMany($manyToMany) |
||
447 | |||
448 | public function getManyToMany() |
||
452 | |||
453 | protected function parseOption($option) |
||
470 | } |
||
471 |