| Conditions | 10 |
| Paths | 64 |
| Total Lines | 24 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 81 | private function parseString(string $value, int &$i): ?string |
||
| 82 | { |
||
| 83 | $isQuoted = $value[$i] === '"'; |
||
| 84 | $stringEndChars = $isQuoted ? ['"'] : [$this->delimiter, '}']; |
||
| 85 | $result = ''; |
||
| 86 | $len = strlen($value); |
||
| 87 | |||
| 88 | for ($i += $isQuoted ? 1 : 0; $i < $len; ++$i) { |
||
| 89 | if (in_array($value[$i], ['\\', '"'], true) && in_array($value[$i + 1], [$value[$i], '"'], true)) { |
||
| 90 | ++$i; |
||
| 91 | } elseif (in_array($value[$i], $stringEndChars, true)) { |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | |||
| 95 | $result .= $value[$i]; |
||
| 96 | } |
||
| 97 | |||
| 98 | $i -= $isQuoted ? 0 : 1; |
||
| 99 | |||
| 100 | if (!$isQuoted && $result === 'NULL') { |
||
| 101 | $result = null; |
||
| 102 | } |
||
| 103 | |||
| 104 | return $result; |
||
| 105 | } |
||
| 107 |