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() |
|
| 96 | { |
||
| 97 | 7 | $legacyLanguages = \Xoops\Core\Locale\LegacyCodes::getLegacyName(\Xoops\Locale::getCurrent()); |
|
| 98 | 7 | return reset($legacyLanguages); |
|
| 99 | } |
||
| 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 | 1 | public static function getFonts() |
|
| 120 | { |
||
| 121 | return array( |
||
| 122 | 1 | 'Arial', |
|
| 123 | 'Courier', |
||
| 124 | 'Georgia', |
||
| 125 | 'Helvetica', |
||
| 126 | 'Impact', |
||
| 127 | 'Verdana', |
||
| 128 | 'Haettenschweiler' |
||
| 129 | ); |
||
| 130 | } |
||
| 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() |
|
| 143 | { |
||
| 144 | return array( |
||
| 145 | 1 | 'xx-small' => 'xx-Small', |
|
| 146 | 'x-small' => 'x-Small', |
||
| 147 | 'small' => 'Small', |
||
| 148 | 'medium' => 'Medium', |
||
| 149 | 'large' => 'Large', |
||
| 150 | 'x-large' => 'x-Large', |
||
| 151 | 'xx-large' => 'xx-Large' |
||
| 152 | ); |
||
| 153 | } |
||
| 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 = '…') |
|
| 172 | { |
||
| 173 | 1 | $str2 = mb_strcut($str, $start, $length - strlen($ellipsis)); |
|
| 174 | 1 | return $str2 . (mb_strlen($str)-$start != mb_strlen($str2) ? $ellipsis : ''); |
|
| 175 | } |
||
| 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) |
|
| 211 | { |
||
| 212 | 1 | $ret = Utf8::trim($text); |
|
| 213 | |||
| 214 | 1 | return $ret; |
|
| 215 | } |
||
| 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') |
|
| 233 | { |
||
| 234 | 36 | $workingTime = Time::cleanTime($time); |
|
| 235 | |||
| 236 | 36 | switch (strtolower($format)) { |
|
| 237 | 36 | case 'short': |
|
| 238 | 36 | case 's': |
|
| 239 | 2 | return Time::formatDateTime($workingTime, 'short'); |
|
| 240 | |||
| 241 | 34 | case 'medium': |
|
| 242 | 34 | case 'm': |
|
| 243 | 2 | return Time::formatDateTime($workingTime, 'medium'); |
|
| 244 | |||
| 245 | 32 | case 'long': |
|
| 246 | 32 | case 'l': |
|
| 247 | 2 | return Time::formatDateTime($workingTime, 'long'); |
|
| 248 | |||
| 249 | 30 | case 'full': |
|
| 250 | 30 | case 'f': |
|
| 251 | 2 | return Time::formatDateTime($workingTime, 'full'); |
|
| 252 | |||
| 253 | 28 | case 'custom': |
|
| 254 | 26 | case 'c': |
|
| 255 | 2 | $specialName = Calendar::getDateRelativeName($workingTime, true); |
|
| 256 | 2 | if ($specialName != '') { |
|
| 257 | 2 | return $specialName; |
|
| 258 | } |
||
| 259 | // no break - fall through |
||
| 260 | 26 | case 'elapse': |
|
| 261 | 12 | case 'e': |
|
| 262 | 14 | return Time::describeRelativeInterval($workingTime); |
|
| 263 | |||
| 264 | 12 | case 'short-date': |
|
| 265 | 2 | return Time::formatDate($workingTime, 'short'); |
|
| 266 | |||
| 267 | 10 | case 'short-time': |
|
| 268 | 2 | return Time::formatTime($workingTime, 'short'); |
|
| 269 | |||
| 270 | 8 | case 'medium-date': |
|
| 271 | 1 | return Time::formatDate($workingTime, 'medium'); |
|
| 272 | |||
| 273 | 7 | case 'medium-time': |
|
| 274 | 1 | return Time::formatTime($workingTime, 'medium'); |
|
| 275 | |||
| 276 | 6 | case 'long-date': |
|
| 277 | return Time::formatDate($workingTime, 'long'); |
||
| 278 | |||
| 279 | 6 | case 'long-time': |
|
| 280 | return Time::formatTime($workingTime, 'long'); |
||
| 281 | |||
| 282 | 6 | case 'full-date': |
|
| 283 | 1 | return Time::formatDate($workingTime, 'full'); |
|
| 284 | |||
| 285 | 5 | case 'full-time': |
|
| 286 | 1 | return Time::formatTime($workingTime, 'full'); |
|
| 287 | |||
| 288 | 4 | case 'rss': |
|
| 289 | 2 | $workingTime->setTimezone(new \DateTimeZone('UTC')); |
|
| 290 | 2 | return $workingTime->format($workingTime::RSS); |
|
| 291 | |||
| 292 | 2 | case 'mysql': |
|
| 293 | 2 | $workingTime->setTimezone(new \DateTimeZone('UTC')); |
|
| 294 | 2 | return $workingTime->format('Y-m-d H:i:s'); |
|
| 295 | |||
| 296 | default: |
||
| 297 | if ($format != '') { |
||
| 298 | return $workingTime->format($format); |
||
| 299 | } |
||
| 300 | return Time::formatDateTime($workingTime, 'long'); |
||
| 301 | break; |
||
| 302 | } |
||
| 303 | } |
||
| 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) |
|
| 322 | { |
||
| 323 | 1 | if (function_exists('money_format')) { |
|
| 324 | 1 | $result = money_format($format, $number); |
|
| 325 | } else { |
||
| 326 | $result = sprintf('%01.2f', $number); |
||
| 327 | } |
||
| 328 | |||
| 329 | 1 | return $result; |
|
| 330 | } |
||
| 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.