| Conditions | 7 |
| Paths | 9 |
| Total Lines | 127 |
| Code Lines | 117 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 66 | public static function convertDateIcuToPhp($pattern, $type = 'date', $locale): string |
||
| 67 | { |
||
| 68 | if (isset(self::$icuShortFormats[$pattern])) { |
||
| 69 | if (extension_loaded('intl')) { |
||
| 70 | if ($type === 'date') { |
||
| 71 | $formatter = new IntlDateFormatter($locale, self::$icuShortFormats[$pattern], IntlDateFormatter::NONE); |
||
| 72 | } elseif ($type === 'time') { |
||
| 73 | $formatter = new IntlDateFormatter($locale, IntlDateFormatter::NONE, self::$icuShortFormats[$pattern]); |
||
| 74 | } else { |
||
| 75 | $formatter = new IntlDateFormatter($locale, self::$icuShortFormats[$pattern], self::$icuShortFormats[$pattern]); |
||
| 76 | } |
||
| 77 | $pattern = $formatter->getPattern(); |
||
| 78 | } else { |
||
| 79 | return static::$phpFallbackDatePatterns[$pattern][$type]; |
||
|
|
|||
| 80 | } |
||
| 81 | } |
||
| 82 | // http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax |
||
| 83 | // escaped text |
||
| 84 | $escaped = []; |
||
| 85 | if (preg_match_all('/(?<!\')\'(.*?[^\'])\'(?!\')/', $pattern, $matches, PREG_SET_ORDER)) { |
||
| 86 | foreach ($matches as $match) { |
||
| 87 | $match[1] = str_replace('\'\'', '\'', $match[1]); |
||
| 88 | $escaped[$match[0]] = '\\' . implode('\\', preg_split('//u', $match[1], -1, PREG_SPLIT_NO_EMPTY)); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | return strtr($pattern, array_merge($escaped, [ |
||
| 93 | "''" => "\\'", // two single quotes produce one |
||
| 94 | 'G' => '', // era designator like (Anno Domini) |
||
| 95 | 'Y' => 'o', // 4digit year of "Week of Year" |
||
| 96 | 'y' => 'Y', // 4digit year e.g. 2014 |
||
| 97 | 'yyyy' => 'Y', // 4digit year e.g. 2014 |
||
| 98 | 'yy' => 'y', // 2digit year number eg. 14 |
||
| 99 | 'u' => '', // extended year e.g. 4601 |
||
| 100 | 'U' => '', // cyclic year name, as in Chinese lunar calendar |
||
| 101 | 'r' => '', // related Gregorian year e.g. 1996 |
||
| 102 | 'Q' => '', // number of quarter |
||
| 103 | 'QQ' => '', // number of quarter '02' |
||
| 104 | 'QQQ' => '', // quarter 'Q2' |
||
| 105 | 'QQQQ' => '', // quarter '2nd quarter' |
||
| 106 | 'QQQQQ' => '', // number of quarter '2' |
||
| 107 | 'q' => '', // number of Stand Alone quarter |
||
| 108 | 'qq' => '', // number of Stand Alone quarter '02' |
||
| 109 | 'qqq' => '', // Stand Alone quarter 'Q2' |
||
| 110 | 'qqqq' => '', // Stand Alone quarter '2nd quarter' |
||
| 111 | 'qqqqq' => '', // number of Stand Alone quarter '2' |
||
| 112 | 'M' => 'n', // Numeric representation of a month, without leading zeros |
||
| 113 | 'MM' => 'm', // Numeric representation of a month, with leading zeros |
||
| 114 | 'MMM' => 'M', // A short textual representation of a month, three letters |
||
| 115 | 'MMMM' => 'F', // A full textual representation of a month, such as January or March |
||
| 116 | 'MMMMM' => '', |
||
| 117 | 'L' => 'n', // Stand alone month in year |
||
| 118 | 'LL' => 'm', // Stand alone month in year |
||
| 119 | 'LLL' => 'M', // Stand alone month in year |
||
| 120 | 'LLLL' => 'F', // Stand alone month in year |
||
| 121 | 'LLLLL' => '', // Stand alone month in year |
||
| 122 | 'w' => 'W', // ISO-8601 week number of year |
||
| 123 | 'ww' => 'W', // ISO-8601 week number of year |
||
| 124 | 'W' => '', // week of the current month |
||
| 125 | 'd' => 'j', // day without leading zeros |
||
| 126 | 'dd' => 'd', // day with leading zeros |
||
| 127 | 'D' => 'z', // day of the year 0 to 365 |
||
| 128 | 'F' => '', // Day of Week in Month. eg. 2nd Wednesday in July |
||
| 129 | 'g' => '', // Modified Julian day. This is different from the conventional Julian day number in two regards. |
||
| 130 | 'E' => 'D', // day of week written in short form eg. Sun |
||
| 131 | 'EE' => 'D', |
||
| 132 | 'EEE' => 'D', |
||
| 133 | 'EEEE' => 'l', // day of week fully written eg. Sunday |
||
| 134 | 'EEEEE' => '', |
||
| 135 | 'EEEEEE' => '', |
||
| 136 | 'e' => 'N', // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun |
||
| 137 | 'ee' => 'N', // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year |
||
| 138 | 'eee' => 'D', |
||
| 139 | 'eeee' => 'l', |
||
| 140 | 'eeeee' => '', |
||
| 141 | 'eeeeee' => '', |
||
| 142 | 'c' => 'N', // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun |
||
| 143 | 'cc' => 'N', // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year |
||
| 144 | 'ccc' => 'D', |
||
| 145 | 'cccc' => 'l', |
||
| 146 | 'ccccc' => '', |
||
| 147 | 'cccccc' => '', |
||
| 148 | 'a' => 'A', // AM/PM marker |
||
| 149 | 'h' => 'g', // 12-hour format of an hour without leading zeros 1 to 12h |
||
| 150 | 'hh' => 'h', // 12-hour format of an hour with leading zeros, 01 to 12 h |
||
| 151 | 'H' => 'G', // 24-hour format of an hour without leading zeros 0 to 23h |
||
| 152 | 'HH' => 'H', // 24-hour format of an hour with leading zeros, 00 to 23 h |
||
| 153 | 'k' => '', // hour in day (1~24) |
||
| 154 | 'kk' => '', // hour in day (1~24) |
||
| 155 | 'K' => '', // hour in am/pm (0~11) |
||
| 156 | 'KK' => '', // hour in am/pm (0~11) |
||
| 157 | 'm' => 'i', // Minutes without leading zeros, not supported by php but we fallback |
||
| 158 | 'mm' => 'i', // Minutes with leading zeros |
||
| 159 | 's' => 's', // Seconds, without leading zeros, not supported by php but we fallback |
||
| 160 | 'ss' => 's', // Seconds, with leading zeros |
||
| 161 | 'S' => '', // fractional second |
||
| 162 | 'SS' => '', // fractional second |
||
| 163 | 'SSS' => '', // fractional second |
||
| 164 | 'SSSS' => '', // fractional second |
||
| 165 | 'A' => '', // milliseconds in day |
||
| 166 | 'z' => 'T', // Timezone abbreviation |
||
| 167 | 'zz' => 'T', // Timezone abbreviation |
||
| 168 | 'zzz' => 'T', // Timezone abbreviation |
||
| 169 | 'zzzz' => 'T', // Timezone full name, not supported by php but we fallback |
||
| 170 | 'Z' => 'O', // Difference to Greenwich time (GMT) in hours |
||
| 171 | 'ZZ' => 'O', // Difference to Greenwich time (GMT) in hours |
||
| 172 | 'ZZZ' => 'O', // Difference to Greenwich time (GMT) in hours |
||
| 173 | 'ZZZZ' => '\G\M\TP', // Time Zone: long localized GMT (=OOOO) e.g. GMT-08:00 |
||
| 174 | 'ZZZZZ' => '', // TIme Zone: ISO8601 extended hms? (=XXXXX) |
||
| 175 | 'O' => '', // Time Zone: short localized GMT e.g. GMT-8 |
||
| 176 | 'OOOO' => '\G\M\TP', // Time Zone: long localized GMT (=ZZZZ) e.g. GMT-08:00 |
||
| 177 | 'v' => '\G\M\TP', // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here |
||
| 178 | 'vvvv' => '\G\M\TP', // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here |
||
| 179 | 'V' => '', // Time Zone: short time zone ID |
||
| 180 | 'VV' => 'e', // Time Zone: long time zone ID |
||
| 181 | 'VVV' => '', // Time Zone: time zone exemplar city |
||
| 182 | 'VVVV' => '\G\M\TP', // Time Zone: generic location (falls back to OOOO) using the ICU defined fallback here |
||
| 183 | 'X' => '', // Time Zone: ISO8601 basic hm?, with Z for 0, e.g. -08, +0530, Z |
||
| 184 | 'XX' => 'O, \Z', // Time Zone: ISO8601 basic hm, with Z, e.g. -0800, Z |
||
| 185 | 'XXX' => 'P, \Z', // Time Zone: ISO8601 extended hm, with Z, e.g. -08:00, Z |
||
| 186 | 'XXXX' => '', // Time Zone: ISO8601 basic hms?, with Z, e.g. -0800, -075258, Z |
||
| 187 | 'XXXXX' => '', // Time Zone: ISO8601 extended hms?, with Z, e.g. -08:00, -07:52:58, Z |
||
| 188 | 'x' => '', // Time Zone: ISO8601 basic hm?, without Z for 0, e.g. -08, +0530 |
||
| 189 | 'xx' => 'O', // Time Zone: ISO8601 basic hm, without Z, e.g. -0800 |
||
| 190 | 'xxx' => 'P', // Time Zone: ISO8601 extended hm, without Z, e.g. -08:00 |
||
| 191 | 'xxxx' => '', // Time Zone: ISO8601 basic hms?, without Z, e.g. -0800, -075258 |
||
| 192 | 'xxxxx' => '', // Time Zone: ISO8601 extended hms?, without Z, e.g. -08:00, -07:52:58 |
||
| 193 | ])); |
||
| 304 |