@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | class Brackets implements \Transphporm\Parser\Tokenizable { |
12 | 12 | |
13 | - private $types = [ |
|
13 | + private $types = [ |
|
14 | 14 | Tokenizer::OPEN_BRACKET => ['(', ')'], |
15 | 15 | Tokenizer::OPEN_BRACE => ['{', '}'], |
16 | 16 | Tokenizer::OPEN_SQUARE_BRACKET => ['[', ']'] |
@@ -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; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | public function setLocale($locale) { |
45 | - $format = new \Transphporm\Module\Format($locale); |
|
46 | - $this->modules[get_class($format)] = $format; |
|
47 | - } |
|
45 | + $format = new \Transphporm\Module\Format($locale); |
|
46 | + $this->modules[get_class($format)] = $format; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | public function addPath($dir) { |
50 | 50 | $this->filePath->addPath($dir); |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | |
101 | 101 | //Load a template, firstly check if it's a file or a valid string |
102 | 102 | private function loadTemplate() { |
103 | - $result = ['cache' => $this->template, 'headers' => []]; |
|
103 | + $result = ['cache' => $this->template, 'headers' => []]; |
|
104 | 104 | if (strpos($this->template, "\n") === false && is_file($this->template)) $result = $this->loadTemplateFromFile($this->template); |
105 | 105 | return $result; |
106 | 106 | } |
107 | 107 | |
108 | - private function loadTemplateFromFile($file) { |
|
109 | - $xml = $this->cache->load($this->cacheKey . $file, filemtime($file)); |
|
110 | - return $xml ? $xml : ['cache' => file_get_contents($file) ?: "", 'headers' => []]; |
|
111 | - } |
|
108 | + private function loadTemplateFromFile($file) { |
|
109 | + $xml = $this->cache->load($this->cacheKey . $file, filemtime($file)); |
|
110 | + return $xml ? $xml : ['cache' => file_get_contents($file) ?: "", 'headers' => []]; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | public function setCache(\ArrayAccess $cache) { |
114 | 114 | $this->cache = new Cache($cache); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'headers' => array_merge($result['headers'], $headers), |
73 | 73 | 'body' => $this->doPostProcessing($template)->output($document) |
74 | 74 | ]; |
75 | - $this->cache->write($tssCache->getCacheKey($data) . $this->template, $result); |
|
75 | + $this->cache->write($tssCache->getCacheKey($data).$this->template, $result); |
|
76 | 76 | } |
77 | 77 | unset($result['cache'], $result['renderTime']); |
78 | 78 | return (object) $result; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $elementData = new \Transphporm\Hook\ElementData(new \SplObjectStorage(), $data); |
83 | 83 | $functionSet = new FunctionSet($elementData); |
84 | 84 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
85 | - $template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>' . $body . '</template>' ); |
|
85 | + $template = new Template($this->isValidDoc($body) ? str_ireplace('<!doctype', '<!DOCTYPE', $body) : '<template>'.$body.'</template>'); |
|
86 | 86 | |
87 | 87 | $valueParser = new Parser\Value($functionSet); |
88 | 88 | $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | private function loadTemplateFromFile($file) { |
109 | - $xml = $this->cache->load($this->cacheKey . $file, filemtime($file)); |
|
109 | + $xml = $this->cache->load($this->cacheKey.$file, filemtime($file)); |
|
110 | 110 | return $xml ? $xml : ['cache' => file_get_contents($file) ?: "", 'headers' => []]; |
111 | 111 | } |
112 | 112 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | $offset = $this->getUpdateFrequency($frequency); |
50 | 50 | |
51 | - if ($time > $this->lastRun + $offset) return true; |
|
51 | + if ($time > $this->lastRun+$offset) return true; |
|
52 | 52 | else return false; |
53 | 53 | } |
54 | 54 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | $num = (int) $frequency; |
76 | 76 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
77 | 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 |
|
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 |
|
79 | 79 | |
80 | - return $num * constant(self::class . '::' . $unit); |
|
80 | + return $num * constant(self::class.'::'.$unit); |
|
81 | 81 | } |
82 | 82 | } |
@@ -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 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | public function updateRequired($data) { |
45 | - $this->cacheName = $this->getCacheKey($data) . $this->fileName; |
|
45 | + $this->cacheName = $this->getCacheKey($data).$this->fileName; |
|
46 | 46 | |
47 | 47 | $rules = $this->getRulesFromCache($this->fileName); |
48 | 48 | //Nothing was cached or the TSS file has changed, update is required |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | if ($this->cacheKey) { |
60 | 60 | $parser = new \Transphporm\Parser\Value($data); |
61 | 61 | $cacheKey = $parser->parseTokens($this->cacheKey)[0]; |
62 | - $this->cacheName = $cacheKey . $this->fileName; |
|
62 | + $this->cacheName = $cacheKey.$this->fileName; |
|
63 | 63 | return $cacheKey; |
64 | 64 | } |
65 | 65 | else return ''; |
@@ -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; |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | $this->fileName = $fileName; |
18 | 18 | $this->filePath = $filePath; |
19 | 19 | $this->cache = $cache; |
20 | - $this->time = isset($time) ? $time : time(); |
|
21 | - $this->cacheName = $this->fileName; |
|
20 | + $this->time = isset($time) ? $time : time(); |
|
21 | + $this->cacheName = $this->fileName; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | private function getRulesFromCache($file) { |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | //write the sheet to cache |
80 | - public function write($rules, $imports = []) { |
|
80 | + public function write($rules, $imports = []) { |
|
81 | 81 | $existing = $this->cache->load($this->fileName, filemtime($this->fileName)); |
82 | 82 | if (isset($existing['import']) && empty($imports)) $imports = $existing['import']; |
83 | 83 | $this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]); |
84 | 84 | |
85 | 85 | return $rules; |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - //Gets the minimum update-frequency for a sheet's rules |
|
88 | + //Gets the minimum update-frequency for a sheet's rules |
|
89 | 89 | private function getMinUpdateFreq($rules) { |
90 | 90 | $min = \PHP_INT_MAX; |
91 | 91 |
@@ -7,17 +7,17 @@ |
||
7 | 7 | namespace Transphporm\SheetLoader; |
8 | 8 | //Separates out TSS file loading/caching from parsing |
9 | 9 | class SheetLoader { |
10 | - private $tss; |
|
11 | - private $filePath; |
|
12 | - private $time; |
|
13 | - private $import = []; |
|
14 | - |
|
15 | - public function __construct(\Transphporm\Cache $cache, \Transphporm\FilePath $filePath, TSSRules $tss, $time) { |
|
16 | - $this->cache = $cache; |
|
17 | - $this->filePath = $filePath; |
|
18 | - $this->tss = $tss; |
|
19 | - $this->time = isset($time) ? $time : time(); |
|
20 | - } |
|
10 | + private $tss; |
|
11 | + private $filePath; |
|
12 | + private $time; |
|
13 | + private $import = []; |
|
14 | + |
|
15 | + public function __construct(\Transphporm\Cache $cache, \Transphporm\FilePath $filePath, TSSRules $tss, $time) { |
|
16 | + $this->cache = $cache; |
|
17 | + $this->filePath = $filePath; |
|
18 | + $this->tss = $tss; |
|
19 | + $this->time = isset($time) ? $time : time(); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | //Allows controlling whether any updates are required to the template |
23 | 23 | //e.g. return false |