@@ -69,7 +69,9 @@ discard block |
||
69 | 69 | $selector->type = $token['type']; |
70 | 70 | $selectors[] = $selector; |
71 | 71 | } |
72 | - if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value']; |
|
72 | + if (isset($token['value'])) { |
|
73 | + $selectors[count($selectors)-1]->string = $token['value']; |
|
74 | + } |
|
73 | 75 | } |
74 | 76 | return $selectors; |
75 | 77 | } |
@@ -79,7 +81,9 @@ discard block |
||
79 | 81 | $selectors = $this->split($css); |
80 | 82 | $xpath = '/'; |
81 | 83 | foreach ($selectors as $selector) { |
82 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
84 | + if (isset($this->translators[$selector->type])) { |
|
85 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
86 | + } |
|
83 | 87 | } |
84 | 88 | |
85 | 89 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -92,11 +96,15 @@ discard block |
||
92 | 96 | $split = $css->splitOnToken(Tokenizer::GREATER_THAN); |
93 | 97 | $numSplits = count($split); |
94 | 98 | |
95 | - if ($numSplits <= 1) return $css; |
|
99 | + if ($numSplits <= 1) { |
|
100 | + return $css; |
|
101 | + } |
|
96 | 102 | |
97 | 103 | for ($i = 0; $i < $numSplits; $i++) { |
98 | 104 | $tokens->add($split[$i]->trim()); |
99 | - if (isset($split[$i+1])) $tokens->add(['type' => Tokenizer::GREATER_THAN]); |
|
105 | + if (isset($split[$i+1])) { |
|
106 | + $tokens->add(['type' => Tokenizer::GREATER_THAN]); |
|
107 | + } |
|
100 | 108 | } |
101 | 109 | |
102 | 110 | return $tokens; |
@@ -44,22 +44,31 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | private function timeFrequency($frequency, $time = null) { |
47 | - if ($time === null) $time = time(); |
|
47 | + if ($time === null) { |
|
48 | + $time = time(); |
|
49 | + } |
|
48 | 50 | |
49 | 51 | $offset = $this->getUpdateFrequency($frequency); |
50 | 52 | |
51 | - if ($time > $this->lastRun + $offset) return true; |
|
52 | - else return false; |
|
53 | + if ($time > $this->lastRun + $offset) { |
|
54 | + return true; |
|
55 | + } else { |
|
56 | + return false; |
|
57 | + } |
|
53 | 58 | } |
54 | 59 | |
55 | 60 | public function shouldRun($time = null) { |
56 | 61 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
57 | 62 | $frequency = $this->properties['update-frequency']->read(); |
58 | 63 | $static = ['always' => true, 'never' => false]; |
59 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
60 | - else return $this->timeFrequency($frequency, $time); |
|
64 | + if (isset($static[$frequency])) { |
|
65 | + return $static[$frequency]; |
|
66 | + } else { |
|
67 | + return $this->timeFrequency($frequency, $time); |
|
68 | + } |
|
69 | + } else { |
|
70 | + return true; |
|
61 | 71 | } |
62 | - else return true; |
|
63 | 72 | } |
64 | 73 | |
65 | 74 | public function getUpdateFrequency($frequency = null) { |
@@ -67,15 +76,22 @@ discard block |
||
67 | 76 | $frequency = isset($this->properties['update-frequency']) ? $this->properties['update-frequency']->read() : false; |
68 | 77 | } |
69 | 78 | |
70 | - if (empty($frequency)) return 0; |
|
71 | - else return $this->calcUpdateFrequency($frequency); |
|
79 | + if (empty($frequency)) { |
|
80 | + return 0; |
|
81 | + } else { |
|
82 | + return $this->calcUpdateFrequency($frequency); |
|
83 | + } |
|
72 | 84 | } |
73 | 85 | |
74 | 86 | private function calcUpdateFrequency($frequency) { |
75 | 87 | $num = (int) $frequency; |
76 | 88 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
77 | - if ($frequency == 'always') return 0; |
|
78 | - else if ($frequency == 'never') return self::D*3650; //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem |
|
89 | + if ($frequency == 'always') { |
|
90 | + return 0; |
|
91 | + } else if ($frequency == 'never') { |
|
92 | + return self::D*3650; |
|
93 | + } |
|
94 | + //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem |
|
79 | 95 | |
80 | 96 | return $num * constant(self::class . '::' . $unit); |
81 | 97 | } |
@@ -30,7 +30,9 @@ discard block |
||
30 | 30 | if ($rules) { |
31 | 31 | foreach ($rules['import'] as $file) { |
32 | 32 | //Check that the import file hasn't been changed since the cache was written |
33 | - if (filemtime($file) > $rules['ctime']) return false; |
|
33 | + if (filemtime($file) > $rules['ctime']) { |
|
34 | + return false; |
|
35 | + } |
|
34 | 36 | } |
35 | 37 | } |
36 | 38 | |
@@ -46,10 +48,14 @@ discard block |
||
46 | 48 | |
47 | 49 | $rules = $this->getRulesFromCache($this->fileName); |
48 | 50 | //Nothing was cached or the TSS file has changed, update is required |
49 | - if (empty($rules)) return true; |
|
51 | + if (empty($rules)) { |
|
52 | + return true; |
|
53 | + } |
|
50 | 54 | |
51 | 55 | //Find the sheet's minimum update-frequency, if it hasn't passed then no updates are required |
52 | - if ($rules['ctime']+$rules['minFreq'] <= $this->time) return true; |
|
56 | + if ($rules['ctime']+$rules['minFreq'] <= $this->time) { |
|
57 | + return true; |
|
58 | + } |
|
53 | 59 | |
54 | 60 | return false; |
55 | 61 | } |
@@ -61,15 +67,19 @@ discard block |
||
61 | 67 | $cacheKey = $parser->parseTokens($this->cacheKey)[0]; |
62 | 68 | $this->cacheName = $cacheKey . $this->fileName; |
63 | 69 | return $cacheKey; |
70 | + } else { |
|
71 | + return ''; |
|
64 | 72 | } |
65 | - else return ''; |
|
66 | 73 | } |
67 | 74 | |
68 | 75 | public function getRules($cssToXpath, $valueParser, $sheetLoader, $indexStart) { |
69 | 76 | $rules = $this->getRulesFromCache($this->fileName)['rules']; |
70 | 77 | $this->filePath->addPath(dirname(realpath($this->fileName))); |
71 | - if (empty($rules)) $tss = file_get_contents($this->fileName); |
|
72 | - else return $rules; |
|
78 | + if (empty($rules)) { |
|
79 | + $tss = file_get_contents($this->fileName); |
|
80 | + } else { |
|
81 | + return $rules; |
|
82 | + } |
|
73 | 83 | |
74 | 84 | return $tss == null ? [] : (new \Transphporm\Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart); |
75 | 85 | } |
@@ -77,7 +87,9 @@ discard block |
||
77 | 87 | //write the sheet to cache |
78 | 88 | public function write($rules, $imports = []) { |
79 | 89 | $existing = $this->cache->load($this->fileName, filemtime($this->fileName)); |
80 | - if (isset($existing['import']) && empty($imports)) $imports = $existing['import']; |
|
90 | + if (isset($existing['import']) && empty($imports)) { |
|
91 | + $imports = $existing['import']; |
|
92 | + } |
|
81 | 93 | $this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]); |
82 | 94 | |
83 | 95 | return $rules; |
@@ -89,7 +101,9 @@ discard block |
||
89 | 101 | |
90 | 102 | foreach ($rules as $rule) { |
91 | 103 | $ruleFreq = $rule->getUpdateFrequency(); |
92 | - if ($ruleFreq < $min) $min = $ruleFreq; |
|
104 | + if ($ruleFreq < $min) { |
|
105 | + $min = $ruleFreq; |
|
106 | + } |
|
93 | 107 | } |
94 | 108 | |
95 | 109 | return $min; |