Complex classes like HtmlTable 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 HtmlTable, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class HtmlTable extends HtmlSemDoubleElement { |
||
| 18 | private $_colCount; |
||
| 19 | |||
| 20 | public function __construct($identifier, $rowCount, $colCount) { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Returns/create eventually a part of the table corresponding to the $key : thead, tbody or tfoot |
||
| 29 | * @param string $key |
||
| 30 | * @return HtmlTableContent |
||
| 31 | */ |
||
| 32 | private function getPart($key) { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Returns/create eventually the body of the table |
||
| 44 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 45 | */ |
||
| 46 | public function getBody() { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Returns/create eventually the header of the table |
||
| 52 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 53 | */ |
||
| 54 | public function getHeader() { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns/create eventually the footer of the table |
||
| 60 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 61 | */ |
||
| 62 | public function getFooter() { |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Checks if the part corresponding to $key exists |
||
| 68 | * @param string $key |
||
| 69 | * @return boolean |
||
| 70 | */ |
||
| 71 | public function hasPart($key) { |
||
| 74 | |||
| 75 | /** |
||
| 76 | * |
||
| 77 | * @param int $rowCount |
||
| 78 | * @param int $colCount |
||
| 79 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 80 | */ |
||
| 81 | public function setRowCount($rowCount, $colCount) { |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Returns the cell (HtmlTD) at position $row,$col |
||
| 88 | * @param int $row |
||
| 89 | * @param int $col |
||
| 90 | * @return \Ajax\semantic\html\content\HtmlTD |
||
| 91 | */ |
||
| 92 | public function getCell($row, $col) { |
||
| 95 | |||
| 96 | public function getRow($rowIndex) { |
||
| 99 | |||
| 100 | public function addRow($values=array()) { |
||
| 105 | |||
| 106 | public function newRow() { |
||
| 109 | |||
| 110 | public function setValues($values=array()) { |
||
| 114 | |||
| 115 | public function setHeaderValues($values=array()) { |
||
| 118 | |||
| 119 | public function setFooterValues($values=array()) { |
||
| 122 | |||
| 123 | public function setColValues($colIndex, $values=array()) { |
||
| 127 | |||
| 128 | public function setRowValues($rowIndex, $values=array()) { |
||
| 132 | |||
| 133 | public function addColVariations($colIndex, $variations=array()) { |
||
| 136 | |||
| 137 | public function colCenter($colIndex) { |
||
| 140 | |||
| 141 | public function colRight($colIndex) { |
||
| 144 | |||
| 145 | public function colLeft($colIndex) { |
||
| 148 | |||
| 149 | private function colAlign($colIndex, $function) { |
||
| 162 | |||
| 163 | public function setCelled() { |
||
| 166 | |||
| 167 | public function setBasic($very=false) { |
||
| 172 | |||
| 173 | public function setCollapsing() { |
||
| 176 | |||
| 177 | public function setDefinition() { |
||
| 180 | |||
| 181 | public function setStructured() { |
||
| 184 | |||
| 185 | public function setSortable($colIndex=NULL) { |
||
| 191 | |||
| 192 | public function setSingleLine() { |
||
| 195 | |||
| 196 | public function setFixed() { |
||
| 199 | |||
| 200 | public function conditionalCellFormat($callback, $format) { |
||
| 204 | |||
| 205 | public function conditionalRowFormat($callback, $format) { |
||
| 209 | |||
| 210 | public function applyCells($callback) { |
||
| 214 | |||
| 215 | public function applyRows($callback) { |
||
| 219 | |||
| 220 | public function setSelectable() { |
||
| 223 | |||
| 224 | /** |
||
| 225 | * |
||
| 226 | * {@inheritDoc} |
||
| 227 | * |
||
| 228 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
||
| 229 | */ |
||
| 230 | public function compile(JsUtils $js=NULL, View $view=NULL) { |
||
| 237 | |||
| 238 | /** |
||
| 239 | * |
||
| 240 | * {@inheritDoc} |
||
| 241 | * |
||
| 242 | * @see \Ajax\common\html\BaseHtml::fromDatabaseObject() |
||
| 243 | */ |
||
| 244 | public function fromDatabaseObject($object, $function) { |
||
| 252 | } |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.