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