@@ -25,8 +25,11 @@ discard block |
||
25 | 25 | $this->file = $tss; |
26 | 26 | $this->rules = $this->cache->load($tss); |
27 | 27 | $this->filePath->setBaseDir(dirname(realpath($tss)) . DIRECTORY_SEPARATOR); |
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 = $this->stripComments($tss, '//', "\n"); |
32 | 35 | $this->tss = $this->stripComments($this->tss, '/*', '*/'); |
@@ -35,7 +38,9 @@ discard block |
||
35 | 38 | } |
36 | 39 | |
37 | 40 | public function parse($indexStart = 0) { |
38 | - if (!empty($this->rules)) return $this->rules['rules']; |
|
41 | + if (!empty($this->rules)) { |
|
42 | + return $this->rules['rules']; |
|
43 | + } |
|
39 | 44 | $rules = $this->parseTokens($indexStart); |
40 | 45 | usort($rules, [$this, 'sortRules']); |
41 | 46 | $this->checkError($rules); |
@@ -47,8 +52,9 @@ discard block |
||
47 | 52 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
48 | 53 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
49 | 54 | $this->rules = array_merge($this->rules, $processing); |
55 | + } else if ($token['type'] !== Tokenizer::NEW_LINE) { |
|
56 | + $this->addRules($token, $indexStart); |
|
50 | 57 | } |
51 | - else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart); |
|
52 | 58 | } |
53 | 59 | return $this->rules; |
54 | 60 | } |
@@ -56,14 +62,18 @@ discard block |
||
56 | 62 | private function addRules($token, $indexStart) { |
57 | 63 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
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) { |
@@ -90,7 +100,9 @@ discard block |
||
90 | 100 | } |
91 | 101 | |
92 | 102 | private function processingInstructions($token, $indexStart) { |
93 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
103 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
104 | + return false; |
|
105 | + } |
|
94 | 106 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
95 | 107 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
96 | 108 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -112,7 +124,9 @@ discard block |
||
112 | 124 | |
113 | 125 | private function sortRules($a, $b) { |
114 | 126 | //If they have the same depth, compare on index |
115 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
127 | + if ($a->depth === $b->depth) { |
|
128 | + return $a->index < $b->index ? -1 : 1; |
|
129 | + } |
|
116 | 130 | |
117 | 131 | return ($a->depth < $b->depth) ? -1 : 1; |
118 | 132 | } |
@@ -121,7 +135,9 @@ discard block |
||
121 | 135 | $pos = 0; |
122 | 136 | while (($pos = strpos($str, $open, $pos)) !== false) { |
123 | 137 | $end = strpos($str, $close, $pos); |
124 | - if ($end === false) break; |
|
138 | + if ($end === false) { |
|
139 | + break; |
|
140 | + } |
|
125 | 141 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
126 | 142 | } |
127 | 143 |
@@ -7,8 +7,11 @@ discard block |
||
7 | 7 | |
8 | 8 | public function __construct($customBase = null) { |
9 | 9 | $this->baseDir = ''; |
10 | - if ($customBase === null) $this->customBase = getcwd(); |
|
11 | - else $this->customBase = rtrim($customBase, '/'); |
|
10 | + if ($customBase === null) { |
|
11 | + $this->customBase = getcwd(); |
|
12 | + } else { |
|
13 | + $this->customBase = rtrim($customBase, '/'); |
|
14 | + } |
|
12 | 15 | } |
13 | 16 | |
14 | 17 | public function setBaseDir($baseDir) { |
@@ -16,7 +19,10 @@ discard block |
||
16 | 19 | } |
17 | 20 | |
18 | 21 | public function getFilePath($filePath = '') { |
19 | - if (isset($filePath[0]) && $filePath[0] == '/') return $this->customBase . $filePath; |
|
20 | - else return $this->baseDir . $filePath; |
|
22 | + if (isset($filePath[0]) && $filePath[0] == '/') { |
|
23 | + return $this->customBase . $filePath; |
|
24 | + } else { |
|
25 | + return $this->baseDir . $filePath; |
|
26 | + } |
|
21 | 27 | } |
22 | 28 | } |