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 |
||
20 | class Column extends Fluent |
||
21 | { |
||
22 | /** |
||
23 | * @param array $attributes |
||
24 | */ |
||
25 | public function __construct($attributes = []) |
||
49 | |||
50 | /** |
||
51 | * Format string to title case. |
||
52 | * |
||
53 | * @param string $value |
||
54 | * @return string |
||
55 | */ |
||
56 | public static function titleFormat($value) |
||
60 | |||
61 | /** |
||
62 | * Create a computed column that is not searchable/orderable. |
||
63 | * |
||
64 | * @param string $data |
||
65 | * @param string|null $title |
||
66 | * @return Column |
||
67 | */ |
||
68 | public static function computed($data, $title = null) |
||
76 | |||
77 | /** |
||
78 | * Set column searchable flag. |
||
79 | * |
||
80 | * @param bool $flag |
||
81 | * @return $this |
||
82 | * @see https://datatables.net/reference/option/columns.searchable |
||
83 | */ |
||
84 | public function searchable(bool $flag = true) |
||
90 | |||
91 | /** |
||
92 | * Set column orderable flag. |
||
93 | * |
||
94 | * @param bool $flag |
||
95 | * @return $this |
||
96 | * @see https://datatables.net/reference/option/columns.orderable |
||
97 | */ |
||
98 | public function orderable(bool $flag = true) |
||
104 | |||
105 | /** |
||
106 | * Set column title. |
||
107 | * |
||
108 | * @param string $value |
||
109 | * @return $this |
||
110 | * @see https://datatables.net/reference/option/columns.title |
||
111 | */ |
||
112 | public function title($value) |
||
118 | |||
119 | /** |
||
120 | * Make a new column instance. |
||
121 | * |
||
122 | * @param string $data |
||
123 | * @param string $name |
||
124 | * @return Column |
||
125 | */ |
||
126 | public static function make($data, $name = '') |
||
135 | |||
136 | /** |
||
137 | * Create a checkbox column. |
||
138 | * |
||
139 | * @param string $title |
||
140 | * @return Column |
||
141 | */ |
||
142 | public static function checkbox($title = '') |
||
151 | |||
152 | /** |
||
153 | * Set column class name. |
||
154 | * |
||
155 | * @param string $class |
||
156 | * @return $this |
||
157 | * @see https://datatables.net/reference/option/columns.className |
||
158 | */ |
||
159 | public function className($class) |
||
165 | |||
166 | /** |
||
167 | * Set column default content. |
||
168 | * |
||
169 | * @param string $value |
||
170 | * @return $this |
||
171 | * @see https://datatables.net/reference/option/columns.defaultContent |
||
172 | */ |
||
173 | public function content($value) |
||
179 | |||
180 | /** |
||
181 | * Set column visible flag. |
||
182 | * |
||
183 | * @param bool $flag |
||
184 | * @return $this |
||
185 | * @see https://datatables.net/reference/option/columns.visible |
||
186 | */ |
||
187 | public function visible(bool $flag = true) |
||
193 | |||
194 | /** |
||
195 | * Append a class name to field. |
||
196 | * |
||
197 | * @param string $class |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function addClass($class) |
||
210 | |||
211 | /** |
||
212 | * Set column exportable flag. |
||
213 | * |
||
214 | * @param bool $flag |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function exportable(bool $flag = true) |
||
223 | |||
224 | /** |
||
225 | * Set column printable flag. |
||
226 | * |
||
227 | * @param bool $flag |
||
228 | * @return $this |
||
229 | */ |
||
230 | public function printable(bool $flag = true) |
||
236 | |||
237 | /** |
||
238 | * Set column width value. |
||
239 | * |
||
240 | * @param int|string $value |
||
241 | * @return $this |
||
242 | * @see https://datatables.net/reference/option/columns.width |
||
243 | */ |
||
244 | public function width($value) |
||
250 | |||
251 | /** |
||
252 | * Set column data option value. |
||
253 | * |
||
254 | * @param string $value |
||
255 | * @return $this |
||
256 | * @see https://datatables.net/reference/option/columns.data |
||
257 | */ |
||
258 | public function data($value) |
||
264 | |||
265 | /** |
||
266 | * Set column name option value. |
||
267 | * |
||
268 | * @param string $value |
||
269 | * @return $this |
||
270 | * @see https://datatables.net/reference/option/columns.name |
||
271 | */ |
||
272 | public function name($value) |
||
278 | |||
279 | /** |
||
280 | * Set column edit field option value. |
||
281 | * |
||
282 | * @param string $value |
||
283 | * @return $this |
||
284 | * @see https://datatables.net/reference/option/columns.editField |
||
285 | */ |
||
286 | public function editField($value) |
||
292 | |||
293 | /** |
||
294 | * Set column orderData option value. |
||
295 | * |
||
296 | * @param mixed $value |
||
297 | * @return $this |
||
298 | * @see https://datatables.net/reference/option/columns.orderData |
||
299 | */ |
||
300 | public function orderData($value) |
||
306 | |||
307 | /** |
||
308 | * Set column orderDataType option value. |
||
309 | * |
||
310 | * @param mixed $value |
||
311 | * @return $this |
||
312 | * @see https://datatables.net/reference/option/columns.orderDataType |
||
313 | */ |
||
314 | public function orderDataType($value) |
||
320 | |||
321 | /** |
||
322 | * Set column orderSequence option value. |
||
323 | * |
||
324 | * @param mixed $value |
||
325 | * @return $this |
||
326 | * @see https://datatables.net/reference/option/columns.orderSequence |
||
327 | */ |
||
328 | public function orderSequence($value) |
||
334 | |||
335 | /** |
||
336 | * Set column cellType option value. |
||
337 | * |
||
338 | * @param mixed $value |
||
339 | * @return $this |
||
340 | * @see https://datatables.net/reference/option/columns.cellType |
||
341 | */ |
||
342 | public function cellType($value) |
||
348 | |||
349 | /** |
||
350 | * Set column type option value. |
||
351 | * |
||
352 | * @param mixed $value |
||
353 | * @return $this |
||
354 | * @see https://datatables.net/reference/option/columns.type |
||
355 | */ |
||
356 | public function type($value) |
||
362 | |||
363 | /** |
||
364 | * Set column contentPadding option value. |
||
365 | * |
||
366 | * @param mixed $value |
||
367 | * @return $this |
||
368 | * @see https://datatables.net/reference/option/columns.contentPadding |
||
369 | */ |
||
370 | public function contentPadding($value) |
||
376 | |||
377 | /** |
||
378 | * Set column createdCell option value. |
||
379 | * |
||
380 | * @param mixed $value |
||
381 | * @return $this |
||
382 | * @see https://datatables.net/reference/option/columns.createdCell |
||
383 | */ |
||
384 | public function createdCell($value) |
||
390 | |||
391 | /** |
||
392 | * Use the js renderer "$.fn.dataTable.render.". |
||
393 | * |
||
394 | * @param mixed $value |
||
395 | * @return $this |
||
396 | * @see https://datatables.net/reference/option/columns.render |
||
397 | */ |
||
398 | public function renderJs($value) |
||
402 | |||
403 | /** |
||
404 | * Set column renderer. |
||
405 | * |
||
406 | * @param mixed $value |
||
407 | * @return $this |
||
408 | * @see https://datatables.net/reference/option/columns.render |
||
409 | */ |
||
410 | public function render($value) |
||
416 | |||
417 | /** |
||
418 | * Set column footer. |
||
419 | * |
||
420 | * @param mixed $value |
||
421 | * @return $this |
||
422 | */ |
||
423 | public function footer($value) |
||
429 | |||
430 | /** |
||
431 | * Parse render attribute. |
||
432 | * |
||
433 | * @param mixed $value |
||
434 | * @return string|null |
||
435 | */ |
||
436 | public function parseRender($value) |
||
457 | |||
458 | /** |
||
459 | * Check if given key & value is a valid datatables built-in renderer function. |
||
460 | * |
||
461 | * @param string $value |
||
462 | * @return bool |
||
463 | */ |
||
464 | private function isBuiltInRenderFunction($value) |
||
472 | |||
473 | /** |
||
474 | * Display render value as is. |
||
475 | * |
||
476 | * @param mixed $value |
||
477 | * @return string |
||
478 | */ |
||
479 | private function parseRenderAsString($value) |
||
483 | |||
484 | /** |
||
485 | * @return array |
||
486 | */ |
||
487 | public function toArray() |
||
491 | } |
||
492 |