Conditions | 11 |
Paths | 25 |
Total Lines | 54 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 22.3602 |
Changes | 4 | ||
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 |
||
11003 | 3 | public static function strrichr( |
|
11004 | string $haystack, |
||
11005 | string $needle, |
||
11006 | bool $before_needle = false, |
||
11007 | string $encoding = 'UTF-8', |
||
11008 | bool $clean_utf8 = false |
||
11009 | ) { |
||
11010 | 3 | if ($haystack === '' || $needle === '') { |
|
11011 | 2 | return false; |
|
11012 | } |
||
11013 | |||
11014 | 3 | if ($encoding !== 'UTF-8' && $encoding !== 'CP850') { |
|
11015 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
11016 | } |
||
11017 | |||
11018 | 3 | if ($clean_utf8) { |
|
11019 | // "mb_strpos()" and "iconv_strpos()" returns wrong position, |
||
11020 | // if invalid characters are found in $haystack before $needle |
||
11021 | 2 | $needle = self::clean($needle); |
|
11022 | 2 | $haystack = self::clean($haystack); |
|
11023 | } |
||
11024 | |||
11025 | // |
||
11026 | // fallback via mbstring |
||
11027 | // |
||
11028 | |||
11029 | 3 | if (self::$SUPPORT['mbstring'] === true) { |
|
11030 | 3 | if ($encoding === 'UTF-8') { |
|
11031 | 3 | return \mb_strrichr($haystack, $needle, $before_needle); |
|
11032 | } |
||
11033 | |||
11034 | 2 | return \mb_strrichr($haystack, $needle, $before_needle, $encoding); |
|
11035 | } |
||
11036 | |||
11037 | // |
||
11038 | // fallback via vanilla php |
||
11039 | // |
||
11040 | |||
11041 | $needle_tmp = self::substr($needle, 0, 1, $encoding); |
||
11042 | if ($needle_tmp === false) { |
||
11043 | return false; |
||
11044 | } |
||
11045 | $needle = (string) $needle_tmp; |
||
11046 | |||
11047 | $pos = self::strripos($haystack, $needle, 0, $encoding); |
||
11048 | if ($pos === false) { |
||
11049 | return false; |
||
11050 | } |
||
11051 | |||
11052 | if ($before_needle) { |
||
11053 | return self::substr($haystack, 0, $pos, $encoding); |
||
11054 | } |
||
11055 | |||
11056 | return self::substr($haystack, $pos, null, $encoding); |
||
11057 | } |
||
14796 |