@@ -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); |
@@ -44,8 +49,9 @@ discard block |
||
44 | 49 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
45 | 50 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
46 | 51 | $this->rules = array_merge($this->rules, $processing); |
52 | + } else if ($token['type'] !== Tokenizer::NEW_LINE) { |
|
53 | + $this->addRules($token, $indexStart++); |
|
47 | 54 | } |
48 | - else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart++); |
|
49 | 55 | } |
50 | 56 | |
51 | 57 | return $this->rules; |
@@ -55,14 +61,18 @@ discard block |
||
55 | 61 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
56 | 62 | |
57 | 63 | $this->tss->skip(count($selector)); |
58 | - if (count($selector) === 0) return; |
|
64 | + if (count($selector) === 0) { |
|
65 | + return; |
|
66 | + } |
|
59 | 67 | |
60 | 68 | $newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']); |
61 | 69 | $this->rules = $this->writeRule($this->rules, $newRules); |
62 | 70 | } |
63 | 71 | |
64 | 72 | private function checkError($rules) { |
65 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
73 | + if (empty($rules) && count($this->tss) > 0) { |
|
74 | + throw new \Exception('No TSS rules parsed'); |
|
75 | + } |
|
66 | 76 | } |
67 | 77 | |
68 | 78 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -89,7 +99,9 @@ discard block |
||
89 | 99 | } |
90 | 100 | |
91 | 101 | private function processingInstructions($token, $indexStart) { |
92 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
102 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
103 | + return false; |
|
104 | + } |
|
93 | 105 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
94 | 106 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
95 | 107 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -109,7 +121,9 @@ discard block |
||
109 | 121 | |
110 | 122 | private function sortRules($a, $b) { |
111 | 123 | //If they have the same depth, compare on index |
112 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
124 | + if ($a->depth === $b->depth) { |
|
125 | + return $a->index < $b->index ? -1 : 1; |
|
126 | + } |
|
113 | 127 | |
114 | 128 | return ($a->depth < $b->depth) ? -1 : 1; |
115 | 129 | } |