@@ -121,7 +121,7 @@ |
||
121 | 121 | |
122 | 122 | |
123 | 123 | private function sortPseudo($a, $b) { |
124 | - return count($a->pseudo) < count($b->pseudo) ? -1 :1; |
|
124 | + return count($a->pseudo) < count($b->pseudo) ? -1 : 1; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | private function getProperties($tokens) { |
@@ -25,14 +25,19 @@ discard block |
||
25 | 25 | $this->file = $tss; |
26 | 26 | $this->rules = $this->cache->load($tss); |
27 | 27 | $this->filePath->addPath(dirname(realpath($tss))); |
28 | - if (empty($this->rules)) $tss = file_get_contents($tss); |
|
29 | - else return; |
|
28 | + if (empty($this->rules)) { |
|
29 | + $tss = file_get_contents($tss); |
|
30 | + } else { |
|
31 | + return; |
|
32 | + } |
|
30 | 33 | } |
31 | 34 | $this->tss = (new Tokenizer($tss))->getTokens(); |
32 | 35 | } |
33 | 36 | |
34 | 37 | public function parse($indexStart = 0) { |
35 | - if (!empty($this->rules)) return $this->rules['rules']; |
|
38 | + if (!empty($this->rules)) { |
|
39 | + return $this->rules['rules']; |
|
40 | + } |
|
36 | 41 | $rules = $this->parseTokens($indexStart); |
37 | 42 | usort($rules, [$this, 'sortRules']); |
38 | 43 | $this->checkError($rules); |
@@ -45,8 +50,9 @@ discard block |
||
45 | 50 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
46 | 51 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
47 | 52 | $this->rules = array_merge($this->rules, $processing); |
53 | + } else if ($token['type'] !== Tokenizer::NEW_LINE) { |
|
54 | + $this->addRules($token, $indexStart++); |
|
48 | 55 | } |
49 | - else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart++); |
|
50 | 56 | } |
51 | 57 | |
52 | 58 | return $this->rules; |
@@ -56,14 +62,18 @@ discard block |
||
56 | 62 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
57 | 63 | |
58 | 64 | $this->tss->skip(count($selector)); |
59 | - if (count($selector) === 0) return; |
|
65 | + if (count($selector) === 0) { |
|
66 | + return; |
|
67 | + } |
|
60 | 68 | |
61 | 69 | $newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']); |
62 | 70 | $this->rules = $this->writeRule($this->rules, $newRules); |
63 | 71 | } |
64 | 72 | |
65 | 73 | private function checkError($rules) { |
66 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
74 | + if (empty($rules) && count($this->tss) > 0) { |
|
75 | + throw new \Exception('No TSS rules parsed'); |
|
76 | + } |
|
67 | 77 | } |
68 | 78 | |
69 | 79 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -91,7 +101,9 @@ discard block |
||
91 | 101 | } |
92 | 102 | |
93 | 103 | private function processingInstructions($token, $indexStart) { |
94 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
104 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
105 | + return false; |
|
106 | + } |
|
95 | 107 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
96 | 108 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
97 | 109 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -111,10 +123,15 @@ discard block |
||
111 | 123 | |
112 | 124 | private function sortRules($a, $b) { |
113 | 125 | //If they have the same depth, compare on index |
114 | - if ($a->query === $b->query) return $this->sortPseudo($a, $b); |
|
126 | + if ($a->query === $b->query) { |
|
127 | + return $this->sortPseudo($a, $b); |
|
128 | + } |
|
115 | 129 | |
116 | - if ($a->depth === $b->depth) $property = 'index'; |
|
117 | - else $property = 'depth'; |
|
130 | + if ($a->depth === $b->depth) { |
|
131 | + $property = 'index'; |
|
132 | + } else { |
|
133 | + $property = 'depth'; |
|
134 | + } |
|
118 | 135 | |
119 | 136 | return ($a->$property < $b->$property) ? -1 : 1; |
120 | 137 | } |