Completed
Push — master ( da7c37...06f4a4 )
by Tom
03:19
created
src/SheetLoader.php 1 patch
Braces   +42 added lines, -15 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
@@ -106,10 +121,14 @@  discard block
 block discarded – undo
106 121
 		usort($rules, [$this, 'sortRules']);
107 122
 
108 123
 		foreach ($rules as $rule) {
109
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
124
+			if ($rule->shouldRun($this->time)) {
125
+				$this->executeTssRule($rule, $template, $config);
126
+			}
110 127
 		}
111 128
 
112
-		if (is_file($this->tss)) $this->write($this->tss, $rules, $this->import);
129
+		if (is_file($this->tss)) {
130
+			$this->write($this->tss, $rules, $this->import);
131
+		}
113 132
 	}
114 133
 
115 134
 	//Load the TSS
@@ -118,8 +137,11 @@  discard block
 block discarded – undo
118 137
     		//$rules = $this->cache->load($tss);
119 138
     		$rules = $this->getRulesFromCache($tss)['rules'];
120 139
 			$this->filePath->addPath(dirname(realpath($tss)));
121
-			if (empty($rules)) $tss = file_get_contents($tss);
122
-			else return $rules;
140
+			if (empty($rules)) {
141
+				$tss = file_get_contents($tss);
142
+			} else {
143
+				return $rules;
144
+			}
123 145
     	}
124 146
 		return $tss == null ? [] : (new Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $this))->parse($indexStart);
125 147
 	}
@@ -136,10 +158,15 @@  discard block
 block discarded – undo
136 158
 
137 159
 	private function sortRules($a, $b) {
138 160
 		//If they have the same depth, compare on index
139
-		if ($a->query === $b->query) return $this->sortPseudo($a, $b);
161
+		if ($a->query === $b->query) {
162
+			return $this->sortPseudo($a, $b);
163
+		}
140 164
 
141
-		if ($a->depth === $b->depth) $property = 'index';
142
-		else $property = 'depth';
165
+		if ($a->depth === $b->depth) {
166
+			$property = 'index';
167
+		} else {
168
+			$property = 'depth';
169
+		}
143 170
 
144 171
 		return ($a->$property < $b->$property) ? -1 : 1;
145 172
 	}
Please login to merge, or discard this patch.