| Conditions | 9 |
| Paths | 3 |
| Total Lines | 60 |
| Code Lines | 35 |
| 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 |
||
| 38 | private static function parseLines(array $lines, int &$index = 0, int $expectedIndent = 0): mixed |
||
| 39 | { |
||
| 40 | $result = []; |
||
| 41 | $isObject = false; |
||
|
|
|||
| 42 | $isList = false; |
||
| 43 | |||
| 44 | while ($index < count($lines)) { |
||
| 45 | $line = $lines[$index]; |
||
| 46 | $indent = self::getIndent($line); |
||
| 47 | $content = trim($line); |
||
| 48 | |||
| 49 | if ('' === $content) { |
||
| 50 | ++$index; |
||
| 51 | |||
| 52 | continue; |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($indent < $expectedIndent) { |
||
| 56 | break; |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($indent > $expectedIndent) { |
||
| 60 | ++$index; |
||
| 61 | |||
| 62 | continue; |
||
| 63 | } |
||
| 64 | |||
| 65 | if (str_contains($content, Constants::OBJECT_MARKER)) { |
||
| 66 | $isObject = true; |
||
| 67 | [$key, $value] = self::parseObjectLine($content); |
||
| 68 | ++$index; |
||
| 69 | |||
| 70 | if ($index < count($lines)) { |
||
| 71 | $nextLine = $lines[$index]; |
||
| 72 | $nextIndent = self::getIndent($nextLine); |
||
| 73 | if ($nextIndent > $expectedIndent) { |
||
| 74 | $result[$key] = self::parseLines($lines, $index, $nextIndent); |
||
| 75 | |||
| 76 | continue; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | $result[$key] = $value; |
||
| 81 | |||
| 82 | continue; |
||
| 83 | } |
||
| 84 | |||
| 85 | if (str_contains($content, Constants::ARRAY_MARKER)) { |
||
| 86 | $isList = true; |
||
| 87 | $result[] = self::parseArrayLine($content); |
||
| 88 | ++$index; |
||
| 89 | |||
| 90 | continue; |
||
| 91 | } |
||
| 92 | |||
| 93 | $result[] = Primitives::decode($content); |
||
| 94 | ++$index; |
||
| 95 | } |
||
| 96 | |||
| 97 | return $result; |
||
| 98 | } |
||
| 162 |