Complex classes like AbstractLocale 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 AbstractLocale, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | abstract class AbstractLocale |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * isMultiByte - does locale depend on multi-byte characters? |
||
| 33 | * |
||
| 34 | * @return bool true always true with UTF-8 |
||
| 35 | * |
||
| 36 | * @deprecated since 2.6.0 -- UTF-8 is always used |
||
| 37 | */ |
||
| 38 | 1 | public static function isMultiByte() |
|
| 42 | |||
| 43 | /** |
||
| 44 | * isRtl - is text order right to left? |
||
| 45 | * |
||
| 46 | * @return bool true if right to left |
||
| 47 | */ |
||
| 48 | 1 | public static function isRtl() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * todo, do not forget to set this on locale load |
||
| 55 | */ |
||
| 56 | 1 | public static function setLocale() |
|
| 60 | |||
| 61 | /** |
||
| 62 | * getCharset - return current character set, always UTF-8 |
||
| 63 | * |
||
| 64 | * @return string character set |
||
| 65 | */ |
||
| 66 | 18 | public static function getCharset() |
|
| 70 | |||
| 71 | /** |
||
| 72 | * getLocale - return the current locale |
||
| 73 | * |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | 6 | public static function getLocale() |
|
| 80 | |||
| 81 | /** |
||
| 82 | * getLangCode - return language code for the current locale (locale with '-' separator) |
||
| 83 | * |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | 15 | public static function getLangCode() |
|
| 90 | |||
| 91 | /** |
||
| 92 | * getLegacyLanguage - return legacy language code for the current locale |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | 7 | public static function getLegacyLanguage() |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @return string |
||
| 103 | */ |
||
| 104 | 1 | public static function getTimezone() |
|
| 108 | |||
| 109 | /** |
||
| 110 | * The generic css fonts are: |
||
| 111 | * - cursive |
||
| 112 | * - fantasy |
||
| 113 | * - monospace |
||
| 114 | * - sans-serif |
||
| 115 | * - serif |
||
| 116 | * |
||
| 117 | * @return string[] |
||
| 118 | */ |
||
| 119 | 2 | public static function getFonts() |
|
| 131 | |||
| 132 | /** |
||
| 133 | * The css should adjust based on the |
||
| 134 | * html:lang(ja) { |
||
| 135 | * font-size: 150%; |
||
| 136 | * } |
||
| 137 | * Then classes can be relative to that base em |
||
| 138 | * CJK fonts may need to be shown in a larger size due to complex glyphs |
||
| 139 | * |
||
| 140 | * @return array |
||
| 141 | */ |
||
| 142 | 1 | public static function getFontSizes() |
|
| 154 | |||
| 155 | /** |
||
| 156 | * @return string[] |
||
| 157 | */ |
||
| 158 | 1 | public static function getAdminRssUrls() |
|
| 162 | |||
| 163 | /** |
||
| 164 | * @param mixed $str |
||
| 165 | * @param integer $start |
||
| 166 | * @param integer $length |
||
| 167 | * @param string $ellipsis |
||
| 168 | * |
||
| 169 | * @return string |
||
| 170 | */ |
||
| 171 | 1 | public static function substr($str, $start, $length, $ellipsis = '…') |
|
| 176 | |||
| 177 | /** |
||
| 178 | * filter to UTF-8, converts invalid $text as CP1252 and forces NFC normalization |
||
| 179 | * |
||
| 180 | * @param mixed $text |
||
| 181 | * |
||
| 182 | * @return string |
||
| 183 | */ |
||
| 184 | 1 | public static function utf8_encode($text) |
|
| 188 | |||
| 189 | /** |
||
| 190 | * @param mixed $text |
||
| 191 | * @param string $to |
||
| 192 | * @param string $from |
||
| 193 | * |
||
| 194 | * @return string |
||
| 195 | * |
||
| 196 | * @deprecated |
||
| 197 | */ |
||
| 198 | 1 | public static function convert_encoding($text, $to = 'utf-8', $from = '') |
|
| 202 | |||
| 203 | /** |
||
| 204 | * XoopsLocalAbstract::trim() |
||
| 205 | * |
||
| 206 | * @param mixed $text |
||
| 207 | * |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | 1 | public static function trim($text) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Function to display formatted times in user timezone |
||
| 219 | * |
||
| 220 | * @param mixed $time |
||
| 221 | * @param string $format Format codes () |
||
| 222 | * 's' or 'short' - short; |
||
| 223 | * 'm' or 'medium' - medium; |
||
| 224 | * 'l' or 'long' - long; |
||
| 225 | * 'c' or 'custom' - format determined according to interval to present; |
||
| 226 | * 'e' or 'elapse' - Elapsed; |
||
| 227 | * 'mysql' - Y-m-d H:i:s; |
||
| 228 | * 'rss' |
||
| 229 | * |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | 36 | public static function formatTimestamp($time, $format = 'l') |
|
| 304 | |||
| 305 | /** |
||
| 306 | * @param int $number |
||
| 307 | * |
||
| 308 | * @return string |
||
| 309 | */ |
||
| 310 | 1 | public static function number_format($number) |
|
| 314 | |||
| 315 | /** |
||
| 316 | * @param string $format |
||
| 317 | * @param string $number |
||
| 318 | * |
||
| 319 | * @return string |
||
| 320 | */ |
||
| 321 | 1 | public static function money_format($format, $number) |
|
| 331 | |||
| 332 | /** |
||
| 333 | * Sort array values according to current locale rules, maintaining index association |
||
| 334 | * |
||
| 335 | * @param array $array to sort |
||
| 336 | * @return void |
||
| 337 | */ |
||
| 338 | 5 | public static function asort(&$array) |
|
| 348 | } |
||
| 349 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.