Completed
Push — master ( a6da3f...e38a6e )
by Richard
03:27
created
src/Parser/Sheet.php 1 patch
Braces   +35 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,8 +24,11 @@  discard block
 block discarded – undo
24 24
 			$this->file = $tss;
25 25
 			$this->rules = $this->getRulesFromCache($tss, $templatePrefix);
26 26
 			$baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR;
27
-			if (empty($this->rules)) $tss = file_get_contents($tss);
28
-			else return;
27
+			if (empty($this->rules)) {
28
+				$tss = file_get_contents($tss);
29
+			} else {
30
+				return;
31
+			}
29 32
 		}
30 33
 		$this->tss = $this->stripComments($tss, '//', "\n");
31 34
 		$this->tss = $this->stripComments($this->tss, '/*', '*/');
@@ -44,7 +47,9 @@  discard block
 block discarded – undo
44 47
 		$rules = $this->cache->load($key, filemtime($this->file));
45 48
 		if ($rules) {
46 49
 			foreach ($rules['import'] as $file) {
47
-				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false;
50
+				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) {
51
+					return false;
52
+				}
48 53
 			}
49 54
 		}
50 55
 		return $rules;
@@ -55,11 +60,15 @@  discard block
 block discarded – undo
55 60
 	}
56 61
 
57 62
 	public function parse($indexStart = 0) {
58
-		if (!empty($this->rules)) return $this->rules['rules'];
63
+		if (!empty($this->rules)) {
64
+			return $this->rules['rules'];
65
+		}
59 66
 		$rules = $this->parseTokens($indexStart);
60 67
 		usort($rules, [$this, 'sortRules']);
61 68
 		$this->checkError($rules);
62
-		if (!empty($this->file)) $this->cache->write($this->getCacheKey($this->file), ['rules' => $rules, 'import' => $this->import]);
69
+		if (!empty($this->file)) {
70
+			$this->cache->write($this->getCacheKey($this->file), ['rules' => $rules, 'import' => $this->import]);
71
+		}
63 72
 		return $rules;
64 73
 	}
65 74
 
@@ -71,14 +80,15 @@  discard block
 block discarded – undo
71 80
 				$this->tss->skip($processing['skip']+1);
72 81
 				$rules = array_merge($rules, $processing['rules']);
73 82
 				continue;
74
-			}
75
-			else if ($token['type'] === Tokenizer::NEW_LINE) {
83
+			} else if ($token['type'] === Tokenizer::NEW_LINE) {
76 84
 				$line++;
77 85
 				continue;
78 86
 			}
79 87
 			$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
80 88
 			$this->tss->skip(count($selector));
81
-			if (count($selector) === 0) break;
89
+			if (count($selector) === 0) {
90
+				break;
91
+			}
82 92
 
83 93
 			$newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $line);
84 94
 			$rules = $this->writeRule($rules, $newRules);
@@ -87,7 +97,9 @@  discard block
 block discarded – undo
87 97
 	}
88 98
 
89 99
 	private function checkError($rules) {
90
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
100
+		if (empty($rules) && count($this->tss) > 0) {
101
+			throw new \Exception('No TSS rules parsed');
102
+		}
91 103
 	}
92 104
 
93 105
 	private function CssToRules($selector, $index, $properties, $line) {
@@ -114,7 +126,9 @@  discard block
 block discarded – undo
114 126
 	}
115 127
 
116 128
 	private function processingInstructions($token, $indexStart) {
117
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
129
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
130
+			return false;
131
+		}
118 132
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
119 133
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
120 134
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -124,8 +138,11 @@  discard block
 block discarded – undo
124 138
 	}
125 139
 
126 140
 	private function import($args, $indexStart) {
127
-		if ($this->file !== null) $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
128
-		else $fileName = $args[0];
141
+		if ($this->file !== null) {
142
+			$fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0];
143
+		} else {
144
+			$fileName = $args[0];
145
+		}
129 146
 		$this->import[] = $fileName;
130 147
 		$sheet = new Sheet($fileName, $this->prefix, $this->baseDir, $this->xPath, $this->valueParser, $this->cache);
131 148
 		return $sheet->parse($indexStart);
@@ -133,7 +150,9 @@  discard block
 block discarded – undo
133 150
 
134 151
 	private function sortRules($a, $b) {
135 152
 		//If they have the same depth, compare on index
136
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
153
+		if ($a->depth === $b->depth) {
154
+			return $a->index < $b->index ? -1 : 1;
155
+		}
137 156
 
138 157
 		return ($a->depth < $b->depth) ? -1 : 1;
139 158
 	}
@@ -142,7 +161,9 @@  discard block
 block discarded – undo
142 161
 		$pos = 0;
143 162
 		while (($pos = strpos($str, $open, $pos)) !== false) {
144 163
 			$end = strpos($str, $close, $pos);
145
-			if ($end === false) break;
164
+			if ($end === false) {
165
+				break;
166
+			}
146 167
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
147 168
 		}
148 169
 
Please login to merge, or discard this patch.