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 | 34 | 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 | 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 | 2 | 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 | static function checkbox ($in = [], $data = []) { |
|
183 | /** |
||
184 | * Rendering of input[type=radio] with automatic adding labels and necessary classes |
||
185 | * |
||
186 | * @static |
||
187 | * |
||
188 | * @param array $in |
||
189 | * @param array $data |
||
190 | * |
||
191 | * @return string |
||
1 ignored issue
–
show
|
|||
192 | */ |
||
193 | 2 | static function radio ($in = [], $data = []) { |
|
215 | /** |
||
216 | * @static |
||
217 | * |
||
218 | * @param array $in |
||
219 | * @param array $data |
||
220 | * @param string $type |
||
221 | * |
||
222 | * @return bool|string |
||
223 | */ |
||
224 | 2 | protected static function common_checkbox_radio_pre (&$in, $data, $type) { |
|
239 | /** |
||
240 | * @static |
||
241 | * |
||
242 | * @param array $item |
||
243 | */ |
||
244 | 2 | protected static function common_checkbox_radio_post (&$item) { |
|
249 | /** |
||
250 | * @static |
||
251 | * |
||
252 | * @param array $in |
||
253 | * @param callable $callable |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | 2 | protected static function common_checkbox_radio_reduce ($in, $callable) { |
|
266 | } |
||
267 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.