@@ -102,14 +102,14 @@ |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | private function getProperties($tokens) { |
105 | - $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
105 | + $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
106 | 106 | |
107 | - $return = []; |
|
108 | - foreach ($rules as $rule) { |
|
109 | - $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
110 | - $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
111 | - } |
|
107 | + $return = []; |
|
108 | + foreach ($rules as $rule) { |
|
109 | + $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
110 | + $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
111 | + } |
|
112 | 112 | |
113 | - return $return; |
|
114 | - } |
|
113 | + return $return; |
|
114 | + } |
|
115 | 115 | } |
@@ -44,17 +44,17 @@ |
||
44 | 44 | |
45 | 45 | |
46 | 46 | //write the sheet to cache |
47 | - public function write($file, $rules, $imports = []) { |
|
47 | + public function write($file, $rules, $imports = []) { |
|
48 | 48 | if (is_file($file)) { |
49 | 49 | $existing = $this->cache->load($file, filemtime($file)); |
50 | 50 | if (isset($existing['import'])) $imports = $existing['import']; |
51 | 51 | $this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]); |
52 | 52 | } |
53 | 53 | return $rules; |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - public function setKey($key) { |
|
57 | - $this->cacheKey = $key; |
|
58 | - } |
|
56 | + public function setKey($key) { |
|
57 | + $this->cacheKey = $key; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | \ No newline at end of file |
@@ -36,7 +36,7 @@ |
||
36 | 36 | if ($this->cacheKey) { |
37 | 37 | $parser = new Parser\Value($data); |
38 | 38 | $parsedKey = $parser->parseTokens($this->cacheKey)[0]; |
39 | - $this->cacheName = $parsedKey . $this->tss; |
|
39 | + $this->cacheName = $parsedKey.$this->tss; |
|
40 | 40 | return $parsedKey; |
41 | 41 | } |
42 | 42 | else return ''; |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | if ($rules) { |
25 | 25 | foreach ($rules['import'] as $file) { |
26 | 26 | //Check that the import file hasn't been changed since the cache was written |
27 | - if (filemtime($file) > $rules['ctime']) return false; |
|
27 | + if (filemtime($file) > $rules['ctime']) { |
|
28 | + return false; |
|
29 | + } |
|
28 | 30 | } |
29 | 31 | } |
30 | 32 | return $rules; |
@@ -32,14 +34,17 @@ discard block |
||
32 | 34 | |
33 | 35 | public function getCacheKey($tss, $data) { |
34 | 36 | //Read the rules so that $this->cacheKey is set |
35 | - if (is_file($tss)) $this->getRulesFromCache($tss); |
|
37 | + if (is_file($tss)) { |
|
38 | + $this->getRulesFromCache($tss); |
|
39 | + } |
|
36 | 40 | if ($this->cacheKey) { |
37 | 41 | $parser = new Parser\Value($data); |
38 | 42 | $parsedKey = $parser->parseTokens($this->cacheKey)[0]; |
39 | 43 | $this->cacheName = $parsedKey . $this->tss; |
40 | 44 | return $parsedKey; |
45 | + } else { |
|
46 | + return ''; |
|
41 | 47 | } |
42 | - else return ''; |
|
43 | 48 | } |
44 | 49 | |
45 | 50 | |
@@ -47,7 +52,9 @@ discard block |
||
47 | 52 | public function write($file, $rules, $imports = []) { |
48 | 53 | if (is_file($file)) { |
49 | 54 | $existing = $this->cache->load($file, filemtime($file)); |
50 | - if (isset($existing['import'])) $imports = $existing['import']; |
|
55 | + if (isset($existing['import'])) { |
|
56 | + $imports = $existing['import']; |
|
57 | + } |
|
51 | 58 | $this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]); |
52 | 59 | } |
53 | 60 | return $rules; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | public function updateRequired($data) { |
44 | - $this->cacheName = $this->getCacheKey($data) . $this->fileName; |
|
44 | + $this->cacheName = $this->getCacheKey($data).$this->fileName; |
|
45 | 45 | |
46 | 46 | $rules = $this->getRulesFromCache($this->fileName, $data); |
47 | 47 | //Nothing was cached or the TSS file has changed, update is required |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | if ($this->cacheKey) { |
59 | 59 | $parser = new \Transphporm\Parser\Value($data); |
60 | 60 | $cacheKey = $parser->parseTokens($this->cacheKey)[0]; |
61 | - $this->cacheName = $cacheKey . $this->fileName; |
|
61 | + $this->cacheName = $cacheKey.$this->fileName; |
|
62 | 62 | return $cacheKey; |
63 | 63 | } |
64 | 64 | else return ''; |
@@ -29,7 +29,9 @@ discard block |
||
29 | 29 | if ($rules) { |
30 | 30 | foreach ($rules['import'] as $file) { |
31 | 31 | //Check that the import file hasn't been changed since the cache was written |
32 | - if (filemtime($file) > $rules['ctime']) return false; |
|
32 | + if (filemtime($file) > $rules['ctime']) { |
|
33 | + return false; |
|
34 | + } |
|
33 | 35 | } |
34 | 36 | } |
35 | 37 | |
@@ -45,10 +47,14 @@ discard block |
||
45 | 47 | |
46 | 48 | $rules = $this->getRulesFromCache($this->fileName, $data); |
47 | 49 | //Nothing was cached or the TSS file has changed, update is required |
48 | - if (empty($rules)) return true; |
|
50 | + if (empty($rules)) { |
|
51 | + return true; |
|
52 | + } |
|
49 | 53 | |
50 | 54 | //Find the sheet's minimum update-frequency, if it hasn't passed then no updates are required |
51 | - if ($rules['ctime']+$rules['minFreq'] <= $this->time) return true; |
|
55 | + if ($rules['ctime']+$rules['minFreq'] <= $this->time) { |
|
56 | + return true; |
|
57 | + } |
|
52 | 58 | |
53 | 59 | return false; |
54 | 60 | } |
@@ -60,15 +66,19 @@ discard block |
||
60 | 66 | $cacheKey = $parser->parseTokens($this->cacheKey)[0]; |
61 | 67 | $this->cacheName = $cacheKey . $this->fileName; |
62 | 68 | return $cacheKey; |
69 | + } else { |
|
70 | + return ''; |
|
63 | 71 | } |
64 | - else return ''; |
|
65 | 72 | } |
66 | 73 | |
67 | 74 | public function getRules($cssToXpath, $valueParser, $sheetLoader, $indexStart) { |
68 | 75 | $rules = $this->getRulesFromCache($this->fileName)['rules']; |
69 | 76 | $this->filePath->addPath(dirname(realpath($this->fileName))); |
70 | - if (empty($rules)) $tss = file_get_contents($this->fileName); |
|
71 | - else return $rules; |
|
77 | + if (empty($rules)) { |
|
78 | + $tss = file_get_contents($this->fileName); |
|
79 | + } else { |
|
80 | + return $rules; |
|
81 | + } |
|
72 | 82 | |
73 | 83 | return $tss == null ? [] : (new \Transphporm\Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart); |
74 | 84 | } |
@@ -76,7 +86,9 @@ discard block |
||
76 | 86 | //write the sheet to cache |
77 | 87 | public function write($rules, $imports = []) { |
78 | 88 | $existing = $this->cache->load($this->fileName, filemtime($this->fileName)); |
79 | - if (isset($existing['import']) && empty($imports)) $imports = $existing['import']; |
|
89 | + if (isset($existing['import']) && empty($imports)) { |
|
90 | + $imports = $existing['import']; |
|
91 | + } |
|
80 | 92 | $this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]); |
81 | 93 | |
82 | 94 | return $rules; |
@@ -88,7 +100,9 @@ discard block |
||
88 | 100 | |
89 | 101 | foreach ($rules as $rule) { |
90 | 102 | $ruleFreq = $rule->getUpdateFrequency(); |
91 | - if ($ruleFreq < $min) $min = $ruleFreq; |
|
103 | + if ($ruleFreq < $min) { |
|
104 | + $min = $ruleFreq; |
|
105 | + } |
|
92 | 106 | } |
93 | 107 | |
94 | 108 | return $min; |
@@ -39,8 +39,9 @@ discard block |
||
39 | 39 | if ($token['type'] == \Transphporm\Parser\Tokenizer::NAME && $token['value'] == 'data') { |
40 | 40 | $tokens->next(); |
41 | 41 | $newTokens = array_merge($newTokens, iterator_to_array($tokens->current()['value'])); |
42 | + } else { |
|
43 | + $newTokens[] = $token; |
|
42 | 44 | } |
43 | - else $newTokens[] = $token; |
|
44 | 45 | } |
45 | 46 | |
46 | 47 | $this->tss->setCacheKey(new \Transphporm\Parser\Tokens($newTokens)); |
@@ -58,7 +59,9 @@ discard block |
||
58 | 59 | usort($rules, [$this, 'sortRules']); |
59 | 60 | |
60 | 61 | foreach ($rules as $rule) { |
61 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
62 | + if ($rule->shouldRun($this->time)) { |
|
63 | + $this->executeTssRule($rule, $template, $config); |
|
64 | + } |
|
62 | 65 | } |
63 | 66 | |
64 | 67 | //if (is_file($this->tss)) $this->write($this->tss, $rules, $this->import); |
@@ -83,10 +86,15 @@ discard block |
||
83 | 86 | |
84 | 87 | private function sortRules($a, $b) { |
85 | 88 | //If they have the same depth, compare on index |
86 | - if ($a->query === $b->query) return $this->sortPseudo($a, $b); |
|
89 | + if ($a->query === $b->query) { |
|
90 | + return $this->sortPseudo($a, $b); |
|
91 | + } |
|
87 | 92 | |
88 | - if ($a->depth === $b->depth) $property = 'index'; |
|
89 | - else $property = 'depth'; |
|
93 | + if ($a->depth === $b->depth) { |
|
94 | + $property = 'index'; |
|
95 | + } else { |
|
96 | + $property = 'depth'; |
|
97 | + } |
|
90 | 98 | |
91 | 99 | return ($a->$property < $b->$property) ? -1 : 1; |
92 | 100 | } |