Conditions | 13 |
Paths | 14 |
Total Lines | 54 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 21.3333 |
Changes | 2 | ||
Bugs | 0 | 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 |
||
7898 | 16 | public static function str_split_pattern(string $str, string $pattern, int $limit = -1): array |
|
7899 | { |
||
7900 | 16 | if ($limit === 0) { |
|
7901 | 2 | return []; |
|
7902 | } |
||
7903 | |||
7904 | 14 | if ($pattern === '') { |
|
7905 | 1 | return [$str]; |
|
7906 | } |
||
7907 | |||
7908 | 13 | if (self::$SUPPORT['mbstring'] === true) { |
|
7909 | 13 | if ($limit >= 0) { |
|
7910 | 8 | $result_tmp = \mb_split($pattern, $str); |
|
7911 | 8 | if ($result_tmp === false) { |
|
7912 | return []; |
||
7913 | } |
||
7914 | |||
7915 | 8 | $result = []; |
|
7916 | 8 | foreach ($result_tmp as $item_tmp) { |
|
7917 | 8 | if ($limit === 0) { |
|
7918 | 4 | break; |
|
7919 | } |
||
7920 | 8 | --$limit; |
|
7921 | |||
7922 | 8 | $result[] = $item_tmp; |
|
7923 | } |
||
7924 | |||
7925 | 8 | return $result; |
|
7926 | } |
||
7927 | |||
7928 | 5 | $result = \mb_split($pattern, $str); |
|
7929 | 5 | if ($result === false) { |
|
7930 | return []; |
||
7931 | } |
||
7932 | |||
7933 | 5 | return $result; |
|
7934 | } |
||
7935 | |||
7936 | if ($limit > 0) { |
||
7937 | ++$limit; |
||
7938 | } else { |
||
7939 | $limit = -1; |
||
7940 | } |
||
7941 | |||
7942 | $array = \preg_split('/' . \preg_quote($pattern, '/') . '/u', $str, $limit); |
||
7943 | if ($array === false) { |
||
7944 | return []; |
||
7945 | } |
||
7946 | |||
7947 | if ($limit > 0 && \count($array) === $limit) { |
||
7948 | \array_pop($array); |
||
7949 | } |
||
7950 | |||
7951 | return $array; |
||
7952 | } |
||
13694 |