Conditions | 12 |
Paths | 40 |
Total Lines | 48 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 12.2341 |
Changes | 5 | ||
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 |
||
9159 | 3 | public static function strcspn( |
|
9160 | string $str, |
||
9161 | string $char_list, |
||
9162 | int $offset = 0, |
||
9163 | 3 | int $length = null, |
|
9164 | string $encoding = 'UTF-8' |
||
9165 | ): int { |
||
9166 | 11 | if ($encoding !== 'UTF-8' && $encoding !== 'CP850') { |
|
9167 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
9168 | } |
||
9169 | |||
9170 | 10 | if ($char_list === '') { |
|
9171 | 10 | return (int) self::strlen($str, $encoding); |
|
9172 | 9 | } |
|
9173 | 9 | ||
9174 | if ($offset || $length !== null) { |
||
9175 | if ($encoding === 'UTF-8') { |
||
9176 | if ($length === null) { |
||
9177 | 9 | $str_tmp = \mb_substr($str, $offset); |
|
9178 | } else { |
||
9179 | $str_tmp = \mb_substr($str, $offset, $length); |
||
9180 | 2 | } |
|
9181 | } else { |
||
9182 | $str_tmp = self::substr($str, $offset, $length, $encoding); |
||
9183 | } |
||
9184 | |||
9185 | if ($str_tmp === false) { |
||
9186 | return 0; |
||
9187 | } |
||
9188 | |||
9189 | $str = $str_tmp; |
||
9190 | } |
||
9191 | |||
9192 | if ($str === '') { |
||
9193 | return 0; |
||
9194 | } |
||
9195 | |||
9196 | $matches = []; |
||
9197 | if (\preg_match('/^(.*?)' . self::rxClass($char_list) . '/us', $str, $matches)) { |
||
9198 | $return = self::strlen($matches[1], $encoding); |
||
9199 | 4 | if ($return === false) { |
|
9200 | return 0; |
||
9201 | 4 | } |
|
9202 | 4 | ||
9203 | return $return; |
||
9204 | } |
||
9205 | 4 | ||
9206 | 1 | return (int) self::strlen($str, $encoding); |
|
9207 | } |
||
13757 |