Complex classes like Base 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 Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | abstract class Base extends BananaHTML { |
||
| 22 | /** |
||
| 23 | * Special processing for URLs with hash |
||
| 24 | * |
||
| 25 | * @static |
||
| 26 | * |
||
| 27 | * @param string $url |
||
| 28 | * |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | 2 | protected static function url_with_hash ($url) { |
|
| 34 | /** |
||
| 35 | * Convert relative URL to absolute |
||
| 36 | * |
||
| 37 | * @static |
||
| 38 | * |
||
| 39 | * @param string $url |
||
| 40 | * |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | 2 | protected static function absolute_url ($url) { |
|
| 49 | /** |
||
| 50 | * Allows to add something to inner of form, for example, hidden session input to prevent CSRF |
||
| 51 | * |
||
| 52 | * @static |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | 2 | protected static function form_csrf () { |
|
| 71 | /** |
||
| 72 | * CleverStyle Framework-specific processing of attributes |
||
| 73 | * |
||
| 74 | * @static |
||
| 75 | * |
||
| 76 | * @param string $tag |
||
| 77 | * @param array $attributes |
||
| 78 | */ |
||
| 79 | 36 | protected static function pre_processing ($tag, &$attributes) { |
|
| 92 | /** |
||
| 93 | * Sometimes HTML code can be intended |
||
| 94 | * |
||
| 95 | * This function allows to store inner text of tags, that are sensitive to this operation (textarea, pre, code), and return some identifier. |
||
| 96 | * Later, at page generation, this identifier will be replaced by original text again. |
||
| 97 | * |
||
| 98 | * @param string $text |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | 2 | protected static function indentation_protection ($text) { |
|
| 107 | /** |
||
| 108 | * Pseudo tag for labels with tooltips, specified <i>input</i> is translation item of <b>$L</b> object, |
||
| 109 | * <i>input</i>_into item of <b>$L</b> is content of tooltip |
||
| 110 | * |
||
| 111 | * @static |
||
| 112 | * |
||
| 113 | * @param array|string $in |
||
| 114 | * @param array $data |
||
| 115 | * |
||
| 116 | * @return mixed |
||
| 117 | */ |
||
| 118 | 2 | public static function info ($in = '', $data = []) { |
|
| 135 | /** |
||
| 136 | * Pseudo tag for inserting of icons |
||
| 137 | * |
||
| 138 | * @static |
||
| 139 | * |
||
| 140 | * @param string $icon Icon name in Font Awesome |
||
| 141 | * @param array $data |
||
| 142 | * |
||
| 143 | * @return mixed |
||
| 144 | */ |
||
| 145 | 6 | public static function icon ($icon, $data = []) { |
|
| 155 | /** |
||
| 156 | * Rendering of input[type=checkbox] with automatic adding labels and necessary classes |
||
| 157 | * |
||
| 158 | * @static |
||
| 159 | * |
||
| 160 | * @param array $in |
||
| 161 | * @param array $data |
||
| 162 | * |
||
| 163 | * @return string |
||
| 164 | */ |
||
| 165 | 2 | public static function checkbox ($in = [], $data = []) { |
|
| 181 | /** |
||
| 182 | * Rendering of input[type=radio] with automatic adding labels and necessary classes |
||
| 183 | * |
||
| 184 | * @static |
||
| 185 | * |
||
| 186 | * @param array $in |
||
| 187 | * @param array $data |
||
| 188 | * |
||
| 189 | * @return string |
||
| 190 | */ |
||
| 191 | 2 | public static function radio ($in = [], $data = []) { |
|
| 212 | /** |
||
| 213 | * @static |
||
| 214 | * |
||
| 215 | * @param array $in |
||
| 216 | * @param array $data |
||
| 217 | * @param string $type |
||
| 218 | * |
||
| 219 | * @return bool|string |
||
| 220 | */ |
||
| 221 | 2 | protected static function common_checkbox_radio_pre (&$in, $data, $type) { |
|
| 236 | /** |
||
| 237 | * @static |
||
| 238 | * |
||
| 239 | * @param array $item |
||
| 240 | */ |
||
| 241 | 2 | protected static function common_checkbox_radio_post (&$item) { |
|
| 246 | /** |
||
| 247 | * @static |
||
| 248 | * |
||
| 249 | * @param array $in |
||
| 250 | * @param callable $callable |
||
| 251 | * |
||
| 252 | * @return string |
||
| 253 | */ |
||
| 254 | 2 | protected static function common_checkbox_radio_reduce ($in, $callable) { |
|
| 262 | } |
||
| 263 |