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  | 
            ||
| 19 | abstract class Column extends FilterableColumn  | 
            ||
| 20 | { | 
            ||
| 21 | |||
| 22 | use Traits\TLink;  | 
            ||
| 23 | |||
| 24 | /**  | 
            ||
| 25 | * @var array  | 
            ||
| 26 | */  | 
            ||
| 27 | protected $replacements = [];  | 
            ||
| 28 | |||
| 29 | /**  | 
            ||
| 30 | * @var Renderer|NULL  | 
            ||
| 31 | */  | 
            ||
| 32 | protected $renderer;  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * @var string  | 
            ||
| 36 | */  | 
            ||
| 37 | protected $template;  | 
            ||
| 38 | |||
| 39 | /**  | 
            ||
| 40 | * @var bool|string  | 
            ||
| 41 | */  | 
            ||
| 42 | protected $sortable = FALSE;  | 
            ||
| 43 | |||
| 44 | /**  | 
            ||
| 45 | * @var bool  | 
            ||
| 46 | */  | 
            ||
| 47 | protected $sortable_reset_pagination = FALSE;  | 
            ||
| 48 | |||
| 49 | /**  | 
            ||
| 50 | * @var null|callable  | 
            ||
| 51 | */  | 
            ||
| 52 | protected $sortable_callback = NULL;  | 
            ||
| 53 | |||
| 54 | /**  | 
            ||
| 55 | * @var array  | 
            ||
| 56 | */  | 
            ||
| 57 | protected $sort;  | 
            ||
| 58 | |||
| 59 | /**  | 
            ||
| 60 | * @var bool  | 
            ||
| 61 | */  | 
            ||
| 62 | protected $template_escaping = TRUE;  | 
            ||
| 63 | |||
| 64 | /**  | 
            ||
| 65 | * @var bool  | 
            ||
| 66 | */  | 
            ||
| 67 | protected $header_escaping = FALSE;  | 
            ||
| 68 | |||
| 69 | |||
| 70 | /**  | 
            ||
| 71 | * @var string  | 
            ||
| 72 | */  | 
            ||
| 73 | protected $align;  | 
            ||
| 74 | |||
| 75 | |||
| 76 | /**  | 
            ||
| 77 | * @var array  | 
            ||
| 78 | */  | 
            ||
| 79 | protected $template_variables = [];  | 
            ||
| 80 | |||
| 81 | /**  | 
            ||
| 82 | * @var callable  | 
            ||
| 83 | */  | 
            ||
| 84 | protected $editable_callback;  | 
            ||
| 85 | |||
| 86 | /**  | 
            ||
| 87 | * @var array  | 
            ||
| 88 | */  | 
            ||
| 89 | protected $editable_element = ['textarea', ['class' => 'form-control']];  | 
            ||
| 90 | |||
| 91 | /**  | 
            ||
| 92 | * Cached html elements  | 
            ||
| 93 | * @var array  | 
            ||
| 94 | */  | 
            ||
| 95 | protected $el_cache = [];  | 
            ||
| 96 | |||
| 97 | /**  | 
            ||
| 98 | * @var bool  | 
            ||
| 99 | */  | 
            ||
| 100 | protected $default_hide = FALSE;  | 
            ||
| 101 | |||
| 102 | /**  | 
            ||
| 103 | * @var ColumnAggregationFunction  | 
            ||
| 104 | */  | 
            ||
| 105 | protected $aggregation_function = NULL;  | 
            ||
| 106 | |||
| 107 | |||
| 108 | /**  | 
            ||
| 109 | * Render row item into template  | 
            ||
| 110 | * @param Row $row  | 
            ||
| 111 | * @return mixed  | 
            ||
| 112 | */  | 
            ||
| 113 | public function render(Row $row)  | 
            ||
| 136 | |||
| 137 | |||
| 138 | /**  | 
            ||
| 139 | * Try to render item with custom renderer  | 
            ||
| 140 | * @param Row $row  | 
            ||
| 141 | * @return mixed  | 
            ||
| 142 | */  | 
            ||
| 143 | public function useRenderer(Row $row)  | 
            ||
| 161 | |||
| 162 | |||
| 163 | /**  | 
            ||
| 164 | * Should be column values escaped in latte?  | 
            ||
| 165 | * @param bool $template_escaping  | 
            ||
| 166 | */  | 
            ||
| 167 | public function setTemplateEscaping($template_escaping = TRUE)  | 
            ||
| 173 | |||
| 174 | |||
| 175 | public function isTemplateEscaped()  | 
            ||
| 179 | |||
| 180 | /**  | 
            ||
| 181 | * Should be column header escaped in latte?  | 
            ||
| 182 | * @param bool $header_escaping  | 
            ||
| 183 | */  | 
            ||
| 184 | public function setHeaderEscaping($header_escaping = FALSE)  | 
            ||
| 190 | |||
| 191 | public function isHeaderEscaped()  | 
            ||
| 195 | |||
| 196 | |||
| 197 | /**  | 
            ||
| 198 | * Set column sortable or not  | 
            ||
| 199 | * @param bool|string $sortable  | 
            ||
| 200 | */  | 
            ||
| 201 | public function setSortable($sortable = TRUE)  | 
            ||
| 207 | |||
| 208 | |||
| 209 | /**  | 
            ||
| 210 | * Tell whether column is sortable  | 
            ||
| 211 | * @return bool  | 
            ||
| 212 | */  | 
            ||
| 213 | public function isSortable()  | 
            ||
| 217 | |||
| 218 | |||
| 219 | /**  | 
            ||
| 220 | * Shoud be the pagination reseted after sorting?  | 
            ||
| 221 | * @param bool $sortable_reset_pagination  | 
            ||
| 222 | * @return static  | 
            ||
| 223 | */  | 
            ||
| 224 | public function setSortableResetPagination($sortable_reset_pagination = TRUE)  | 
            ||
| 230 | |||
| 231 | |||
| 232 | /**  | 
            ||
| 233 | * Do reset pagination after sorting?  | 
            ||
| 234 | * @return bool  | 
            ||
| 235 | */  | 
            ||
| 236 | public function sortableResetPagination()  | 
            ||
| 240 | |||
| 241 | |||
| 242 | /**  | 
            ||
| 243 | * Set custom ORDER BY clause  | 
            ||
| 244 | * @param callable $sortable_callback  | 
            ||
| 245 | * @return static  | 
            ||
| 246 | */  | 
            ||
| 247 | public function setSortableCallback(callable $sortable_callback)  | 
            ||
| 253 | |||
| 254 | |||
| 255 | /**  | 
            ||
| 256 | * Get custom ORDER BY clause  | 
            ||
| 257 | * @return callable|null  | 
            ||
| 258 | */  | 
            ||
| 259 | public function getSortableCallback()  | 
            ||
| 263 | |||
| 264 | |||
| 265 | /**  | 
            ||
| 266 | * Get column to sort by  | 
            ||
| 267 | * @return string  | 
            ||
| 268 | */  | 
            ||
| 269 | public function getSortingColumn()  | 
            ||
| 273 | |||
| 274 | |||
| 275 | /**  | 
            ||
| 276 | * Get column name  | 
            ||
| 277 | * @return string  | 
            ||
| 278 | */  | 
            ||
| 279 | public function getColumnName()  | 
            ||
| 283 | |||
| 284 | |||
| 285 | /**  | 
            ||
| 286 | * Get column value of row item  | 
            ||
| 287 | * @param Row $row  | 
            ||
| 288 | * @return mixed  | 
            ||
| 289 | */  | 
            ||
| 290 | public function getColumnValue(Row $row)  | 
            ||
| 294 | |||
| 295 | |||
| 296 | /**  | 
            ||
| 297 | * @return string  | 
            ||
| 298 | */  | 
            ||
| 299 | public function getName()  | 
            ||
| 303 | |||
| 304 | |||
| 305 | /**  | 
            ||
| 306 | * Set column replacements  | 
            ||
| 307 | * @param array $replacements  | 
            ||
| 308 | * @return Column  | 
            ||
| 309 | */  | 
            ||
| 310 | public function setReplacement(array $replacements)  | 
            ||
| 316 | |||
| 317 | |||
| 318 | /**  | 
            ||
| 319 | * Tell whether columns has replacements  | 
            ||
| 320 | * @return bool  | 
            ||
| 321 | */  | 
            ||
| 322 | public function hasReplacements()  | 
            ||
| 326 | |||
| 327 | |||
| 328 | /**  | 
            ||
| 329 | * Apply replacements  | 
            ||
| 330 | * @param Row $row  | 
            ||
| 331 | * @return array  | 
            ||
| 332 | */  | 
            ||
| 333 | public function applyReplacements(Row $row)  | 
            ||
| 343 | |||
| 344 | |||
| 345 | /**  | 
            ||
| 346 | * Set renderer callback and (it may be optional - the condition callback will decide)  | 
            ||
| 347 | * @param callable $renderer  | 
            ||
| 348 | */  | 
            ||
| 349 | public function setRenderer($renderer, $condition_callback = NULL)  | 
            ||
| 373 | |||
| 374 | |||
| 375 | /**  | 
            ||
| 376 | * Set renderer callback just if condition is truthy  | 
            ||
| 377 | * @param callable $renderer  | 
            ||
| 378 | */  | 
            ||
| 379 | public function setRendererOnCondition($renderer, $condition_callback)  | 
            ||
| 383 | |||
| 384 | |||
| 385 | /**  | 
            ||
| 386 | * Return custom renderer callback  | 
            ||
| 387 | * @return Renderer|null  | 
            ||
| 388 | */  | 
            ||
| 389 | public function getRenderer()  | 
            ||
| 393 | |||
| 394 | |||
| 395 | /**  | 
            ||
| 396 | * Column may have its own template  | 
            ||
| 397 | * @param string $template  | 
            ||
| 398 | */  | 
            ||
| 399 | public function setTemplate($template, array $template_variables = [])  | 
            ||
| 406 | |||
| 407 | |||
| 408 | /**  | 
            ||
| 409 | * Column can have variables that will be passed to custom template scope  | 
            ||
| 410 | * @return array  | 
            ||
| 411 | */  | 
            ||
| 412 | public function getTemplateVariables()  | 
            ||
| 416 | |||
| 417 | |||
| 418 | /**  | 
            ||
| 419 | * Tell whether column has its owntemplate  | 
            ||
| 420 | * @return bool  | 
            ||
| 421 | */  | 
            ||
| 422 | public function hasTemplate()  | 
            ||
| 426 | |||
| 427 | |||
| 428 | /**  | 
            ||
| 429 | * Get column template path  | 
            ||
| 430 | * @return string  | 
            ||
| 431 | */  | 
            ||
| 432 | public function getTemplate()  | 
            ||
| 436 | |||
| 437 | |||
| 438 | /**  | 
            ||
| 439 | * Tell whether data source is sorted by this collumn  | 
            ||
| 440 | * @return bool  | 
            ||
| 441 | */  | 
            ||
| 442 | public function isSortedBy()  | 
            ||
| 446 | |||
| 447 | |||
| 448 | /**  | 
            ||
| 449 | * Tell column his sorting options  | 
            ||
| 450 | * @param array $sort  | 
            ||
| 451 | */  | 
            ||
| 452 | public function setSort(array $sort)  | 
            ||
| 458 | |||
| 459 | |||
| 460 | /**  | 
            ||
| 461 | * What sorting will be applied after next click?  | 
            ||
| 462 | * @return array  | 
            ||
| 463 | */  | 
            ||
| 464 | public function getSortNext()  | 
            ||
| 474 | |||
| 475 | |||
| 476 | /**  | 
            ||
| 477 | * @return bool  | 
            ||
| 478 | */  | 
            ||
| 479 | public function hasSortNext()  | 
            ||
| 485 | |||
| 486 | |||
| 487 | /**  | 
            ||
| 488 | * Is sorting ascending?  | 
            ||
| 489 | * @return bool  | 
            ||
| 490 | */  | 
            ||
| 491 | public function isSortAsc()  | 
            ||
| 495 | |||
| 496 | |||
| 497 | /**  | 
            ||
| 498 | * Set column alignment  | 
            ||
| 499 | * @param string $align  | 
            ||
| 500 | */  | 
            ||
| 501 | public function setAlign($align)  | 
            ||
| 507 | |||
| 508 | |||
| 509 | /**  | 
            ||
| 510 | * Has column some alignment?  | 
            ||
| 511 | * @return bool [description]  | 
            ||
| 512 | */  | 
            ||
| 513 | public function hasAlign()  | 
            ||
| 517 | |||
| 518 | |||
| 519 | /**  | 
            ||
| 520 | * Get column alignment  | 
            ||
| 521 | * @return string  | 
            ||
| 522 | */  | 
            ||
| 523 | public function getAlign()  | 
            ||
| 527 | |||
| 528 | |||
| 529 | /**  | 
            ||
| 530 | * Set column content fit  | 
            ||
| 531 | * @param bool $fit_content  | 
            ||
| 532 | * @return $this  | 
            ||
| 533 | */  | 
            ||
| 534 | public function setFitContent($fit_content = TRUE)  | 
            ||
| 540 | |||
| 541 | |||
| 542 | /**  | 
            ||
| 543 | * Set callback that will be called after inline editing  | 
            ||
| 544 | * @param callable $editable_callback  | 
            ||
| 545 | */  | 
            ||
| 546 | public function setEditableCallback(callable $editable_callback)  | 
            ||
| 552 | |||
| 553 | |||
| 554 | /**  | 
            ||
| 555 | * Return callback that is used after inline editing  | 
            ||
| 556 | * @return callable  | 
            ||
| 557 | */  | 
            ||
| 558 | public function getEditableCallback()  | 
            ||
| 562 | |||
| 563 | |||
| 564 | /**  | 
            ||
| 565 | * Is column editable?  | 
            ||
| 566 | * @return bool  | 
            ||
| 567 | */  | 
            ||
| 568 | public function isEditable()  | 
            ||
| 572 | |||
| 573 | |||
| 574 | /**  | 
            ||
| 575 | * Element is by default textarea, user can change that  | 
            ||
| 576 | * @param string $el_type  | 
            ||
| 577 | * @param array $attrs  | 
            ||
| 578 | * @return static  | 
            ||
| 579 | */  | 
            ||
| 580 | public function setEditableInputType($el_type, array $attrs = [])  | 
            ||
| 586 | |||
| 587 | |||
| 588 | /**  | 
            ||
| 589 | * Change small inline edit input type to select  | 
            ||
| 590 | * @param array $options  | 
            ||
| 591 | * @return static  | 
            ||
| 592 | */  | 
            ||
| 593 | public function setEditableInputTypeSelect(array $options = [])  | 
            ||
| 607 | |||
| 608 | |||
| 609 | /**  | 
            ||
| 610 | * [getEditableInputType description]  | 
            ||
| 611 | * @return array  | 
            ||
| 612 | */  | 
            ||
| 613 | public function getEditableInputType()  | 
            ||
| 617 | |||
| 618 | |||
| 619 | /**  | 
            ||
| 620 | * Set attributes for both th and td element  | 
            ||
| 621 | * @param array $attrs  | 
            ||
| 622 | * @return static  | 
            ||
| 623 | */  | 
            ||
| 624 | public function addAttributes(array $attrs)  | 
            ||
| 631 | |||
| 632 | |||
| 633 | /**  | 
            ||
| 634 | * Get th/td column element  | 
            ||
| 635 | * @param string $tag th|td  | 
            ||
| 636 | * @param string $key  | 
            ||
| 637 | * @param Row|NULL $row  | 
            ||
| 638 | * @return Html  | 
            ||
| 639 | */  | 
            ||
| 640 | public function getElementPrototype($tag, $key = NULL, Row $row = NULL)  | 
            ||
| 683 | |||
| 684 | |||
| 685 | /**  | 
            ||
| 686 | * @param bool $default_hide  | 
            ||
| 687 | * @return static  | 
            ||
| 688 | */  | 
            ||
| 689 | public function setDefaultHide($default_hide = TRUE)  | 
            ||
| 699 | |||
| 700 | |||
| 701 | public function getDefaultHide()  | 
            ||
| 705 | |||
| 706 | |||
| 707 | /**  | 
            ||
| 708 | * Get row item params (E.g. action may be called id => $item->id, name => $item->name, ...)  | 
            ||
| 709 | * @param Row $row  | 
            ||
| 710 | * @param array $params_list  | 
            ||
| 711 | * @return array  | 
            ||
| 712 | */  | 
            ||
| 713 | protected function getItemParams(Row $row, array $params_list)  | 
            ||
| 723 | |||
| 724 | |||
| 725 | /**  | 
            ||
| 726 | * @return string  | 
            ||
| 727 | */  | 
            ||
| 728 | public function getColumn()  | 
            ||
| 732 | |||
| 733 | |||
| 734 | /**  | 
            ||
| 735 | * @return ColumnAggregationFunction  | 
            ||
| 736 | */  | 
            ||
| 737 | public function getAggregationFunction()  | 
            ||
| 741 | |||
| 742 | |||
| 743 | /**  | 
            ||
| 744 | * @return bool  | 
            ||
| 745 | */  | 
            ||
| 746 | public function hasAggregationFunction()  | 
            ||
| 750 | |||
| 751 | |||
| 752 | /**  | 
            ||
| 753 | * @param $aggregation_type use ColumnAggregationFunction::$aggregation_type...  | 
            ||
| 754 | * @param string $column  | 
            ||
| 755 | * @return ColumnAggregationFunction  | 
            ||
| 756 | */  | 
            ||
| 757 | public function setAggregationFunction($aggregation_type, $column = NULL)  | 
            ||
| 765 | }  | 
            ||
| 766 |