Conditions | 12 |
Paths | 12 |
Total Lines | 43 |
Code Lines | 29 |
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 |
||
68 | public function parse(string $line): array |
||
69 | { |
||
70 | $line = trim($line); |
||
71 | |||
72 | $parts = []; |
||
73 | $selector = null; |
||
74 | $functions = []; |
||
75 | for ($i = 0; $i < strlen($line); $i++) { |
||
76 | $char = $line[$i]; |
||
77 | if (empty(trim($char)) && empty(trim($selector))) { |
||
78 | continue; |
||
79 | } |
||
80 | |||
81 | if ($char !== ':') { |
||
82 | $selector .= $char; |
||
83 | } else { |
||
84 | do { |
||
85 | $brackets = 0; |
||
86 | $functionLine = ''; |
||
87 | for (; ++$i < strlen($line);) { |
||
88 | $char = $line[$i]; |
||
89 | $functionLine .= $char; |
||
90 | if ($char === '(') { |
||
91 | $brackets++; |
||
92 | } elseif ($char === ')' && --$brackets === 0) { |
||
93 | break; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | $functions[] = $this->parseFunctionString($functionLine); |
||
98 | } while (++$i < strlen($line) && $line[$i] === ':'); |
||
99 | |||
100 | $parts[] = new ParsedSelector($selector, $functions); |
||
101 | $selector = null; |
||
102 | $functions = []; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | if (!empty(trim($selector)) || !empty($functions)) { |
||
107 | $parts[] = new ParsedSelector($selector, $functions); |
||
108 | } |
||
109 | |||
110 | return $parts; |
||
111 | } |
||
132 |