Conditions | 10 |
Paths | 8 |
Total Lines | 74 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 10.7998 |
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 |
||
5538 | 32 | public static function str_camelize( |
|
5539 | string $str, |
||
5540 | string $encoding = 'UTF-8', |
||
5541 | bool $clean_utf8 = false, |
||
5542 | string $lang = null, |
||
5543 | bool $try_to_keep_the_string_length = false |
||
5544 | ): string { |
||
5545 | 32 | if ($clean_utf8) { |
|
5546 | $str = self::clean($str); |
||
5547 | } |
||
5548 | |||
5549 | 32 | if ($encoding !== 'UTF-8' && $encoding !== 'CP850') { |
|
5550 | 26 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
5551 | } |
||
5552 | |||
5553 | 32 | $str = self::lcfirst( |
|
5554 | 32 | \trim($str), |
|
5555 | $encoding, |
||
5556 | false, |
||
5557 | $lang, |
||
5558 | $try_to_keep_the_string_length |
||
5559 | ); |
||
5560 | 32 | $str = (string) \preg_replace('/^[-_]+/', '', $str); |
|
5561 | |||
5562 | 32 | $use_mb_functions = $lang === null && !$try_to_keep_the_string_length; |
|
5563 | |||
5564 | 32 | $str = (string) \preg_replace_callback( |
|
5565 | '/[-_\\s]+(.)?/u', |
||
5566 | /** |
||
5567 | * @param array $match |
||
5568 | * |
||
5569 | * @psalm-pure |
||
5570 | * |
||
5571 | * @return string |
||
5572 | */ |
||
5573 | 32 | static function (array $match) use ($use_mb_functions, $encoding, $lang, $try_to_keep_the_string_length): string { |
|
5574 | 27 | if (isset($match[1])) { |
|
5575 | 27 | if ($use_mb_functions) { |
|
5576 | 27 | if ($encoding === 'UTF-8') { |
|
5577 | 27 | return \mb_strtoupper($match[1]); |
|
5578 | } |
||
5579 | |||
5580 | return \mb_strtoupper($match[1], $encoding); |
||
5581 | } |
||
5582 | |||
5583 | return self::strtoupper($match[1], $encoding, false, $lang, $try_to_keep_the_string_length); |
||
5584 | } |
||
5585 | |||
5586 | 1 | return ''; |
|
5587 | }, |
||
5588 | $str |
||
5589 | ); |
||
5590 | |||
5591 | 32 | return (string) \preg_replace_callback( |
|
5592 | '/[\\p{N}]+(.)?/u', |
||
5593 | /** |
||
5594 | * @param array $match |
||
5595 | * |
||
5596 | * @psalm-pure |
||
5597 | * |
||
5598 | * @return string |
||
5599 | */ |
||
5600 | 32 | static function (array $match) use ($use_mb_functions, $encoding, $clean_utf8, $lang, $try_to_keep_the_string_length): string { |
|
5601 | 6 | if ($use_mb_functions) { |
|
5602 | 6 | if ($encoding === 'UTF-8') { |
|
5603 | 6 | return \mb_strtoupper($match[0]); |
|
5604 | } |
||
5605 | |||
5606 | return \mb_strtoupper($match[0], $encoding); |
||
5607 | } |
||
5608 | |||
5609 | return self::strtoupper($match[0], $encoding, $clean_utf8, $lang, $try_to_keep_the_string_length); |
||
5610 | }, |
||
5611 | $str |
||
5612 | ); |
||
13722 |