Conditions | 14 |
Paths | 17 |
Total Lines | 67 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 14.6366 |
Changes | 5 | ||
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 |
||
9363 | 25 | public static function stripos( |
|
9364 | string $haystack, |
||
9365 | string $needle, |
||
9366 | int $offset = 0, |
||
9367 | string $encoding = 'UTF-8', |
||
9368 | bool $clean_utf8 = false |
||
9369 | ) { |
||
9370 | 25 | if ($haystack === '') { |
|
9371 | 5 | if (\PHP_VERSION_ID >= 80000 && $needle === '') { |
|
9372 | 2 | return 0; |
|
9373 | } |
||
9374 | |||
9375 | 5 | return false; |
|
9376 | } |
||
9377 | |||
9378 | 24 | if ($needle === '' && \PHP_VERSION_ID < 80000) { |
|
9379 | return false; |
||
9380 | } |
||
9381 | |||
9382 | 24 | if ($clean_utf8) { |
|
9383 | // "mb_strpos()" and "iconv_strpos()" returns wrong position, |
||
9384 | // if invalid characters are found in $haystack before $needle |
||
9385 | 1 | $haystack = self::clean($haystack); |
|
9386 | 1 | $needle = self::clean($needle); |
|
9387 | } |
||
9388 | |||
9389 | 24 | if (self::$SUPPORT['mbstring'] === true) { |
|
9390 | 24 | if ($encoding === 'UTF-8') { |
|
9391 | 24 | return \mb_stripos($haystack, $needle, $offset); |
|
9392 | } |
||
9393 | |||
9394 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
9395 | |||
9396 | 2 | return \mb_stripos($haystack, $needle, $offset, $encoding); |
|
9397 | } |
||
9398 | |||
9399 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
9400 | |||
9401 | if ( |
||
9402 | 2 | $encoding === 'UTF-8' // INFO: "grapheme_stripos()" can't handle other encodings |
|
9403 | && |
||
9404 | 2 | $offset >= 0 // grapheme_stripos() can't handle negative offset |
|
9405 | && |
||
9406 | 2 | self::$SUPPORT['intl'] === true |
|
9407 | ) { |
||
9408 | $return_tmp = \grapheme_stripos($haystack, $needle, $offset); |
||
9409 | if ($return_tmp !== false) { |
||
9410 | return $return_tmp; |
||
9411 | } |
||
9412 | } |
||
9413 | |||
9414 | // |
||
9415 | // fallback for ascii only |
||
9416 | // |
||
9417 | |||
9418 | 2 | if (ASCII::is_ascii($haystack . $needle)) { |
|
9419 | 2 | return \stripos($haystack, $needle, $offset); |
|
9420 | } |
||
9421 | |||
9422 | // |
||
9423 | // fallback via vanilla php |
||
9424 | // |
||
9425 | |||
9426 | 2 | $haystack = self::strtocasefold($haystack, true, false, $encoding, null, false); |
|
9427 | 2 | $needle = self::strtocasefold($needle, true, false, $encoding, null, false); |
|
9428 | |||
9429 | 2 | return self::strpos($haystack, $needle, $offset, $encoding); |
|
9430 | } |
||
13706 |