Conditions | 14 |
Paths | 17 |
Total Lines | 67 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 14.6366 |
Changes | 6 | ||
Bugs | 3 | 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 |
||
9303 | 25 | public static function stripos( |
|
9304 | string $haystack, |
||
9305 | string $needle, |
||
9306 | int $offset = 0, |
||
9307 | string $encoding = 'UTF-8', |
||
9308 | bool $clean_utf8 = false |
||
9309 | ) { |
||
9310 | 25 | if ($haystack === '') { |
|
9311 | 5 | if (\PHP_VERSION_ID >= 80000 && $needle === '') { |
|
9312 | 2 | return 0; |
|
9313 | } |
||
9314 | |||
9315 | 5 | return false; |
|
9316 | } |
||
9317 | |||
9318 | 24 | if ($needle === '' && \PHP_VERSION_ID < 80000) { |
|
9319 | return false; |
||
9320 | } |
||
9321 | |||
9322 | 24 | if ($clean_utf8) { |
|
9323 | // "mb_strpos()" and "iconv_strpos()" returns wrong position, |
||
9324 | // if invalid characters are found in $haystack before $needle |
||
9325 | 1 | $haystack = self::clean($haystack); |
|
9326 | 1 | $needle = self::clean($needle); |
|
9327 | } |
||
9328 | |||
9329 | 24 | if (self::$SUPPORT['mbstring'] === true) { |
|
9330 | 24 | if ($encoding === 'UTF-8') { |
|
9331 | 24 | return \mb_stripos($haystack, $needle, $offset); |
|
9332 | } |
||
9333 | |||
9334 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
9335 | |||
9336 | 2 | return \mb_stripos($haystack, $needle, $offset, $encoding); |
|
9337 | } |
||
9338 | |||
9339 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
9340 | |||
9341 | if ( |
||
9342 | 2 | $encoding === 'UTF-8' // INFO: "grapheme_stripos()" can't handle other encodings |
|
9343 | && |
||
9344 | 2 | $offset >= 0 // grapheme_stripos() can't handle negative offset |
|
9345 | && |
||
9346 | 2 | self::$SUPPORT['intl'] === true |
|
9347 | ) { |
||
9348 | $return_tmp = \grapheme_stripos($haystack, $needle, $offset); |
||
9349 | if ($return_tmp !== false) { |
||
9350 | return $return_tmp; |
||
9351 | } |
||
9352 | } |
||
9353 | |||
9354 | // |
||
9355 | // fallback for ascii only |
||
9356 | // |
||
9357 | |||
9358 | 2 | if (ASCII::is_ascii($haystack . $needle)) { |
|
9359 | 2 | return \stripos($haystack, $needle, $offset); |
|
9360 | } |
||
9361 | |||
9362 | // |
||
9363 | // fallback via vanilla php |
||
9364 | // |
||
9365 | |||
9366 | 2 | $haystack = self::strtocasefold($haystack, true, false, $encoding, null, false); |
|
9367 | 2 | $needle = self::strtocasefold($needle, true, false, $encoding, null, false); |
|
9368 | |||
9369 | 2 | return self::strpos($haystack, $needle, $offset, $encoding); |
|
9370 | } |
||
13666 |