Conditions | 10 |
Paths | 24 |
Total Lines | 30 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 11.2294 |
Changes | 4 | ||
Bugs | 2 | 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 |
||
10753 | 10 | public static function strspn( |
|
10754 | string $str, |
||
10755 | string $mask, |
||
10756 | int $offset = 0, |
||
10757 | int $length = null, |
||
10758 | string $encoding = 'UTF-8' |
||
10759 | ) { |
||
10760 | 10 | if ($encoding !== 'UTF-8' && $encoding !== 'CP850') { |
|
10761 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
||
10762 | } |
||
10763 | |||
10764 | 10 | if ($offset || $length !== null) { |
|
10765 | 2 | if ($encoding === 'UTF-8') { |
|
10766 | 2 | if ($length === null) { |
|
10767 | $str = (string) \mb_substr($str, $offset); |
||
10768 | } else { |
||
10769 | 2 | $str = (string) \mb_substr($str, $offset, $length); |
|
10770 | } |
||
10771 | } else { |
||
10772 | $str = (string) self::substr($str, $offset, $length, $encoding); |
||
10773 | } |
||
10774 | } |
||
10775 | |||
10776 | 10 | if ($str === '' || $mask === '') { |
|
10777 | 2 | return 0; |
|
10778 | } |
||
10779 | |||
10780 | 8 | $matches = []; |
|
10781 | |||
10782 | 8 | return \preg_match('/^' . self::rxClass($mask) . '+/u', $str, $matches) ? (int) self::strlen($matches[0], $encoding) : 0; |
|
10783 | } |
||
13706 |