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