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