@@ -52,6 +52,9 @@ discard block |
||
52 | 52 | return array_keys(array_column($this->tokens, 'type'), $tokenType); |
53 | 53 | } |
54 | 54 | |
55 | + /** |
|
56 | + * @return integer|null |
|
57 | + */ |
|
55 | 58 | private function getKeyToSlice($tokenType) { |
56 | 59 | $keys = $this->getKeysOfTokenType($tokenType); |
57 | 60 | if (empty($keys)) return false; |
@@ -68,6 +71,9 @@ discard block |
||
68 | 71 | return $this->sliceTokens($tokenType, "to", $inclusive); |
69 | 72 | } |
70 | 73 | |
74 | + /** |
|
75 | + * @param string $type |
|
76 | + */ |
|
71 | 77 | private function sliceTokens($tokenType, $type, $increment = false) { |
72 | 78 | $key = $this->getKeyToSlice($tokenType); |
73 | 79 | if ($key === false) return new Tokens([]); |
@@ -76,6 +82,9 @@ discard block |
||
76 | 82 | else return new Tokens(array_slice($this->tokens, $this->iterator, $key)); |
77 | 83 | } |
78 | 84 | |
85 | + /** |
|
86 | + * @param integer $count |
|
87 | + */ |
|
79 | 88 | public function skip($count) { |
80 | 89 | $this->iterator += $count; |
81 | 90 | } |
@@ -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 | |
@@ -48,10 +50,14 @@ discard block |
||
48 | 50 | |
49 | 51 | $rules = $this->getRulesFromCache($this->fileName); |
50 | 52 | //Nothing was cached or the TSS file has changed, update is required |
51 | - if (empty($rules)) return true; |
|
53 | + if (empty($rules)) { |
|
54 | + return true; |
|
55 | + } |
|
52 | 56 | |
53 | 57 | //Find the sheet's minimum update-frequency, if it hasn't passed then no updates are required |
54 | - if ($rules['ctime']+$rules['minFreq'] <= $this->time) return true; |
|
58 | + if ($rules['ctime']+$rules['minFreq'] <= $this->time) { |
|
59 | + return true; |
|
60 | + } |
|
55 | 61 | |
56 | 62 | return false; |
57 | 63 | } |
@@ -63,15 +69,19 @@ discard block |
||
63 | 69 | $cacheKey = $parser->parseTokens($this->cacheKey)[0]; |
64 | 70 | $this->cacheName = $cacheKey . $this->fileName; |
65 | 71 | return $cacheKey; |
72 | + } else { |
|
73 | + return $this->fileName; |
|
66 | 74 | } |
67 | - else return $this->fileName; |
|
68 | 75 | } |
69 | 76 | |
70 | 77 | public function getRules($cssToXpath, $valueParser, $sheetLoader, $indexStart) { |
71 | 78 | $rules = $this->getRulesFromCache($this->fileName); |
72 | 79 | $this->filePath->addPath(dirname(realpath($this->fileName))); |
73 | - if (empty($rules)) $tss = file_get_contents($this->fileName); |
|
74 | - else return $rules['rules']; |
|
80 | + if (empty($rules)) { |
|
81 | + $tss = file_get_contents($this->fileName); |
|
82 | + } else { |
|
83 | + return $rules['rules']; |
|
84 | + } |
|
75 | 85 | |
76 | 86 | return $tss == null ? [] : (new \Transphporm\Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart); |
77 | 87 | } |
@@ -79,7 +89,9 @@ discard block |
||
79 | 89 | //write the sheet to cache |
80 | 90 | public function write($rules, $imports = []) { |
81 | 91 | $existing = $this->cache->load($this->fileName, filemtime($this->fileName)); |
82 | - if (isset($existing['import']) && empty($imports)) $imports = $existing['import']; |
|
92 | + if (isset($existing['import']) && empty($imports)) { |
|
93 | + $imports = $existing['import']; |
|
94 | + } |
|
83 | 95 | $this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]); |
84 | 96 | |
85 | 97 | return $rules; |
@@ -91,7 +103,9 @@ discard block |
||
91 | 103 | |
92 | 104 | foreach ($rules as $rule) { |
93 | 105 | $ruleFreq = $rule->getUpdateFrequency(); |
94 | - if ($ruleFreq < $min) $min = $ruleFreq; |
|
106 | + if ($ruleFreq < $min) { |
|
107 | + $min = $ruleFreq; |
|
108 | + } |
|
95 | 109 | } |
96 | 110 | |
97 | 111 | return $min; |