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 | * @param string $name The column name. |
||
141 | * @param string $title The column title. |
||
142 | * @param string $cellType The column cell type. |
||
143 | */ |
||
144 | public function __construct($name, $title, $cellType = "td") { |
||
153 | |||
154 | /** |
||
155 | * Get the cell type. |
||
156 | * |
||
157 | * @return string Returns the cell type. |
||
158 | */ |
||
159 | public function getCellType() { |
||
162 | |||
163 | /** |
||
164 | * Get the class name. |
||
165 | * |
||
166 | * @return string Returns the class name. |
||
167 | */ |
||
168 | public function getClassname() { |
||
171 | |||
172 | /** |
||
173 | * Get the content padding. |
||
174 | * |
||
175 | * @return string Returns the content padding. |
||
176 | */ |
||
177 | public function getContentPadding() { |
||
180 | |||
181 | /** |
||
182 | * Get the data. |
||
183 | * |
||
184 | * @return integer|string Returns the data. |
||
185 | */ |
||
186 | public function getData() { |
||
189 | |||
190 | /** |
||
191 | * Get the default content |
||
192 | * |
||
193 | * @return string Returns the default content. |
||
194 | */ |
||
195 | public function getDefaultContent() { |
||
198 | |||
199 | /** |
||
200 | * Get the mapping. |
||
201 | * |
||
202 | * @return DataTablesMapping The mapping. |
||
203 | */ |
||
204 | public function getMapping() { |
||
207 | |||
208 | /** |
||
209 | * Get the name. |
||
210 | * |
||
211 | * @return string Returns the name. |
||
212 | */ |
||
213 | public function getName() { |
||
216 | |||
217 | /** |
||
218 | * Get the order data. |
||
219 | * |
||
220 | * @return integer|array Returns the order data. |
||
221 | */ |
||
222 | public function getOrderData() { |
||
225 | |||
226 | /** |
||
227 | * Get the order data type. |
||
228 | * |
||
229 | * @return string Returns the order data type. |
||
230 | */ |
||
231 | public function getOrderDataType() { |
||
234 | |||
235 | /** |
||
236 | * Get the order sequence. |
||
237 | * |
||
238 | * @return string Returns the order sequence. |
||
239 | */ |
||
240 | public function getOrderSequence() { |
||
243 | |||
244 | /** |
||
245 | * Get the orderable. |
||
246 | * |
||
247 | * @return boolean Returns the orderable. |
||
248 | */ |
||
249 | public function getOrderable() { |
||
252 | |||
253 | /** |
||
254 | * Get the searchable. |
||
255 | * |
||
256 | * @return boolean Returns the searchable. |
||
257 | */ |
||
258 | public function getSearchable() { |
||
261 | |||
262 | /** |
||
263 | * Get the title. |
||
264 | * |
||
265 | * @return string Returns the title. |
||
266 | */ |
||
267 | public function getTitle() { |
||
270 | |||
271 | /** |
||
272 | * Get the type. |
||
273 | * |
||
274 | * @return string Returns the type. |
||
275 | */ |
||
276 | public function getType() { |
||
279 | |||
280 | /** |
||
281 | * Get the visible. |
||
282 | * |
||
283 | * @return boolean Returns the visible. |
||
284 | */ |
||
285 | public function getVisible() { |
||
288 | |||
289 | /** |
||
290 | * Get the width. |
||
291 | * |
||
292 | * @return string Returns the width. |
||
293 | */ |
||
294 | public function getWidth() { |
||
297 | |||
298 | /** |
||
299 | * {@inheritdoc} |
||
300 | */ |
||
301 | public function jsonSerialize() { |
||
304 | |||
305 | /** |
||
306 | * Set the cell type. |
||
307 | * |
||
308 | * @param string $cellType The cell type. |
||
309 | * @return DataTablesColumn Returns this DataTables column. |
||
310 | */ |
||
311 | public function setCellType($cellType) { |
||
322 | |||
323 | /** |
||
324 | * Set the class name. |
||
325 | * |
||
326 | * @param string $classname The class name. |
||
327 | * @return DataTablesColumn Returns this DataTables column. |
||
328 | */ |
||
329 | public function setClassname($classname) { |
||
333 | |||
334 | /** |
||
335 | * Set the content padding. |
||
336 | * |
||
337 | * @param string $contentPadding The content padding. |
||
338 | * @return DataTablesColumn Returns this DataTables column. |
||
339 | */ |
||
340 | public function setContentPadding($contentPadding) { |
||
344 | |||
345 | /** |
||
346 | * Set the data. |
||
347 | * |
||
348 | * @param integer|string $data The data. |
||
349 | * @return DataTablesColumn Returns this DataTables column. |
||
350 | */ |
||
351 | public function setData($data) { |
||
355 | |||
356 | /** |
||
357 | * Set the default content. |
||
358 | * |
||
359 | * @param string $defaultContent The default content. |
||
360 | * @return DataTablesColumn Returns this DataTables column. |
||
361 | */ |
||
362 | public function setDefaultContent($defaultContent) { |
||
366 | |||
367 | /** |
||
368 | * Set the name. |
||
369 | * |
||
370 | * @param string $name The name. |
||
371 | * @return DataTablesColumn Returns this DataTables column. |
||
372 | */ |
||
373 | public function setName($name) { |
||
377 | |||
378 | /** |
||
379 | * Set the order data. |
||
380 | * |
||
381 | * @param integer|array $orderData The order data. |
||
382 | * @return DataTablesColumn Returns this DataTables column. |
||
383 | */ |
||
384 | public function setOrderData($orderData) { |
||
388 | |||
389 | /** |
||
390 | * Set the order data type. |
||
391 | * |
||
392 | * @param string $orderDataType The order data type. |
||
393 | * @return DataTablesColumn Returns this DataTables column. |
||
394 | */ |
||
395 | public function setOrderDataType($orderDataType) { |
||
399 | |||
400 | /** |
||
401 | * Set the order sequence. |
||
402 | * |
||
403 | * @param string $orderSequence The order sequence. |
||
404 | * @return DataTablesColumn Returns this DataTables column. |
||
405 | */ |
||
406 | public function setOrderSequence($orderSequence) { |
||
417 | |||
418 | /** |
||
419 | * Set the orderable. |
||
420 | * |
||
421 | * @param boolean $orderable The orderable. |
||
422 | * @return DataTablesColumn Returns this DataTables column. |
||
423 | */ |
||
424 | public function setOrderable($orderable) { |
||
428 | |||
429 | /** |
||
430 | * Set the searchable. |
||
431 | * |
||
432 | * @param boolean $searchable The searchable. |
||
433 | * @return DataTablesColumn Returns this DataTables column. |
||
434 | */ |
||
435 | public function setSearchable($searchable) { |
||
439 | |||
440 | /** |
||
441 | * Set the title. |
||
442 | * |
||
443 | * @param string $title The title. |
||
444 | * @return DataTablesColumn Returns this DataTables column. |
||
445 | */ |
||
446 | public function setTitle($title) { |
||
450 | |||
451 | /** |
||
452 | * Set the type. |
||
453 | * |
||
454 | * @param string $type The type. |
||
455 | * @return DataTablesColumn Returns this DataTables column. |
||
456 | */ |
||
457 | public function setType($type) { |
||
472 | |||
473 | /** |
||
474 | * Set the visible. |
||
475 | * |
||
476 | * @param boolean $visible The visible. |
||
477 | * @return DataTablesColumn Returns this DataTables column. |
||
478 | */ |
||
479 | public function setVisible($visible) { |
||
483 | |||
484 | /** |
||
485 | * Set the width. |
||
486 | * |
||
487 | * @param string $width The width. |
||
488 | * @return DataTablesColumn Returns this DataTables column. |
||
489 | */ |
||
490 | public function setWidth($width) { |
||
494 | |||
495 | /** |
||
496 | * Convert into an array representing this instance. |
||
497 | * |
||
498 | * @return array Returns an array representing this instance. |
||
499 | */ |
||
500 | public function toArray() { |
||
524 | |||
525 | } |
||
526 |