Complex classes like html_Core 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 html_Core, and based on these observations, apply Extract Interface, too.
1 | <?php defined('SYSPATH') or die('No direct access allowed.'); |
||
12 | class html_Core |
||
13 | { |
||
14 | |||
15 | // Enable or disable automatic setting of target="_blank" |
||
16 | public static $windowed_urls = false; |
||
17 | |||
18 | /** |
||
19 | * Convert special characters to HTML entities |
||
20 | * |
||
21 | * @param string string to convert |
||
22 | * @param boolean encode existing entities |
||
23 | * @return string |
||
24 | */ |
||
25 | public static function specialchars($str, $double_encode = true) |
||
46 | |||
47 | /** |
||
48 | * Perform a html::specialchars() with additional URL specific encoding. |
||
49 | * |
||
50 | * @param string string to convert |
||
51 | * @param boolean encode existing entities |
||
52 | * @return string |
||
53 | */ |
||
54 | public static function specialurlencode($str, $double_encode = true) |
||
58 | |||
59 | /** |
||
60 | * Create HTML link anchors. |
||
61 | * |
||
62 | * @param string URL or URI string |
||
63 | * @param string link text |
||
64 | * @param array HTML anchor attributes |
||
65 | * @param string non-default protocol, eg: https |
||
66 | * @param boolean option to escape the title that is output |
||
67 | * @return string |
||
68 | */ |
||
69 | public static function anchor($uri, $title = null, $attributes = null, $protocol = null, $escape_title = false) |
||
94 | |||
95 | /** |
||
96 | * Creates an HTML anchor to a file. |
||
97 | * |
||
98 | * @param string name of file to link to |
||
99 | * @param string link text |
||
100 | * @param array HTML anchor attributes |
||
101 | * @param string non-default protocol, eg: ftp |
||
102 | * @return string |
||
103 | */ |
||
104 | public static function file_anchor($file, $title = null, $attributes = null, $protocol = null) |
||
114 | |||
115 | /** |
||
116 | * Similar to anchor, but with the protocol parameter first. |
||
117 | * |
||
118 | * @param string link protocol |
||
119 | * @param string URI or URL to link to |
||
120 | * @param string link text |
||
121 | * @param array HTML anchor attributes |
||
122 | * @return string |
||
123 | */ |
||
124 | public static function panchor($protocol, $uri, $title = null, $attributes = false) |
||
128 | |||
129 | /** |
||
130 | * Create an array of anchors from an array of link/title pairs. |
||
131 | * |
||
132 | * @param array link/title pairs |
||
133 | * @return array |
||
134 | */ |
||
135 | public static function anchor_array(array $array) |
||
144 | |||
145 | /** |
||
146 | * Generates an obfuscated version of an email address. |
||
147 | * |
||
148 | * @param string email address |
||
149 | * @return string |
||
150 | */ |
||
151 | public static function email($email) |
||
167 | |||
168 | /** |
||
169 | * Creates an email anchor. |
||
170 | * |
||
171 | * @param string email address to send to |
||
172 | * @param string link text |
||
173 | * @param array HTML anchor attributes |
||
174 | * @return string |
||
175 | */ |
||
176 | public static function mailto($email, $title = null, $attributes = null) |
||
206 | |||
207 | /** |
||
208 | * Generate a "breadcrumb" list of anchors representing the URI. |
||
209 | * |
||
210 | * @param array segments to use as breadcrumbs, defaults to using Router::$segments |
||
211 | * @return string |
||
212 | */ |
||
213 | public static function breadcrumb($segments = null) |
||
230 | |||
231 | /** |
||
232 | * Creates a meta tag. |
||
233 | * |
||
234 | * @param string|array tag name, or an array of tags |
||
235 | * @param string tag "content" value |
||
236 | * @return string |
||
237 | */ |
||
238 | public static function meta($tag, $value = null) |
||
256 | |||
257 | /** |
||
258 | * Creates a stylesheet link. |
||
259 | * |
||
260 | * @param string|array filename, or array of filenames to match to array of medias |
||
261 | * @param string|array media type of stylesheet, or array to match filenames |
||
262 | * @param boolean include the index_page in the link |
||
263 | * @return string |
||
264 | */ |
||
265 | public static function stylesheet($style, $media = false, $index = false) |
||
269 | |||
270 | /** |
||
271 | * Creates a link tag. |
||
272 | * |
||
273 | * @param string|array filename |
||
274 | * @param string|array relationship |
||
275 | * @param string|array mimetype |
||
276 | * @param string specifies suffix of the file |
||
277 | * @param string|array specifies on what device the document will be displayed |
||
278 | * @param boolean include the index_page in the link |
||
279 | * @return string |
||
280 | */ |
||
281 | public static function link($href, $rel, $type, $suffix = false, $media = false, $index = false) |
||
322 | |||
323 | /** |
||
324 | * Creates a script link. |
||
325 | * |
||
326 | * @param string|array filename |
||
327 | * @param boolean include the index_page in the link |
||
328 | * @return string |
||
329 | */ |
||
330 | public static function script($script, $index = false) |
||
354 | |||
355 | /** |
||
356 | * Creates a image link. |
||
357 | * |
||
358 | * @param string image source, or an array of attributes |
||
359 | * @param string|array image alt attribute, or an array of attributes |
||
360 | * @param boolean include the index_page in the link |
||
361 | * @return string |
||
362 | */ |
||
363 | public static function image($src = null, $alt = null, $index = false) |
||
382 | |||
383 | /** |
||
384 | * Compiles an array of HTML attributes into an attribute string. |
||
385 | * |
||
386 | * @param string|array array of attributes |
||
387 | * @return string |
||
388 | */ |
||
389 | public static function attributes($attrs) |
||
406 | } // End html |
||
407 |