| Conditions | 16 |
| Paths | 20 |
| Total Lines | 47 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 2 | 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 |
||
| 75 | public function parse(string $line): array |
||
| 76 | { |
||
| 77 | $line = trim($line); |
||
| 78 | |||
| 79 | $parts = []; |
||
| 80 | $selector = null; |
||
| 81 | $functions = []; |
||
| 82 | $quoted = false; |
||
| 83 | for ($i = 0; $i < strlen($line); $i++) { |
||
| 84 | $char = $line[$i]; |
||
| 85 | if (empty(trim($char)) && empty(trim($selector))) { |
||
| 86 | continue; |
||
| 87 | } |
||
| 88 | if ($char === '"' || $char === '\'') { |
||
| 89 | $quoted = !$quoted; |
||
|
|
|||
| 90 | } |
||
| 91 | |||
| 92 | if ($char !== ':' || $quoted) { |
||
| 93 | $selector .= $char; |
||
| 94 | } else { |
||
| 95 | do { |
||
| 96 | $brackets = 0; |
||
| 97 | $functionLine = ''; |
||
| 98 | for (; ++$i < strlen($line);) { |
||
| 99 | $char = $line[$i]; |
||
| 100 | $functionLine .= $char; |
||
| 101 | if ($char === '(') { |
||
| 102 | $brackets++; |
||
| 103 | } elseif ($char === ')' && --$brackets === 0) { |
||
| 104 | break; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $functions[] = $this->parseFunctionString($functionLine); |
||
| 109 | } while (++$i < strlen($line) && $line[$i] === ':'); |
||
| 110 | |||
| 111 | $parts[] = new ParsedSelector($selector, $functions); |
||
| 112 | $selector = null; |
||
| 113 | $functions = []; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | if (!empty(trim($selector)) || !empty($functions)) { |
||
| 118 | $parts[] = new ParsedSelector($selector, $functions); |
||
| 119 | } |
||
| 120 | |||
| 121 | return $parts; |
||
| 122 | } |
||
| 145 |