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 | /** |
||
| 97 | * Retuns the row at $rowIndex |
||
| 98 | * @param int $rowIndex |
||
| 99 | * @return \Ajax\semantic\html\content\HtmlTR |
||
| 100 | */ |
||
| 101 | public function getRow($rowIndex) { |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Adds a new row and sets $values to his cols |
||
| 107 | * @param array $values |
||
| 108 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
| 109 | */ |
||
| 110 | public function addRow($values=array()) { |
||
| 115 | |||
| 116 | /** |
||
| 117 | * adds and returns a new row |
||
| 118 | * @return \Ajax\semantic\html\content\table\HtmlTR |
||
| 119 | */ |
||
| 120 | public function newRow() { |
||
| 123 | |||
| 124 | public function setValues($values=array()) { |
||
| 128 | |||
| 129 | public function setHeaderValues($values=array()) { |
||
| 132 | |||
| 133 | public function setFooterValues($values=array()) { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Sets values to the col at index $colIndex |
||
| 139 | * @param int $colIndex |
||
| 140 | * @param array $values |
||
| 141 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
| 142 | */ |
||
| 143 | public function setColValues($colIndex, $values=array()) { |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Sets values to the row at index $rowIndex |
||
| 150 | * @param int $rowIndex |
||
| 151 | * @param array $values |
||
| 152 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
| 153 | */ |
||
| 154 | public function setRowValues($rowIndex, $values=array()) { |
||
| 158 | |||
| 159 | public function addColVariations($colIndex, $variations=array()) { |
||
| 162 | |||
| 163 | public function colCenter($colIndex) { |
||
| 166 | |||
| 167 | public function colRight($colIndex) { |
||
| 170 | |||
| 171 | public function colLeft($colIndex) { |
||
| 174 | |||
| 175 | private function colAlign($colIndex, $function) { |
||
| 188 | |||
| 189 | public function setCelled() { |
||
| 192 | |||
| 193 | public function setBasic($very=false) { |
||
| 198 | |||
| 199 | public function setCollapsing() { |
||
| 202 | |||
| 203 | public function setDefinition() { |
||
| 206 | |||
| 207 | public function setStructured() { |
||
| 210 | |||
| 211 | public function setSortable($colIndex=NULL) { |
||
| 217 | |||
| 218 | public function setSingleLine() { |
||
| 221 | |||
| 222 | public function setFixed() { |
||
| 225 | |||
| 226 | public function conditionalCellFormat($callback, $format) { |
||
| 230 | |||
| 231 | public function conditionalRowFormat($callback, $format) { |
||
| 235 | |||
| 236 | public function applyCells($callback) { |
||
| 240 | |||
| 241 | public function applyRows($callback) { |
||
| 245 | |||
| 246 | public function setSelectable() { |
||
| 249 | |||
| 250 | /** |
||
| 251 | * |
||
| 252 | * {@inheritDoc} |
||
| 253 | * |
||
| 254 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
||
| 255 | */ |
||
| 256 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
| 263 | |||
| 264 | /** |
||
| 265 | * |
||
| 266 | * {@inheritDoc} |
||
| 267 | * |
||
| 268 | * @see \Ajax\common\html\BaseHtml::fromDatabaseObject() |
||
| 269 | */ |
||
| 270 | public function fromDatabaseObject($object, $function) { |
||
| 278 | } |
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.