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 |
||
18 | class HtmlTable extends HtmlSemDoubleElement { |
||
19 | private $_colCount; |
||
20 | private $_compileParts; |
||
21 | private $_footer; |
||
22 | private $_afterCompileEvents; |
||
23 | |||
24 | public function __construct($identifier, $rowCount, $colCount) { |
||
32 | |||
33 | /** |
||
34 | * Returns/create eventually a part of the table corresponding to the $key : thead, tbody or tfoot |
||
35 | * @param string $key |
||
36 | * @return HtmlTableContent |
||
37 | */ |
||
38 | public function getPart($key) { |
||
47 | |||
48 | /** |
||
49 | * Returns/create eventually the body of the table |
||
50 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
51 | */ |
||
52 | public function getBody() { |
||
55 | |||
56 | /** |
||
57 | * Returns/create eventually the header of the table |
||
58 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
59 | */ |
||
60 | public function getHeader() { |
||
63 | |||
64 | /** |
||
65 | * Returns/create eventually the footer of the table |
||
66 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
67 | */ |
||
68 | public function getFooter() { |
||
71 | |||
72 | /** |
||
73 | * Checks if the part corresponding to $key exists |
||
74 | * @param string $key |
||
75 | * @return boolean |
||
76 | */ |
||
77 | public function hasPart($key) { |
||
80 | |||
81 | /** |
||
82 | * |
||
83 | * @param int $rowCount |
||
84 | * @param int $colCount |
||
85 | * @return \Ajax\semantic\html\content\table\HtmlTableContent |
||
86 | */ |
||
87 | public function setRowCount($rowCount, $colCount) { |
||
91 | |||
92 | /** |
||
93 | * Returns the cell (HtmlTD) at position $row,$col |
||
94 | * @param int $row |
||
95 | * @param int $col |
||
96 | * @return \Ajax\semantic\html\content\HtmlTD |
||
97 | */ |
||
98 | public function getCell($row, $col) { |
||
101 | |||
102 | /** |
||
103 | * Retuns the row at $rowIndex |
||
104 | * @param int $rowIndex |
||
105 | * @return \Ajax\semantic\html\content\HtmlTR |
||
106 | */ |
||
107 | public function getRow($rowIndex) { |
||
110 | |||
111 | /** |
||
112 | * Adds a new row and sets $values to his cols |
||
113 | * @param array $values |
||
114 | * @return HtmlTR |
||
115 | */ |
||
116 | public function addRow($values=array()) { |
||
121 | |||
122 | /** |
||
123 | * adds and returns a new row |
||
124 | * @return \Ajax\semantic\html\content\table\HtmlTR |
||
125 | */ |
||
126 | public function newRow() { |
||
129 | |||
130 | public function setValues($values=array()) { |
||
134 | |||
135 | public function setHeaderValues($values=array()) { |
||
138 | |||
139 | public function setFooterValues($values=array()) { |
||
142 | |||
143 | /** |
||
144 | * Sets values to the col at index $colIndex |
||
145 | * @param int $colIndex |
||
146 | * @param array $values |
||
147 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
148 | */ |
||
149 | public function setColValues($colIndex, $values=array()) { |
||
153 | |||
154 | /** |
||
155 | * Sets values to the row at index $rowIndex |
||
156 | * @param int $rowIndex |
||
157 | * @param array $values |
||
158 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
159 | */ |
||
160 | public function setRowValues($rowIndex, $values=array()) { |
||
164 | |||
165 | public function addColVariations($colIndex, $variations=array()) { |
||
168 | |||
169 | public function colCenter($colIndex) { |
||
172 | |||
173 | public function colRight($colIndex) { |
||
176 | |||
177 | public function colLeft($colIndex) { |
||
180 | |||
181 | private function colAlign($colIndex, $function) { |
||
194 | |||
195 | public function setCelled() { |
||
198 | |||
199 | public function setBasic($very=false) { |
||
204 | |||
205 | public function setCollapsing() { |
||
208 | |||
209 | public function setDefinition() { |
||
212 | |||
213 | public function setStructured() { |
||
216 | |||
217 | public function setSortable($colIndex=NULL) { |
||
223 | |||
224 | public function setSingleLine() { |
||
227 | |||
228 | public function setFixed() { |
||
231 | |||
232 | public function conditionalCellFormat($callback, $format) { |
||
236 | |||
237 | public function conditionalRowFormat($callback, $format) { |
||
241 | |||
242 | public function applyCells($callback) { |
||
246 | |||
247 | public function applyRows($callback) { |
||
251 | |||
252 | public function setSelectable() { |
||
255 | |||
256 | public function setStriped() { |
||
259 | |||
260 | /** |
||
261 | * |
||
262 | * {@inheritDoc} |
||
263 | * |
||
264 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
||
265 | */ |
||
266 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
278 | |||
279 | /** |
||
280 | * |
||
281 | * {@inheritDoc} |
||
282 | * |
||
283 | * @see \Ajax\common\html\BaseHtml::fromDatabaseObject() |
||
284 | */ |
||
285 | public function fromDatabaseObject($object, $function) { |
||
298 | |||
299 | /** |
||
300 | * @param array $parts |
||
301 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
302 | */ |
||
303 | public function setCompileParts($parts=["tbody"]) { |
||
307 | |||
308 | public function refresh(){ |
||
312 | |||
313 | public function run(JsUtils $js){ |
||
319 | |||
320 | /** |
||
321 | * The callback function called after the insertion of each row when fromDatabaseObjects is called |
||
322 | * callback function takes the parameters $row : the row inserted and $object: the instance of model used |
||
323 | * @param callable $callback |
||
324 | * @return \Ajax\semantic\html\collections\HtmlTable |
||
325 | */ |
||
326 | public function onNewRow($callback) { |
||
330 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.