Conditions | 7 |
Paths | 17 |
Total Lines | 57 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 9.4161 |
Changes | 5 | ||
Bugs | 0 | Features | 1 |
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 |
||
12593 | 69 | public static function ucfirst( |
|
12594 | string $str, |
||
12595 | string $encoding = 'UTF-8', |
||
12596 | bool $clean_utf8 = false, |
||
12597 | string $lang = null, |
||
12598 | bool $try_to_keep_the_string_length = false |
||
12599 | ): string { |
||
12600 | 69 | if ($str === '') { |
|
12601 | 3 | return ''; |
|
12602 | } |
||
12603 | |||
12604 | 68 | if ($clean_utf8) { |
|
12605 | // "mb_strpos()" and "iconv_strpos()" returns wrong position, |
||
12606 | // if invalid characters are found in $haystack before $needle |
||
12607 | 1 | $str = self::clean($str); |
|
12608 | } |
||
12609 | |||
12610 | 68 | $use_mb_functions = $lang === null && !$try_to_keep_the_string_length; |
|
12611 | |||
12612 | 68 | if ($encoding === 'UTF-8') { |
|
12613 | 22 | $str_part_two = (string) \mb_substr($str, 1); |
|
12614 | |||
12615 | 22 | if ($use_mb_functions) { |
|
12616 | 22 | $str_part_one = \mb_strtoupper( |
|
12617 | 22 | (string) \mb_substr($str, 0, 1) |
|
12618 | ); |
||
12619 | } else { |
||
12620 | 22 | $str_part_one = self::strtoupper( |
|
12621 | (string) \mb_substr($str, 0, 1), |
||
12622 | $encoding, |
||
12623 | false, |
||
12624 | $lang, |
||
12625 | $try_to_keep_the_string_length |
||
12626 | ); |
||
12627 | } |
||
12628 | } else { |
||
12629 | 47 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
12630 | |||
12631 | 47 | $str_part_two = (string) self::substr($str, 1, null, $encoding); |
|
12632 | |||
12633 | 47 | if ($use_mb_functions) { |
|
12634 | 47 | $str_part_one = \mb_strtoupper( |
|
12635 | 47 | (string) \mb_substr($str, 0, 1, $encoding), |
|
12636 | 47 | $encoding |
|
12637 | ); |
||
12638 | } else { |
||
12639 | $str_part_one = self::strtoupper( |
||
12640 | (string) self::substr($str, 0, 1, $encoding), |
||
12641 | $encoding, |
||
12642 | false, |
||
12643 | $lang, |
||
12644 | $try_to_keep_the_string_length |
||
12645 | ); |
||
12646 | } |
||
12647 | } |
||
12648 | |||
12649 | 68 | return $str_part_one . $str_part_two; |
|
12650 | } |
||
13665 |