| Total Complexity | 41 |
| Total Lines | 204 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Lezer 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.
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 Lezer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class Lezer extends \i18n{ |
||
| 15 | |||
| 16 | private $detected_language_files = []; |
||
| 17 | private $detected_language_env = []; |
||
| 18 | |||
| 19 | // protected $basePath = 'locale'; |
||
| 20 | // protected $filePath = 'locale/{LANGUAGE}/user_interface.ini'; // uses gettext hierarchy |
||
| 21 | // protected $cachePath = 'locale/cache/'; |
||
| 22 | // protected $fallbackLang = 'fra'; // uses ISO-639-3 |
||
| 23 | protected $currentLang = null; |
||
| 24 | |||
| 25 | public function one_language() |
||
| 35 | } |
||
| 36 | |||
| 37 | public function detect_language_files() |
||
| 48 | } |
||
| 49 | |||
| 50 | public function compileFunction() |
||
| 59 | } |
||
| 60 | /** |
||
| 61 | * getUserLangs() |
||
| 62 | * Returns the user languages |
||
| 63 | * Normally it returns an array like this: |
||
| 64 | * 1. Forced language |
||
| 65 | * 2. Language in $_GET['lang'] |
||
| 66 | * 3. Language in $_SESSION['lang'] |
||
| 67 | * 4. COOKIE |
||
| 68 | * 5. Fallback language |
||
| 69 | * Note: duplicate values are deleted. |
||
| 70 | * |
||
| 71 | * @return array with the user languages sorted by priority. |
||
| 72 | */ |
||
| 73 | public function detect_language_env() { |
||
| 109 | } |
||
| 110 | |||
| 111 | |||
| 112 | public static function model_type_to_label($form_model) |
||
| 113 | { |
||
| 114 | return L(sprintf('MODEL_%s_INSTANCE',get_class($form_model)::model_type())); |
||
|
|
|||
| 115 | } |
||
| 116 | public static function field_name_to_label($form_model, $field_name) |
||
| 117 | { |
||
| 118 | return L(sprintf('MODEL_%s_FIELD_%s',(get_class($form_model))::model_type(), $field_name)); |
||
| 119 | } |
||
| 120 | |||
| 121 | // options['decimals'] = int |
||
| 122 | // options['abbrev'] = mixed: key needs to be set |
||
| 123 | public static function when($event, $options=[]) |
||
| 173 | } |
||
| 174 | |||
| 175 | public static function time($time_string, $short=true) |
||
| 176 | { |
||
| 177 | if ($short === true) |
||
| 178 | $time_string = substr($time_string, 0, 5); |
||
| 179 | return $time_string; |
||
| 180 | } |
||
| 181 | |||
| 182 | public static function human_date($date_string, $short=true) |
||
| 198 | } |
||
| 199 | |||
| 200 | public static function human_month($date_string) |
||
| 201 | { |
||
| 202 | return L('DATETIME_CALENDAR_MONTH_'.Dato::format($date_string, 'm')); |
||
| 203 | } |
||
| 204 | |||
| 205 | public static function human_day($date_string) |
||
| 208 | } |
||
| 209 | |||
| 210 | public static function human_seconds($seconds) |
||
| 211 | { |
||
| 212 | $hours = floor($seconds / 3600); |
||
| 224 |