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 | private $_compileParts; |
||
| 20 | private $_footer; |
||
| 21 | |||
| 22 | public function __construct($identifier, $rowCount, $colCount) { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Returns/create eventually a part of the table corresponding to the $key : thead, tbody or tfoot |
||
| 32 | * @param string $key |
||
| 33 | * @return HtmlTableContent |
||
| 34 | */ |
||
| 35 | public function getPart($key) { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Returns/create eventually the body of the table |
||
| 47 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 48 | */ |
||
| 49 | public function getBody() { |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Returns/create eventually the header of the table |
||
| 55 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 56 | */ |
||
| 57 | public function getHeader() { |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Returns/create eventually the footer of the table |
||
| 63 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 64 | */ |
||
| 65 | public function getFooter() { |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Checks if the part corresponding to $key exists |
||
| 71 | * @param string $key |
||
| 72 | * @return boolean |
||
| 73 | */ |
||
| 74 | public function hasPart($key) { |
||
| 77 | |||
| 78 | /** |
||
| 79 | * |
||
| 80 | * @param int $rowCount |
||
| 81 | * @param int $colCount |
||
| 82 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
| 83 | */ |
||
| 84 | public function setRowCount($rowCount, $colCount) { |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Returns the cell (HtmlTD) at position $row,$col |
||
| 91 | * @param int $row |
||
| 92 | * @param int $col |
||
| 93 | * @return \Ajax\semantic\html\content\HtmlTD |
||
| 94 | */ |
||
| 95 | public function getCell($row, $col) { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Retuns the row at $rowIndex |
||
| 101 | * @param int $rowIndex |
||
| 102 | * @return \Ajax\semantic\html\content\HtmlTR |
||
| 103 | */ |
||
| 104 | public function getRow($rowIndex) { |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Adds a new row and sets $values to his cols |
||
| 110 | * @param array $values |
||
| 111 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
| 112 | */ |
||
| 113 | public function addRow($values=array()) { |
||
| 118 | |||
| 119 | /** |
||
| 120 | * adds and returns a new row |
||
| 121 | * @return \Ajax\semantic\html\content\table\HtmlTR |
||
| 122 | */ |
||
| 123 | public function newRow() { |
||
| 126 | |||
| 127 | public function setValues($values=array()) { |
||
| 131 | |||
| 132 | public function setHeaderValues($values=array()) { |
||
| 135 | |||
| 136 | public function setFooterValues($values=array()) { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Sets values to the col at index $colIndex |
||
| 142 | * @param int $colIndex |
||
| 143 | * @param array $values |
||
| 144 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
| 145 | */ |
||
| 146 | public function setColValues($colIndex, $values=array()) { |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Sets values to the row at index $rowIndex |
||
| 153 | * @param int $rowIndex |
||
| 154 | * @param array $values |
||
| 155 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
| 156 | */ |
||
| 157 | public function setRowValues($rowIndex, $values=array()) { |
||
| 161 | |||
| 162 | public function addColVariations($colIndex, $variations=array()) { |
||
| 165 | |||
| 166 | public function colCenter($colIndex) { |
||
| 169 | |||
| 170 | public function colRight($colIndex) { |
||
| 173 | |||
| 174 | public function colLeft($colIndex) { |
||
| 177 | |||
| 178 | private function colAlign($colIndex, $function) { |
||
| 191 | |||
| 192 | public function setCelled() { |
||
| 195 | |||
| 196 | public function setBasic($very=false) { |
||
| 201 | |||
| 202 | public function setCollapsing() { |
||
| 205 | |||
| 206 | public function setDefinition() { |
||
| 209 | |||
| 210 | public function setStructured() { |
||
| 213 | |||
| 214 | public function setSortable($colIndex=NULL) { |
||
| 220 | |||
| 221 | public function setSingleLine() { |
||
| 224 | |||
| 225 | public function setFixed() { |
||
| 228 | |||
| 229 | public function conditionalCellFormat($callback, $format) { |
||
| 233 | |||
| 234 | public function conditionalRowFormat($callback, $format) { |
||
| 238 | |||
| 239 | public function applyCells($callback) { |
||
| 243 | |||
| 244 | public function applyRows($callback) { |
||
| 248 | |||
| 249 | public function setSelectable() { |
||
| 252 | |||
| 253 | /** |
||
| 254 | * |
||
| 255 | * {@inheritDoc} |
||
| 256 | * |
||
| 257 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
||
| 258 | */ |
||
| 259 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
| 271 | |||
| 272 | /** |
||
| 273 | * |
||
| 274 | * {@inheritDoc} |
||
| 275 | * |
||
| 276 | * @see \Ajax\common\html\BaseHtml::fromDatabaseObject() |
||
| 277 | */ |
||
| 278 | public function fromDatabaseObject($object, $function) { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @param array $parts |
||
| 289 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
| 290 | */ |
||
| 291 | public function setCompileParts($parts=["tbody"]) { |
||
| 295 | |||
| 296 | public function refresh(){ |
||
| 300 | |||
| 301 | public function run(JsUtils $js){ |
||
| 307 | |||
| 308 | } |