Conditions | 12 |
Paths | 18 |
Total Lines | 58 |
Code Lines | 32 |
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 |
||
50 | { |
||
51 | if (!class_exists($cssFilter) || !in_array(ICssFilter::class, class_implements($cssFilter))) |
||
52 | throw new \ErrorException("`$cssFilter` does not implement ICssFilter."); |
||
53 | |||
54 | $this->cssFilters[$cssFilter::getFunctionName()] = $cssFilter; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Parse a string to an array containing selectors and special functions |
||
60 | * |
||
61 | * @param string $line The filter to parser |
||
62 | * @return array |
||
63 | */ |
||
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 | } |
||
138 | } |