Complex classes like DataTablesColumn 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 DataTablesColumn, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class DataTablesColumn implements JsonSerializable { |
||
24 | |||
25 | /** |
||
26 | * Cell type. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $cellType; |
||
31 | |||
32 | /** |
||
33 | * Class name. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | private $classname; |
||
38 | |||
39 | /** |
||
40 | * Content padding. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $contentPadding; |
||
45 | |||
46 | /** |
||
47 | * Data. |
||
48 | * |
||
49 | * @var integer|string |
||
50 | */ |
||
51 | private $data; |
||
52 | |||
53 | /** |
||
54 | * Default content. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | private $defaultContent; |
||
59 | |||
60 | /** |
||
61 | * mapping. |
||
62 | * |
||
63 | * @var DataTablesMapping |
||
64 | */ |
||
65 | private $mapping; |
||
66 | |||
67 | /** |
||
68 | * Name. |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | private $name; |
||
73 | |||
74 | /** |
||
75 | * Order data. |
||
76 | * |
||
77 | * @var integer|array |
||
78 | */ |
||
79 | private $orderData; |
||
80 | |||
81 | /** |
||
82 | * Order data type. |
||
83 | * |
||
84 | * @var string |
||
85 | */ |
||
86 | private $orderDataType; |
||
87 | |||
88 | /** |
||
89 | * Order sequence. |
||
90 | * |
||
91 | * @var string |
||
92 | */ |
||
93 | private $orderSequence; |
||
94 | |||
95 | /** |
||
96 | * Orderable. |
||
97 | * |
||
98 | * @var boolean |
||
99 | */ |
||
100 | private $orderable; |
||
101 | |||
102 | /** |
||
103 | * Search. |
||
104 | * |
||
105 | * @var DataTablesSearch |
||
106 | */ |
||
107 | private $search; |
||
108 | |||
109 | /** |
||
110 | * Searchable. |
||
111 | * |
||
112 | * @var boolean |
||
113 | */ |
||
114 | private $searchable; |
||
115 | |||
116 | /** |
||
117 | * Title. |
||
118 | * |
||
119 | * @var string |
||
120 | */ |
||
121 | private $title; |
||
122 | |||
123 | /** |
||
124 | * Type. |
||
125 | * |
||
126 | * @var string |
||
127 | */ |
||
128 | private $type; |
||
129 | |||
130 | /** |
||
131 | * Visible. |
||
132 | * |
||
133 | * @var boolean |
||
134 | */ |
||
135 | private $visible; |
||
136 | |||
137 | /** |
||
138 | * Width. |
||
139 | * |
||
140 | * @var string |
||
141 | */ |
||
142 | private $width; |
||
143 | |||
144 | /** |
||
145 | * Constructor. |
||
146 | */ |
||
147 | protected function __construct() { |
||
154 | |||
155 | /** |
||
156 | * Get the cell type. |
||
157 | * |
||
158 | * @return string Returns the cell type. |
||
159 | */ |
||
160 | public function getCellType() { |
||
163 | |||
164 | /** |
||
165 | * Get the class name. |
||
166 | * |
||
167 | * @return string Returns the class name. |
||
168 | */ |
||
169 | public function getClassname() { |
||
172 | |||
173 | /** |
||
174 | * Get the content padding. |
||
175 | * |
||
176 | * @return string Returns the content padding. |
||
177 | */ |
||
178 | public function getContentPadding() { |
||
181 | |||
182 | /** |
||
183 | * Get the data. |
||
184 | * |
||
185 | * @return integer|string Returns the data. |
||
186 | */ |
||
187 | public function getData() { |
||
190 | |||
191 | /** |
||
192 | * Get the default content |
||
193 | * |
||
194 | * @return string Returns the default content. |
||
195 | */ |
||
196 | public function getDefaultContent() { |
||
199 | |||
200 | /** |
||
201 | * Get the mapping. |
||
202 | * |
||
203 | * @return DataTablesMapping The mapping. |
||
204 | */ |
||
205 | public function getMapping() { |
||
208 | |||
209 | /** |
||
210 | * Get the name. |
||
211 | * |
||
212 | * @return string Returns the name. |
||
213 | */ |
||
214 | public function getName() { |
||
217 | |||
218 | /** |
||
219 | * Get the order data. |
||
220 | * |
||
221 | * @return integer|array Returns the order data. |
||
222 | */ |
||
223 | public function getOrderData() { |
||
226 | |||
227 | /** |
||
228 | * Get the order data type. |
||
229 | * |
||
230 | * @return string Returns the order data type. |
||
231 | */ |
||
232 | public function getOrderDataType() { |
||
235 | |||
236 | /** |
||
237 | * Get the order sequence. |
||
238 | * |
||
239 | * @return string Returns the order sequence. |
||
240 | */ |
||
241 | public function getOrderSequence() { |
||
244 | |||
245 | /** |
||
246 | * Get the orderable. |
||
247 | * |
||
248 | * @return boolean Returns the orderable. |
||
249 | */ |
||
250 | public function getOrderable() { |
||
253 | |||
254 | /** |
||
255 | * Get the search. |
||
256 | * |
||
257 | * @return DataTablesSearch Returns the search. |
||
258 | */ |
||
259 | public function getSearch() { |
||
262 | |||
263 | /** |
||
264 | * Get the searchable. |
||
265 | * |
||
266 | * @return boolean Returns the searchable. |
||
267 | */ |
||
268 | public function getSearchable() { |
||
271 | |||
272 | /** |
||
273 | * Get the title. |
||
274 | * |
||
275 | * @return string Returns the title. |
||
276 | */ |
||
277 | public function getTitle() { |
||
280 | |||
281 | /** |
||
282 | * Get the type. |
||
283 | * |
||
284 | * @return string Returns the type. |
||
285 | */ |
||
286 | public function getType() { |
||
289 | |||
290 | /** |
||
291 | * Get the visible. |
||
292 | * |
||
293 | * @return boolean Returns the visible. |
||
294 | */ |
||
295 | public function getVisible() { |
||
298 | |||
299 | /** |
||
300 | * Get the width. |
||
301 | * |
||
302 | * @return string Returns the width. |
||
303 | */ |
||
304 | public function getWidth() { |
||
307 | |||
308 | /** |
||
309 | * {@inheritdoc} |
||
310 | */ |
||
311 | public function jsonSerialize() { |
||
314 | |||
315 | /** |
||
316 | * Create a DataTables column instance. |
||
317 | * |
||
318 | * @param string $name The column name. |
||
319 | * @param string $title The column title. |
||
320 | * @param string $cellType The column cell type. |
||
321 | * @return DataTablesColumn Returns a DataTables column. |
||
322 | */ |
||
323 | public static function newInstance($name, $title, $cellType = "td") { |
||
336 | |||
337 | /** |
||
338 | * Set the cell type. |
||
339 | * |
||
340 | * @param string $cellType The cell type. |
||
341 | * @return DataTablesColumn Returns this DataTables column. |
||
342 | */ |
||
343 | public function setCellType($cellType) { |
||
347 | |||
348 | /** |
||
349 | * Set the class name. |
||
350 | * |
||
351 | * @param string $classname The class name. |
||
352 | * @return DataTablesColumn Returns this DataTables column. |
||
353 | */ |
||
354 | public function setClassname($classname) { |
||
358 | |||
359 | /** |
||
360 | * Set the content padding. |
||
361 | * |
||
362 | * @param string $contentPadding The content padding. |
||
363 | * @return DataTablesColumn Returns this DataTables column. |
||
364 | */ |
||
365 | public function setContentPadding($contentPadding) { |
||
369 | |||
370 | /** |
||
371 | * Set the data. |
||
372 | * |
||
373 | * @param integer|string $data The data. |
||
374 | * @return DataTablesColumn Returns this DataTables column. |
||
375 | */ |
||
376 | public function setData($data) { |
||
380 | |||
381 | /** |
||
382 | * Set the default content. |
||
383 | * |
||
384 | * @param string $defaultContent The default content. |
||
385 | * @return DataTablesColumn Returns this DataTables column. |
||
386 | */ |
||
387 | public function setDefaultContent($defaultContent) { |
||
391 | |||
392 | /** |
||
393 | * Set the mapping. |
||
394 | * |
||
395 | * @param DataTablesMapping $mapping The mapping. |
||
396 | * @return DataTablesColumn Returns this DataTables column. |
||
397 | */ |
||
398 | protected function setMapping(DataTablesMapping $mapping) { |
||
402 | |||
403 | /** |
||
404 | * Set the name. |
||
405 | * |
||
406 | * @param string $name The name. |
||
407 | * @return DataTablesColumn Returns this DataTables column. |
||
408 | */ |
||
409 | protected function setName($name) { |
||
413 | |||
414 | /** |
||
415 | * Set the order data. |
||
416 | * |
||
417 | * @param integer|array $orderData The order data. |
||
418 | * @return DataTablesColumn Returns this DataTables column. |
||
419 | */ |
||
420 | public function setOrderData($orderData) { |
||
424 | |||
425 | /** |
||
426 | * Set the order data type. |
||
427 | * |
||
428 | * @param string $orderDataType The order data type. |
||
429 | * @return DataTablesColumn Returns this DataTables column. |
||
430 | */ |
||
431 | public function setOrderDataType($orderDataType) { |
||
435 | |||
436 | /** |
||
437 | * Set the order sequence. |
||
438 | * |
||
439 | * @param string $orderSequence The order sequence. |
||
440 | * @return DataTablesColumn Returns this DataTables column. |
||
441 | */ |
||
442 | public function setOrderSequence($orderSequence) { |
||
446 | |||
447 | /** |
||
448 | * Set the orderable. |
||
449 | * |
||
450 | * @param boolean $orderable The orderable. |
||
451 | * @return DataTablesColumn Returns this DataTables column. |
||
452 | */ |
||
453 | public function setOrderable($orderable) { |
||
457 | |||
458 | /** |
||
459 | * Set the search. |
||
460 | * |
||
461 | * @param DataTablesSearch $search The search. |
||
462 | * @return DataTablesColumn Returns this DataTables column. |
||
463 | */ |
||
464 | public function setSearch(DataTablesSearch $search) { |
||
468 | |||
469 | /** |
||
470 | * Set the searchable. |
||
471 | * |
||
472 | * @param boolean $searchable The searchable. |
||
473 | * @return DataTablesColumn Returns this DataTables column. |
||
474 | */ |
||
475 | public function setSearchable($searchable) { |
||
479 | |||
480 | /** |
||
481 | * Set the title. |
||
482 | * |
||
483 | * @param string $title The title. |
||
484 | * @return DataTablesColumn Returns this DataTables column. |
||
485 | */ |
||
486 | public function setTitle($title) { |
||
490 | |||
491 | /** |
||
492 | * Set the type. |
||
493 | * |
||
494 | * @param string $type The type. |
||
495 | * @return DataTablesColumn Returns this DataTables column. |
||
496 | */ |
||
497 | public function setType($type) { |
||
501 | |||
502 | /** |
||
503 | * Set the visible. |
||
504 | * |
||
505 | * @param boolean $visible The visible. |
||
506 | * @return DataTablesColumn Returns this DataTables column. |
||
507 | */ |
||
508 | public function setVisible($visible) { |
||
512 | |||
513 | /** |
||
514 | * Set the width. |
||
515 | * |
||
516 | * @param string $width The width. |
||
517 | * @return DataTablesColumn Returns this DataTables column. |
||
518 | */ |
||
519 | public function setWidth($width) { |
||
523 | |||
524 | /** |
||
525 | * Convert into an array representing this instance. |
||
526 | * |
||
527 | * @return array Returns an array representing this instance. |
||
528 | */ |
||
529 | public function toArray() { |
||
553 | |||
554 | } |
||
555 |