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 |
||
24 | final class DataTablesColumn implements JsonSerializable { |
||
25 | |||
26 | /** |
||
27 | * Cell type. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $cellType = "td"; |
||
32 | |||
33 | /** |
||
34 | * Class name. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $classname; |
||
39 | |||
40 | /** |
||
41 | * Content padding. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $contentPadding; |
||
46 | |||
47 | /** |
||
48 | * Data. |
||
49 | * |
||
50 | * @var integer|string |
||
51 | */ |
||
52 | private $data; |
||
53 | |||
54 | /** |
||
55 | * Default content. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | private $defaultContent; |
||
60 | |||
61 | /** |
||
62 | * mapping. |
||
63 | * |
||
64 | * @var DataTablesMapping |
||
65 | */ |
||
66 | private $mapping; |
||
67 | |||
68 | /** |
||
69 | * Name. |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | private $name; |
||
74 | |||
75 | /** |
||
76 | * Order data. |
||
77 | * |
||
78 | * @var integer|array |
||
79 | */ |
||
80 | private $orderData; |
||
81 | |||
82 | /** |
||
83 | * Order data type. |
||
84 | * |
||
85 | * @var string |
||
86 | */ |
||
87 | private $orderDataType; |
||
88 | |||
89 | /** |
||
90 | * Order sequence. |
||
91 | * |
||
92 | * @var string |
||
93 | */ |
||
94 | private $orderSequence; |
||
95 | |||
96 | /** |
||
97 | * Orderable. |
||
98 | * |
||
99 | * @var boolean |
||
100 | */ |
||
101 | private $orderable = true; |
||
102 | |||
103 | /** |
||
104 | * Searchable. |
||
105 | * |
||
106 | * @var boolean |
||
107 | */ |
||
108 | private $searchable = true; |
||
109 | |||
110 | /** |
||
111 | * Title. |
||
112 | * |
||
113 | * @var string |
||
114 | */ |
||
115 | private $title; |
||
116 | |||
117 | /** |
||
118 | * Type. |
||
119 | * |
||
120 | * @var string |
||
121 | */ |
||
122 | private $type; |
||
123 | |||
124 | /** |
||
125 | * Visible. |
||
126 | * |
||
127 | * @var boolean |
||
128 | */ |
||
129 | private $visible = true; |
||
130 | |||
131 | /** |
||
132 | * Width. |
||
133 | * |
||
134 | * @var string |
||
135 | */ |
||
136 | private $width; |
||
137 | |||
138 | /** |
||
139 | * Constructor. |
||
140 | * |
||
141 | * @param string $name The column name. |
||
142 | * @param string $title The column title. |
||
143 | * @param string $cellType The column cell type. |
||
144 | */ |
||
145 | public function __construct($name, $title, $cellType = "td") { |
||
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 searchable. |
||
256 | * |
||
257 | * @return boolean Returns the searchable. |
||
258 | */ |
||
259 | public function getSearchable() { |
||
262 | |||
263 | /** |
||
264 | * Get the title. |
||
265 | * |
||
266 | * @return string Returns the title. |
||
267 | */ |
||
268 | public function getTitle() { |
||
271 | |||
272 | /** |
||
273 | * Get the type. |
||
274 | * |
||
275 | * @return string Returns the type. |
||
276 | */ |
||
277 | public function getType() { |
||
280 | |||
281 | /** |
||
282 | * Get the visible. |
||
283 | * |
||
284 | * @return boolean Returns the visible. |
||
285 | */ |
||
286 | public function getVisible() { |
||
289 | |||
290 | /** |
||
291 | * Get the width. |
||
292 | * |
||
293 | * @return string Returns the width. |
||
294 | */ |
||
295 | public function getWidth() { |
||
298 | |||
299 | /** |
||
300 | * {@inheritdoc} |
||
301 | */ |
||
302 | public function jsonSerialize() { |
||
305 | |||
306 | /** |
||
307 | * Set the cell type. |
||
308 | * |
||
309 | * @param string $cellType The cell type. |
||
310 | * @return DataTablesColumn Returns the DataTables column. |
||
311 | */ |
||
312 | public function setCellType($cellType) { |
||
323 | |||
324 | /** |
||
325 | * Set the class name. |
||
326 | * |
||
327 | * @param string $classname The class name. |
||
328 | * @return DataTablesColumn Returns the DataTables column. |
||
329 | */ |
||
330 | public function setClassname($classname) { |
||
334 | |||
335 | /** |
||
336 | * Set the content padding. |
||
337 | * |
||
338 | * @param string $contentPadding The content padding. |
||
339 | * @return DataTablesColumn Returns the DataTables column. |
||
340 | */ |
||
341 | public function setContentPadding($contentPadding) { |
||
345 | |||
346 | /** |
||
347 | * Set the data. |
||
348 | * |
||
349 | * @param integer|string $data The data. |
||
350 | * @return DataTablesColumn Returns the DataTables column. |
||
351 | */ |
||
352 | public function setData($data) { |
||
356 | |||
357 | /** |
||
358 | * Set the default content. |
||
359 | * |
||
360 | * @param string $defaultContent The default content. |
||
361 | * @return DataTablesColumn Returns the DataTables column. |
||
362 | */ |
||
363 | public function setDefaultContent($defaultContent) { |
||
367 | |||
368 | /** |
||
369 | * Set the name. |
||
370 | * |
||
371 | * @param string $name The name. |
||
372 | * @return DataTablesColumn Returns the DataTables column. |
||
373 | */ |
||
374 | public function setName($name) { |
||
378 | |||
379 | /** |
||
380 | * Set the order data. |
||
381 | * |
||
382 | * @param integer|array $orderData The order data. |
||
383 | * @return DataTablesColumn Returns the DataTables column. |
||
384 | */ |
||
385 | public function setOrderData($orderData) { |
||
389 | |||
390 | /** |
||
391 | * Set the order data type. |
||
392 | * |
||
393 | * @param string $orderDataType The order data type. |
||
394 | * @return DataTablesColumn Returns the DataTables column. |
||
395 | */ |
||
396 | public function setOrderDataType($orderDataType) { |
||
400 | |||
401 | /** |
||
402 | * Set the order sequence. |
||
403 | * |
||
404 | * @param string $orderSequence The order sequence. |
||
405 | * @return DataTablesColumn Returns the DataTables column. |
||
406 | */ |
||
407 | public function setOrderSequence($orderSequence) { |
||
418 | |||
419 | /** |
||
420 | * Set the orderable. |
||
421 | * |
||
422 | * @param boolean $orderable The orderable. |
||
423 | * @return DataTablesColumn Returns the DataTables column. |
||
424 | */ |
||
425 | public function setOrderable($orderable) { |
||
429 | |||
430 | /** |
||
431 | * Set the searchable. |
||
432 | * |
||
433 | * @param boolean $searchable The searchable. |
||
434 | * @return DataTablesColumn Returns the DataTables column. |
||
435 | */ |
||
436 | public function setSearchable($searchable) { |
||
440 | |||
441 | /** |
||
442 | * Set the title. |
||
443 | * |
||
444 | * @param string $title The title. |
||
445 | * @return DataTablesColumn Returns the DataTables column. |
||
446 | */ |
||
447 | public function setTitle($title) { |
||
451 | |||
452 | /** |
||
453 | * Set the type. |
||
454 | * |
||
455 | * @param string $type The type. |
||
456 | * @return DataTablesColumn Returns the DataTables column. |
||
457 | */ |
||
458 | public function setType($type) { |
||
473 | |||
474 | /** |
||
475 | * Set the visible. |
||
476 | * |
||
477 | * @param boolean $visible The visible. |
||
478 | * @return DataTablesColumn Returns the DataTables column. |
||
479 | */ |
||
480 | public function setVisible($visible) { |
||
484 | |||
485 | /** |
||
486 | * Set the width. |
||
487 | * |
||
488 | * @param string $width The width. |
||
489 | * @return DataTablesColumn Returns the DataTables column. |
||
490 | */ |
||
491 | public function setWidth($width) { |
||
495 | |||
496 | /** |
||
497 | * Convert into an array representing this instance. |
||
498 | * |
||
499 | * @return array Returns an array representing this instance. |
||
500 | */ |
||
501 | public function toArray() { |
||
555 | |||
556 | } |
||
557 |