@@ -32,7 +32,9 @@ discard block |
||
32 | 32 | if ($rules) { |
33 | 33 | foreach ($rules['import'] as $file) { |
34 | 34 | //Check that the import file hasn't been changed since the cache was written |
35 | - if (filemtime($file) > $rules['ctime']) return false; |
|
35 | + if (filemtime($file) > $rules['ctime']) { |
|
36 | + return false; |
|
37 | + } |
|
36 | 38 | } |
37 | 39 | } |
38 | 40 | |
@@ -44,16 +46,22 @@ discard block |
||
44 | 46 | // 2. If the data hasn't changed since the last run |
45 | 47 | //If this function returns false, the rendered template is sent straight from the cache skipping 99% of transphporm's code |
46 | 48 | public function updateRequired($data) { |
47 | - if (!is_file($this->tss)) return true; |
|
49 | + if (!is_file($this->tss)) { |
|
50 | + return true; |
|
51 | + } |
|
48 | 52 | |
49 | 53 | $this->cacheName = $this->getCacheKey($data) . $this->tss; |
50 | 54 | |
51 | 55 | $rules = $this->getRulesFromCache($this->tss, $data); |
52 | 56 | //Nothing was cached or the TSS file has changed, update is required |
53 | - if (empty($rules)) return true; |
|
57 | + if (empty($rules)) { |
|
58 | + return true; |
|
59 | + } |
|
54 | 60 | |
55 | 61 | //Find the sheet's minimum update-frequency, if it hasn't passed then no updates are required |
56 | - if ($rules['ctime']+$rules['minFreq'] <= $this->time) return true; |
|
62 | + if ($rules['ctime']+$rules['minFreq'] <= $this->time) { |
|
63 | + return true; |
|
64 | + } |
|
57 | 65 | |
58 | 66 | return false; |
59 | 67 | } |
@@ -64,7 +72,9 @@ discard block |
||
64 | 72 | |
65 | 73 | foreach ($rules as $rule) { |
66 | 74 | $ruleFreq = $rule->getUpdateFrequency(); |
67 | - if ($ruleFreq < $min) $min = $ruleFreq; |
|
75 | + if ($ruleFreq < $min) { |
|
76 | + $min = $ruleFreq; |
|
77 | + } |
|
68 | 78 | } |
69 | 79 | |
70 | 80 | return $min; |
@@ -79,21 +89,26 @@ discard block |
||
79 | 89 | } |
80 | 90 | |
81 | 91 | public function getCacheKey($data) { |
82 | - if (is_file($this->tss)) $this->getRulesFromCache($this->tss); |
|
92 | + if (is_file($this->tss)) { |
|
93 | + $this->getRulesFromCache($this->tss); |
|
94 | + } |
|
83 | 95 | if ($this->cacheKey) { |
84 | 96 | $parser = new Parser\Value($data); |
85 | 97 | $x= $parser->parseTokens($this->cacheKey)[0]; |
86 | 98 | $this->cacheName = $x . $this->tss; |
87 | 99 | return $x; |
100 | + } else { |
|
101 | + return ''; |
|
88 | 102 | } |
89 | - else return ''; |
|
90 | 103 | } |
91 | 104 | |
92 | 105 | //write the sheet to cache |
93 | 106 | public function write($file, $rules, $imports = []) { |
94 | 107 | if (is_file($file)) { |
95 | 108 | $existing = $this->cache->load($file, filemtime($file)); |
96 | - if (isset($existing['import']) && empty($imports)) $imports = $existing['import']; |
|
109 | + if (isset($existing['import']) && empty($imports)) { |
|
110 | + $imports = $existing['import']; |
|
111 | + } |
|
97 | 112 | $this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]); |
98 | 113 | } |
99 | 114 | return $rules; |
@@ -104,10 +119,14 @@ discard block |
||
104 | 119 | |
105 | 120 | usort($rules, [$this, 'sortRules']); |
106 | 121 | foreach ($rules as $rule) { |
107 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
122 | + if ($rule->shouldRun($this->time)) { |
|
123 | + $this->executeTssRule($rule, $template, $config); |
|
124 | + } |
|
108 | 125 | } |
109 | 126 | |
110 | - if (is_file($this->tss)) $this->write($this->tss, $rules, $this->import); |
|
127 | + if (is_file($this->tss)) { |
|
128 | + $this->write($this->tss, $rules, $this->import); |
|
129 | + } |
|
111 | 130 | } |
112 | 131 | |
113 | 132 | //Load the TSS |
@@ -116,8 +135,11 @@ discard block |
||
116 | 135 | //$rules = $this->cache->load($tss); |
117 | 136 | $rules = $this->getRulesFromCache($tss)['rules']; |
118 | 137 | $this->filePath->addPath(dirname(realpath($tss))); |
119 | - if (empty($rules)) $tss = file_get_contents($tss); |
|
120 | - else return $rules; |
|
138 | + if (empty($rules)) { |
|
139 | + $tss = file_get_contents($tss); |
|
140 | + } else { |
|
141 | + return $rules; |
|
142 | + } |
|
121 | 143 | } |
122 | 144 | return $tss == null ? [] : (new Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $this))->parse(); |
123 | 145 | } |
@@ -134,10 +156,15 @@ discard block |
||
134 | 156 | |
135 | 157 | private function sortRules($a, $b) { |
136 | 158 | //If they have the same depth, compare on index |
137 | - if ($a->query === $b->query) return $this->sortPseudo($a, $b); |
|
159 | + if ($a->query === $b->query) { |
|
160 | + return $this->sortPseudo($a, $b); |
|
161 | + } |
|
138 | 162 | |
139 | - if ($a->depth === $b->depth) $property = 'index'; |
|
140 | - else $property = 'depth'; |
|
163 | + if ($a->depth === $b->depth) { |
|
164 | + $property = 'index'; |
|
165 | + } else { |
|
166 | + $property = 'depth'; |
|
167 | + } |
|
141 | 168 | |
142 | 169 | return ($a->$property < $b->$property) ? -1 : 1; |
143 | 170 | } |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | public function parse($indexStart = 0) { |
27 | - if (!empty($this->rules)) return $this->rules['rules']; |
|
27 | + if (!empty($this->rules)) { |
|
28 | + return $this->rules['rules']; |
|
29 | + } |
|
28 | 30 | $rules = $this->parseTokens($indexStart); |
29 | 31 | $this->checkError($rules); |
30 | 32 | return $rules; |
@@ -35,8 +37,9 @@ discard block |
||
35 | 37 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
36 | 38 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
37 | 39 | $this->rules = array_merge($this->rules, $processing); |
40 | + } else if (!in_array($token['type'], [Tokenizer::NEW_LINE, Tokenizer::AT_SIGN])) { |
|
41 | + $this->addRules($token, $indexStart++); |
|
38 | 42 | } |
39 | - else if (!in_array($token['type'], [Tokenizer::NEW_LINE, Tokenizer::AT_SIGN])) $this->addRules($token, $indexStart++); |
|
40 | 43 | } |
41 | 44 | |
42 | 45 | return $this->rules; |
@@ -46,13 +49,17 @@ discard block |
||
46 | 49 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
47 | 50 | |
48 | 51 | $this->tss->skip(count($selector)); |
49 | - if (count($selector) === 0) return; |
|
52 | + if (count($selector) === 0) { |
|
53 | + return; |
|
54 | + } |
|
50 | 55 | $newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']); |
51 | 56 | $this->rules = $this->writeRule($this->rules, $newRules); |
52 | 57 | } |
53 | 58 | |
54 | 59 | private function checkError($rules) { |
55 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
60 | + if (empty($rules) && count($this->tss) > 0) { |
|
61 | + throw new \Exception('No TSS rules parsed'); |
|
62 | + } |
|
56 | 63 | } |
57 | 64 | |
58 | 65 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -79,7 +86,9 @@ discard block |
||
79 | 86 | } |
80 | 87 | |
81 | 88 | private function processingInstructions($token, $indexStart) { |
82 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
89 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
90 | + return false; |
|
91 | + } |
|
83 | 92 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
84 | 93 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
85 | 94 | $funcToks = $tokens->from(Tokenizer::NAME); |