Conditions | 10 |
Paths | 29 |
Total Lines | 58 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 18 |
CRAP Score | 10.6008 |
Changes | 8 | ||
Bugs | 1 | 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 |
||
11134 | 17 | public static function strtoupper( |
|
11135 | $str, |
||
11136 | string $encoding = 'UTF-8', |
||
11137 | bool $clean_utf8 = false, |
||
11138 | string $lang = null, |
||
11139 | bool $try_to_keep_the_string_length = false |
||
11140 | ): string { |
||
11141 | // init |
||
11142 | 17 | $str = (string) $str; |
|
11143 | |||
11144 | 17 | if ($str === '') { |
|
11145 | 1 | return ''; |
|
11146 | } |
||
11147 | |||
11148 | 16 | if ($clean_utf8) { |
|
11149 | // "mb_strpos()" and "iconv_strpos()" returns wrong position, |
||
11150 | // if invalid characters are found in $haystack before $needle |
||
11151 | 2 | $str = self::clean($str); |
|
11152 | } |
||
11153 | |||
11154 | // hack for old php version or for the polyfill ... |
||
11155 | 16 | if ($try_to_keep_the_string_length) { |
|
11156 | 2 | $str = self::fixStrCaseHelper($str); |
|
11157 | } |
||
11158 | |||
11159 | 16 | if ($lang === null && $encoding === 'UTF-8') { |
|
11160 | 8 | return \mb_strtoupper($str); |
|
11161 | } |
||
11162 | |||
11163 | 10 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
11164 | |||
11165 | 10 | if ($lang !== null) { |
|
11166 | 2 | if (self::$SUPPORT['intl'] === true) { |
|
11167 | 2 | if (self::$INTL_TRANSLITERATOR_LIST === null) { |
|
11168 | self::$INTL_TRANSLITERATOR_LIST = self::getData('transliterator_list'); |
||
11169 | } |
||
11170 | |||
11171 | 2 | $language_code = $lang . '-Upper'; |
|
11172 | 2 | if (!\in_array($language_code, self::$INTL_TRANSLITERATOR_LIST, true)) { |
|
11173 | /** |
||
11174 | * @psalm-suppress ImpureFunctionCall - is is only a warning |
||
11175 | */ |
||
11176 | \trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, \E_USER_WARNING); |
||
11177 | |||
11178 | $language_code = 'Any-Upper'; |
||
11179 | } |
||
11180 | |||
11181 | 2 | return (string) \transliterator_transliterate($language_code, $str); |
|
11182 | } |
||
11183 | |||
11184 | /** |
||
11185 | * @psalm-suppress ImpureFunctionCall - is is only a warning |
||
11186 | */ |
||
11187 | \trigger_error('UTF8::strtolower() without intl cannot handle the "lang"-parameter: ' . $lang, \E_USER_WARNING); |
||
11188 | } |
||
11189 | |||
11190 | // always fallback via symfony polyfill |
||
11191 | 10 | return \mb_strtoupper($str, $encoding); |
|
11192 | } |
||
13722 |