Conditions | 10 |
Paths | 8 |
Total Lines | 74 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 30 |
CRAP Score | 10.2918 |
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 |
||
5522 | 32 | public static function str_camelize( |
|
5523 | string $str, |
||
5524 | string $encoding = 'UTF-8', |
||
5525 | bool $clean_utf8 = false, |
||
5526 | string $lang = null, |
||
5527 | bool $try_to_keep_the_string_length = false |
||
5528 | ): string { |
||
5529 | 32 | if ($clean_utf8) { |
|
5530 | $str = self::clean($str); |
||
5531 | } |
||
5532 | |||
5533 | 32 | if ($encoding !== 'UTF-8' && $encoding !== 'CP850') { |
|
5534 | 26 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
5535 | } |
||
5536 | |||
5537 | 32 | $str = self::lcfirst( |
|
5538 | 32 | \trim($str), |
|
5539 | 32 | $encoding, |
|
5540 | 32 | false, |
|
5541 | 32 | $lang, |
|
5542 | 32 | $try_to_keep_the_string_length |
|
5543 | ); |
||
5544 | 32 | $str = (string) \preg_replace('/^[-_]+/', '', $str); |
|
5545 | |||
5546 | 32 | $use_mb_functions = $lang === null && !$try_to_keep_the_string_length; |
|
5547 | |||
5548 | 32 | $str = (string) \preg_replace_callback( |
|
5549 | 32 | '/[-_\\s]+(.)?/u', |
|
5550 | /** |
||
5551 | * @param array $match |
||
5552 | * |
||
5553 | * @psalm-pure |
||
5554 | * |
||
5555 | * @return string |
||
5556 | */ |
||
5557 | 32 | static function (array $match) use ($use_mb_functions, $encoding, $lang, $try_to_keep_the_string_length): string { |
|
5558 | 27 | if (isset($match[1])) { |
|
5559 | 27 | if ($use_mb_functions) { |
|
5560 | 27 | if ($encoding === 'UTF-8') { |
|
5561 | 27 | return \mb_strtoupper($match[1]); |
|
5562 | } |
||
5563 | |||
5564 | return \mb_strtoupper($match[1], $encoding); |
||
5565 | } |
||
5566 | |||
5567 | return self::strtoupper($match[1], $encoding, false, $lang, $try_to_keep_the_string_length); |
||
5568 | } |
||
5569 | |||
5570 | 1 | return ''; |
|
5571 | 32 | }, |
|
5572 | 32 | $str |
|
5573 | ); |
||
5574 | |||
5575 | 32 | return (string) \preg_replace_callback( |
|
5576 | 32 | '/[\\p{N}]+(.)?/u', |
|
5577 | /** |
||
5578 | * @param array $match |
||
5579 | * |
||
5580 | * @psalm-pure |
||
5581 | * |
||
5582 | * @return string |
||
5583 | */ |
||
5584 | 32 | static function (array $match) use ($use_mb_functions, $encoding, $clean_utf8, $lang, $try_to_keep_the_string_length): string { |
|
5585 | 6 | if ($use_mb_functions) { |
|
5586 | 6 | if ($encoding === 'UTF-8') { |
|
5587 | 6 | return \mb_strtoupper($match[0]); |
|
5588 | } |
||
5589 | |||
5590 | return \mb_strtoupper($match[0], $encoding); |
||
5591 | } |
||
5592 | |||
5593 | return self::strtoupper($match[0], $encoding, $clean_utf8, $lang, $try_to_keep_the_string_length); |
||
5594 | 32 | }, |
|
5595 | 32 | $str |
|
5596 | ); |
||
13706 |