| Conditions | 13 |
| Paths | 32 |
| Total Lines | 56 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 77 | public static function splitList($values): array |
||
| 78 | { |
||
| 79 | if (!\is_array($values)) { |
||
| 80 | $values = [$values]; |
||
| 81 | } |
||
| 82 | |||
| 83 | $result = []; |
||
| 84 | foreach ($values as $value) { |
||
| 85 | if (!\is_string($value)) { |
||
| 86 | throw new \TypeError('$header must either be a string or an array containing strings.'); |
||
| 87 | } |
||
| 88 | |||
| 89 | $v = ''; |
||
| 90 | $isQuoted = false; |
||
| 91 | $isEscaped = false; |
||
| 92 | for ($i = 0, $max = \strlen($value); $i < $max; $i++) { |
||
| 93 | if ($isEscaped) { |
||
| 94 | $v .= $value[$i]; |
||
| 95 | $isEscaped = false; |
||
| 96 | |||
| 97 | continue; |
||
| 98 | } |
||
| 99 | |||
| 100 | if (!$isQuoted && $value[$i] === ',') { |
||
| 101 | $v = \trim($v); |
||
| 102 | if ($v !== '') { |
||
| 103 | $result[] = $v; |
||
| 104 | } |
||
| 105 | |||
| 106 | $v = ''; |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($isQuoted && $value[$i] === '\\') { |
||
| 111 | $isEscaped = true; |
||
| 112 | $v .= $value[$i]; |
||
| 113 | |||
| 114 | continue; |
||
| 115 | } |
||
| 116 | if ($value[$i] === '"') { |
||
| 117 | $isQuoted = !$isQuoted; |
||
| 118 | $v .= $value[$i]; |
||
| 119 | |||
| 120 | continue; |
||
| 121 | } |
||
| 122 | |||
| 123 | $v .= $value[$i]; |
||
| 124 | } |
||
| 125 | |||
| 126 | $v = \trim($v); |
||
| 127 | if ($v !== '') { |
||
| 128 | $result[] = $v; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | return $result; |
||
| 133 | } |
||
| 135 |