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 = "td"; |
||
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 = true; |
||
101 | |||
102 | /** |
||
103 | * Searchable. |
||
104 | * |
||
105 | * @var boolean |
||
106 | */ |
||
107 | private $searchable = true; |
||
108 | |||
109 | /** |
||
110 | * Title. |
||
111 | * |
||
112 | * @var string |
||
113 | */ |
||
114 | private $title; |
||
115 | |||
116 | /** |
||
117 | * Type. |
||
118 | * |
||
119 | * @var string |
||
120 | */ |
||
121 | private $type; |
||
122 | |||
123 | /** |
||
124 | * Visible. |
||
125 | * |
||
126 | * @var boolean |
||
127 | */ |
||
128 | private $visible = true; |
||
129 | |||
130 | /** |
||
131 | * Width. |
||
132 | * |
||
133 | * @var string |
||
134 | */ |
||
135 | private $width; |
||
136 | |||
137 | /** |
||
138 | * Constructor. |
||
139 | */ |
||
140 | protected function __construct() { |
||
143 | |||
144 | /** |
||
145 | * Get the cell type. |
||
146 | * |
||
147 | * @return string Returns the cell type. |
||
148 | */ |
||
149 | public function getCellType() { |
||
152 | |||
153 | /** |
||
154 | * Get the class name. |
||
155 | * |
||
156 | * @return string Returns the class name. |
||
157 | */ |
||
158 | public function getClassname() { |
||
161 | |||
162 | /** |
||
163 | * Get the content padding. |
||
164 | * |
||
165 | * @return string Returns the content padding. |
||
166 | */ |
||
167 | public function getContentPadding() { |
||
170 | |||
171 | /** |
||
172 | * Get the data. |
||
173 | * |
||
174 | * @return integer|string Returns the data. |
||
175 | */ |
||
176 | public function getData() { |
||
179 | |||
180 | /** |
||
181 | * Get the default content |
||
182 | * |
||
183 | * @return string Returns the default content. |
||
184 | */ |
||
185 | public function getDefaultContent() { |
||
188 | |||
189 | /** |
||
190 | * Get the mapping. |
||
191 | * |
||
192 | * @return DataTablesMapping The mapping. |
||
193 | */ |
||
194 | public function getMapping() { |
||
197 | |||
198 | /** |
||
199 | * Get the name. |
||
200 | * |
||
201 | * @return string Returns the name. |
||
202 | */ |
||
203 | public function getName() { |
||
206 | |||
207 | /** |
||
208 | * Get the order data. |
||
209 | * |
||
210 | * @return integer|array Returns the order data. |
||
211 | */ |
||
212 | public function getOrderData() { |
||
215 | |||
216 | /** |
||
217 | * Get the order data type. |
||
218 | * |
||
219 | * @return string Returns the order data type. |
||
220 | */ |
||
221 | public function getOrderDataType() { |
||
224 | |||
225 | /** |
||
226 | * Get the order sequence. |
||
227 | * |
||
228 | * @return string Returns the order sequence. |
||
229 | */ |
||
230 | public function getOrderSequence() { |
||
233 | |||
234 | /** |
||
235 | * Get the orderable. |
||
236 | * |
||
237 | * @return boolean Returns the orderable. |
||
238 | */ |
||
239 | public function getOrderable() { |
||
242 | |||
243 | /** |
||
244 | * Get the searchable. |
||
245 | * |
||
246 | * @return boolean Returns the searchable. |
||
247 | */ |
||
248 | public function getSearchable() { |
||
251 | |||
252 | /** |
||
253 | * Get the title. |
||
254 | * |
||
255 | * @return string Returns the title. |
||
256 | */ |
||
257 | public function getTitle() { |
||
260 | |||
261 | /** |
||
262 | * Get the type. |
||
263 | * |
||
264 | * @return string Returns the type. |
||
265 | */ |
||
266 | public function getType() { |
||
269 | |||
270 | /** |
||
271 | * Get the visible. |
||
272 | * |
||
273 | * @return boolean Returns the visible. |
||
274 | */ |
||
275 | public function getVisible() { |
||
278 | |||
279 | /** |
||
280 | * Get the width. |
||
281 | * |
||
282 | * @return string Returns the width. |
||
283 | */ |
||
284 | public function getWidth() { |
||
287 | |||
288 | /** |
||
289 | * {@inheritdoc} |
||
290 | */ |
||
291 | public function jsonSerialize() { |
||
294 | |||
295 | /** |
||
296 | * Create a DataTables column instance. |
||
297 | * |
||
298 | * @param string $name The column name. |
||
299 | * @param string $title The column title. |
||
300 | * @param string $cellType The column cell type. |
||
301 | * @return DataTablesColumn Returns a DataTables column. |
||
302 | */ |
||
303 | public static function newInstance($name, $title, $cellType = "td") { |
||
316 | |||
317 | /** |
||
318 | * Set the cell type. |
||
319 | * |
||
320 | * @param string $cellType The cell type. |
||
321 | * @return DataTablesColumn Returns this DataTables column. |
||
322 | */ |
||
323 | public function setCellType($cellType) { |
||
334 | |||
335 | /** |
||
336 | * Set the class name. |
||
337 | * |
||
338 | * @param string $classname The class name. |
||
339 | * @return DataTablesColumn Returns this DataTables column. |
||
340 | */ |
||
341 | public function setClassname($classname) { |
||
345 | |||
346 | /** |
||
347 | * Set the content padding. |
||
348 | * |
||
349 | * @param string $contentPadding The content padding. |
||
350 | * @return DataTablesColumn Returns this DataTables column. |
||
351 | */ |
||
352 | public function setContentPadding($contentPadding) { |
||
356 | |||
357 | /** |
||
358 | * Set the data. |
||
359 | * |
||
360 | * @param integer|string $data The data. |
||
361 | * @return DataTablesColumn Returns this DataTables column. |
||
362 | */ |
||
363 | public function setData($data) { |
||
367 | |||
368 | /** |
||
369 | * Set the default content. |
||
370 | * |
||
371 | * @param string $defaultContent The default content. |
||
372 | * @return DataTablesColumn Returns this DataTables column. |
||
373 | */ |
||
374 | public function setDefaultContent($defaultContent) { |
||
378 | |||
379 | /** |
||
380 | * Set the name. |
||
381 | * |
||
382 | * @param string $name The name. |
||
383 | * @return DataTablesColumn Returns this DataTables column. |
||
384 | */ |
||
385 | protected function setName($name) { |
||
389 | |||
390 | /** |
||
391 | * Set the order data. |
||
392 | * |
||
393 | * @param integer|array $orderData The order data. |
||
394 | * @return DataTablesColumn Returns this DataTables column. |
||
395 | */ |
||
396 | public function setOrderData($orderData) { |
||
400 | |||
401 | /** |
||
402 | * Set the order data type. |
||
403 | * |
||
404 | * @param string $orderDataType The order data type. |
||
405 | * @return DataTablesColumn Returns this DataTables column. |
||
406 | */ |
||
407 | public function setOrderDataType($orderDataType) { |
||
411 | |||
412 | /** |
||
413 | * Set the order sequence. |
||
414 | * |
||
415 | * @param string $orderSequence The order sequence. |
||
416 | * @return DataTablesColumn Returns this DataTables column. |
||
417 | */ |
||
418 | public function setOrderSequence($orderSequence) { |
||
429 | |||
430 | /** |
||
431 | * Set the orderable. |
||
432 | * |
||
433 | * @param boolean $orderable The orderable. |
||
434 | * @return DataTablesColumn Returns this DataTables column. |
||
435 | */ |
||
436 | public function setOrderable($orderable) { |
||
440 | |||
441 | /** |
||
442 | * Set the searchable. |
||
443 | * |
||
444 | * @param boolean $searchable The searchable. |
||
445 | * @return DataTablesColumn Returns this DataTables column. |
||
446 | */ |
||
447 | public function setSearchable($searchable) { |
||
451 | |||
452 | /** |
||
453 | * Set the title. |
||
454 | * |
||
455 | * @param string $title The title. |
||
456 | * @return DataTablesColumn Returns this DataTables column. |
||
457 | */ |
||
458 | public function setTitle($title) { |
||
462 | |||
463 | /** |
||
464 | * Set the type. |
||
465 | * |
||
466 | * @param string $type The type. |
||
467 | * @return DataTablesColumn Returns this DataTables column. |
||
468 | */ |
||
469 | public function setType($type) { |
||
484 | |||
485 | /** |
||
486 | * Set the visible. |
||
487 | * |
||
488 | * @param boolean $visible The visible. |
||
489 | * @return DataTablesColumn Returns this DataTables column. |
||
490 | */ |
||
491 | public function setVisible($visible) { |
||
495 | |||
496 | /** |
||
497 | * Set the width. |
||
498 | * |
||
499 | * @param string $width The width. |
||
500 | * @return DataTablesColumn Returns this DataTables column. |
||
501 | */ |
||
502 | public function setWidth($width) { |
||
506 | |||
507 | /** |
||
508 | * Convert into an array representing this instance. |
||
509 | * |
||
510 | * @return array Returns an array representing this instance. |
||
511 | */ |
||
512 | public function toArray() { |
||
536 | |||
537 | } |
||
538 |