Conditions | 25 |
Paths | 222 |
Total Lines | 113 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 121.5677 |
Changes | 8 | ||
Bugs | 4 | 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 |
||
10332 | 14 | public static function strripos( |
|
10333 | string $haystack, |
||
10334 | $needle, |
||
10335 | int $offset = 0, |
||
10336 | string $encoding = 'UTF-8', |
||
10337 | bool $clean_utf8 = false |
||
10338 | ) { |
||
10339 | 14 | if ($haystack === '') { |
|
10340 | 3 | if (\PHP_VERSION_ID >= 80000) { |
|
10341 | 3 | if ($needle === '') { |
|
10342 | 3 | return 0; |
|
10343 | } |
||
10344 | } else { |
||
10345 | return false; |
||
10346 | } |
||
10347 | } |
||
10348 | |||
10349 | // iconv and mbstring do not support integer $needle |
||
10350 | 14 | if ((int) $needle === $needle && $needle >= 0) { |
|
10351 | $needle = (string) self::chr($needle); |
||
10352 | } |
||
10353 | 14 | $needle = (string) $needle; |
|
10354 | |||
10355 | 14 | if ($haystack === '') { |
|
10356 | 1 | if (\PHP_VERSION_ID >= 80000 && $needle === '') { |
|
10357 | return 0; |
||
10358 | } |
||
10359 | |||
10360 | 1 | return false; |
|
10361 | } |
||
10362 | |||
10363 | 14 | if ($needle === '' && \PHP_VERSION_ID < 80000) { |
|
10364 | return false; |
||
10365 | } |
||
10366 | |||
10367 | 14 | if ($clean_utf8) { |
|
10368 | // mb_strripos() && iconv_strripos() is not tolerant to invalid characters |
||
10369 | 3 | $needle = self::clean($needle); |
|
10370 | 3 | $haystack = self::clean($haystack); |
|
10371 | } |
||
10372 | |||
10373 | 14 | if ($encoding !== 'UTF-8' && $encoding !== 'CP850') { |
|
10374 | 9 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
10375 | } |
||
10376 | |||
10377 | // |
||
10378 | // fallback via mbstrig |
||
10379 | // |
||
10380 | |||
10381 | 14 | if (self::$SUPPORT['mbstring'] === true) { |
|
10382 | 14 | if ($encoding === 'UTF-8') { |
|
10383 | 14 | return \mb_strripos($haystack, $needle, $offset); |
|
10384 | } |
||
10385 | |||
10386 | return \mb_strripos($haystack, $needle, $offset, $encoding); |
||
10387 | } |
||
10388 | |||
10389 | // |
||
10390 | // fallback for binary || ascii only |
||
10391 | // |
||
10392 | |||
10393 | if ( |
||
10394 | $encoding === 'CP850' |
||
10395 | || |
||
10396 | $encoding === 'ASCII' |
||
10397 | ) { |
||
10398 | return \strripos($haystack, $needle, $offset); |
||
10399 | } |
||
10400 | |||
10401 | if ( |
||
10402 | $encoding !== 'UTF-8' |
||
10403 | && |
||
10404 | self::$SUPPORT['mbstring'] === false |
||
10405 | ) { |
||
10406 | /** |
||
10407 | * @psalm-suppress ImpureFunctionCall - is is only a warning |
||
10408 | */ |
||
10409 | \trigger_error('UTF8::strripos() without mbstring cannot handle "' . $encoding . '" encoding', \E_USER_WARNING); |
||
10410 | } |
||
10411 | |||
10412 | // |
||
10413 | // fallback via intl |
||
10414 | // |
||
10415 | |||
10416 | if ( |
||
10417 | $encoding === 'UTF-8' // INFO: "grapheme_strripos()" can't handle other encodings |
||
10418 | && |
||
10419 | $offset >= 0 // grapheme_strripos() can't handle negative offset |
||
10420 | && |
||
10421 | self::$SUPPORT['intl'] === true |
||
10422 | ) { |
||
10423 | $return_tmp = \grapheme_strripos($haystack, $needle, $offset); |
||
10424 | if ($return_tmp !== false) { |
||
10425 | return $return_tmp; |
||
10426 | } |
||
10427 | } |
||
10428 | |||
10429 | // |
||
10430 | // fallback for ascii only |
||
10431 | // |
||
10432 | |||
10433 | if (ASCII::is_ascii($haystack . $needle)) { |
||
10434 | return \strripos($haystack, $needle, $offset); |
||
10435 | } |
||
10436 | |||
10437 | // |
||
10438 | // fallback via vanilla php |
||
10439 | // |
||
10440 | |||
10441 | $haystack = self::strtocasefold($haystack, true, false, $encoding); |
||
10442 | $needle = self::strtocasefold($needle, true, false, $encoding); |
||
10443 | |||
10444 | return self::strrpos($haystack, $needle, $offset, $encoding, $clean_utf8); |
||
10445 | } |
||
13666 |