Complex classes like BaseHtml 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 BaseHtml, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | abstract class BaseHtml extends BaseWidget { |
||
18 | protected $_template; |
||
19 | protected $tagName; |
||
20 | protected $properties=array (); |
||
21 | protected $_events=array (); |
||
22 | protected $_wrapBefore=array (); |
||
23 | protected $_wrapAfter=array (); |
||
24 | protected $_bsComponent; |
||
25 | |||
26 | public function getBsComponent() { |
||
29 | |||
30 | public function setBsComponent($bsComponent) { |
||
34 | |||
35 | protected function getTemplate(JsUtils $js=NULL) { |
||
36 | return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
||
37 | } |
||
38 | |||
39 | public function getProperties() { |
||
42 | |||
43 | public function setProperties($properties) { |
||
47 | |||
48 | public function setProperty($name, $value) { |
||
52 | |||
53 | public function getProperty($name) { |
||
57 | |||
58 | public function addToProperty($name, $value, $separator=" ") { |
||
70 | |||
71 | public function addProperties($properties) { |
||
75 | |||
76 | public function compile(JsUtils $js=NULL, View $view=NULL) { |
||
101 | |||
102 | protected function ctrl($name, $value, $typeCtrl) { |
||
114 | |||
115 | protected function propertyContains($propertyName, $value) { |
||
122 | |||
123 | protected function setPropertyCtrl($name, $value, $typeCtrl) { |
||
128 | |||
129 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
||
135 | |||
136 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
||
143 | |||
144 | protected function removePropertyValue($name, $value) { |
||
148 | |||
149 | protected function removePropertyValues($name, $values) { |
||
153 | |||
154 | protected function removeProperty($name) { |
||
159 | |||
160 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
||
169 | |||
170 | protected function addToMember(&$name, $value, $separator=" ") { |
||
174 | |||
175 | protected function addToPropertyUnique($name, $value, $typeCtrl) { |
||
183 | |||
184 | public function addToPropertyCtrl($name, $value, $typeCtrl) { |
||
187 | |||
188 | public function addToPropertyCtrlCheck($name, $value, $typeCtrl) { |
||
194 | |||
195 | protected function removeOldValues(&$oldValue, $allValues) { |
||
199 | |||
200 | /** |
||
201 | * |
||
202 | * @param JsUtils $js |
||
203 | * @return SimpleExtComponent |
||
204 | */ |
||
205 | public abstract function run(JsUtils $js); |
||
206 | |||
207 | public function getTagName() { |
||
210 | |||
211 | public function setTagName($tagName) { |
||
215 | |||
216 | public function fromArray($array) { |
||
246 | |||
247 | public function fromDatabaseObjects($objects, $function) { |
||
255 | |||
256 | public function fromDatabaseObject($object, $function) { |
||
258 | |||
259 | public function wrap($before, $after="") { |
||
266 | |||
267 | public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
||
276 | |||
277 | public function _addEvent($event, $jsCode) { |
||
289 | |||
290 | public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
||
293 | |||
294 | public function onClick($jsCode, $stopPropagation=false, $preventDefault=true) { |
||
297 | |||
298 | public function setClick($jsCode) { |
||
301 | |||
302 | public function addEventsOnRun(JsUtils $js) { |
||
323 | |||
324 | public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) { |
||
330 | |||
331 | public function getOn($event, $url, $responseElement="", $parameters=array()) { |
||
334 | |||
335 | public function getOnClick($url, $responseElement="", $parameters=array()) { |
||
338 | |||
339 | public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) { |
||
343 | |||
344 | public function postOnClick($url, $params="{}", $responseElement="", $parameters=array()) { |
||
347 | |||
348 | public function postFormOn($event, $url, $form, $responseElement="", $parameters=array()) { |
||
352 | |||
353 | public function postFormOnClick($url, $form, $responseElement="", $parameters=array()) { |
||
356 | |||
357 | public function getElementById($identifier, $elements) { |
||
374 | |||
375 | public function __toString() { |
||
378 | |||
379 | /** |
||
380 | * Puts HTML values in quotes for use in jQuery code |
||
381 | * unless the supplied value contains the Javascript 'this' or 'event' |
||
382 | * object, in which case no quotes are added |
||
383 | * |
||
384 | * @param string $value |
||
385 | * @return string |
||
386 | */ |
||
387 | public function _prep_value($value) { |
||
396 | |||
397 | public function jsDoJquery($jqueryCall, $param="") { |
||
400 | |||
401 | public function executeOnRun($jsCode) { |
||
404 | |||
405 | public function jsHtml($content="") { |
||
408 | |||
409 | public function jsShow() { |
||
412 | |||
413 | public function jsHide() { |
||
416 | |||
417 | protected function setWrapBefore($wrapBefore) { |
||
421 | |||
422 | protected function setWrapAfter($wrapAfter) { |
||
426 | } |