Completed
Push — master ( ed50b2...c7ae95 )
by Richard
02:27
created
src/Parser/Tokens.php 1 patch
Braces   +26 added lines, -9 removed lines patch added patch discarded remove patch
@@ -44,23 +44,35 @@  discard block
 block discarded – undo
44 44
 
45 45
     private function getKeyToSlice($tokenType) {
46 46
         $keys = $this->getKeysOfTokenType($tokenType);
47
-        if (empty($keys)) return false;
47
+        if (empty($keys)) {
48
+        	return false;
49
+        }
48 50
         $key = $keys[0];
49
-        for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) $key = $keys[$i];
51
+        for ($i = 0; $key < $this->iterator && isset($keys[$i]); $i++) {
52
+        	$key = $keys[$i];
53
+        }
50 54
         return $key;
51 55
     }
52 56
 
53 57
     public function from($tokenType, $inclusive = false) {
54 58
         $key = $this->getKeyToSlice($tokenType);
55
-        if ($key === false) return new Tokens([]);
56
-        if (!$inclusive) $key++;
59
+        if ($key === false) {
60
+        	return new Tokens([]);
61
+        }
62
+        if (!$inclusive) {
63
+        	$key++;
64
+        }
57 65
         return new Tokens(array_slice($this->tokens, $key));
58 66
     }
59 67
 
60 68
     public function to($tokenType, $inclusive = false) {
61 69
         $key = $this->getKeyToSlice($tokenType);
62
-        if ($key === false) return new Tokens([]);
63
-        if ($inclusive) $key++;
70
+        if ($key === false) {
71
+        	return new Tokens([]);
72
+        }
73
+        if ($inclusive) {
74
+        	$key++;
75
+        }
64 76
         return new Tokens(array_slice($this->tokens, $this->iterator, $key));
65 77
     }
66 78
 
@@ -72,8 +84,11 @@  discard block
 block discarded – undo
72 84
         $splitTokens = [];
73 85
 		$i = 0;
74 86
 		foreach ($this->tokens as $token) {
75
-			if ($token['type'] === $tokenType) $i++;
76
-			else $splitTokens[$i][] = $token;
87
+			if ($token['type'] === $tokenType) {
88
+				$i++;
89
+			} else {
90
+				$splitTokens[$i][] = $token;
91
+			}
77 92
 		}
78 93
         return array_map(function ($tokens) {
79 94
             return new Tokens($tokens);
@@ -96,7 +111,9 @@  discard block
 block discarded – undo
96 111
 
97 112
     public function removeLine() {
98 113
         $tokens = $this->tokens;
99
-        foreach ($tokens as &$token) unset($token['line']);
114
+        foreach ($tokens as &$token) {
115
+        	unset($token['line']);
116
+        }
100 117
         return new Tokens($tokens);
101 118
     }
102 119
 
Please login to merge, or discard this patch.
src/Parser/Sheet.php 1 patch
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,8 +25,11 @@  discard block
 block discarded – undo
25 25
 			$this->file = $tss;
26 26
 			$this->rules = $this->cache->load($tss);
27 27
 			$this->filePath->setBaseDir(dirname(realpath($tss)) . DIRECTORY_SEPARATOR);
28
-			if (empty($this->rules)) $tss = file_get_contents($tss);
29
-			else return;
28
+			if (empty($this->rules)) {
29
+				$tss = file_get_contents($tss);
30
+			} else {
31
+				return;
32
+			}
30 33
 		}
31 34
 		$this->tss = $this->stripComments($tss, '//', "\n");
32 35
 		$this->tss = $this->stripComments($this->tss, '/*', '*/');
@@ -35,7 +38,9 @@  discard block
 block discarded – undo
35 38
 	}
36 39
 
37 40
 	public function parse($indexStart = 0) {
38
-		if (!empty($this->rules)) return $this->rules['rules'];
41
+		if (!empty($this->rules)) {
42
+			return $this->rules['rules'];
43
+		}
39 44
 		$rules = $this->parseTokens($indexStart);
40 45
 		usort($rules, [$this, 'sortRules']);
41 46
 		$this->checkError($rules);
@@ -47,8 +52,9 @@  discard block
 block discarded – undo
47 52
 		foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) {
48 53
 			if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) {
49 54
 				$this->rules = array_merge($this->rules, $processing);
55
+			} else if ($token['type'] !== Tokenizer::NEW_LINE) {
56
+				$this->addRules($token, $indexStart);
50 57
 			}
51
-			else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart);
52 58
 		}
53 59
 		return $this->rules;
54 60
 	}
@@ -56,14 +62,18 @@  discard block
 block discarded – undo
56 62
 	private function addRules($token, $indexStart) {
57 63
 		$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
58 64
 		$this->tss->skip(count($selector));
59
-		if (count($selector) === 0) return;
65
+		if (count($selector) === 0) {
66
+			return;
67
+		}
60 68
 
61 69
 		$newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']);
62 70
 		$this->rules = $this->writeRule($this->rules, $newRules);
63 71
 	}
64 72
 
65 73
 	private function checkError($rules) {
66
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
74
+		if (empty($rules) && count($this->tss) > 0) {
75
+			throw new \Exception('No TSS rules parsed');
76
+		}
67 77
 	}
68 78
 
69 79
 	private function CssToRules($selector, $index, $properties, $line) {
@@ -90,7 +100,9 @@  discard block
 block discarded – undo
90 100
 	}
91 101
 
92 102
 	private function processingInstructions($token, $indexStart) {
93
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
103
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
104
+			return false;
105
+		}
94 106
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
95 107
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
96 108
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -112,7 +124,9 @@  discard block
 block discarded – undo
112 124
 
113 125
 	private function sortRules($a, $b) {
114 126
 		//If they have the same depth, compare on index
115
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
127
+		if ($a->depth === $b->depth) {
128
+			return $a->index < $b->index ? -1 : 1;
129
+		}
116 130
 
117 131
 		return ($a->depth < $b->depth) ? -1 : 1;
118 132
 	}
@@ -121,7 +135,9 @@  discard block
 block discarded – undo
121 135
 		$pos = 0;
122 136
 		while (($pos = strpos($str, $open, $pos)) !== false) {
123 137
 			$end = strpos($str, $close, $pos);
124
-			if ($end === false) break;
138
+			if ($end === false) {
139
+				break;
140
+			}
125 141
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
126 142
 		}
127 143
 
Please login to merge, or discard this patch.
src/Parser/Tokenizer.php 1 patch
Braces   +30 added lines, -12 removed lines patch added patch discarded remove patch
@@ -79,8 +79,11 @@  discard block
 block discarded – undo
79 79
 			$i += $this->doStrings($tokens, $char, $i);
80 80
 			$i += $this->doBrackets($tokens, $char, $i);
81 81
 		}
82
-		if ($returnObj) return new Tokens($tokens);
83
-		else return $tokens;
82
+		if ($returnObj) {
83
+			return new Tokens($tokens);
84
+		} else {
85
+			return $tokens;
86
+		}
84 87
 	}
85 88
 
86 89
 	private function doSimpleTokens(&$tokens, $char) {
@@ -117,10 +120,15 @@  discard block
 block discarded – undo
117 120
 	}
118 121
 
119 122
 	private function processLiterals(&$tokens, $name) {
120
-		if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name];
121
-		else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true];
122
-		else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false];
123
-		else $tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo];
123
+		if (is_numeric($name)) {
124
+			$tokens[] = ['type' => self::NUMERIC, 'value' => $name];
125
+		} else if ($name == 'true') {
126
+			$tokens[] = ['type' => self::BOOL, 'value' => true];
127
+		} else if ($name == 'false') {
128
+			$tokens[] = ['type' => self::BOOL, 'value' => false];
129
+		} else {
130
+			$tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo];
131
+		}
124 132
 	}
125 133
 
126 134
 	private function doBrackets(&$tokens, $char, $i) {
@@ -154,7 +162,9 @@  discard block
 block discarded – undo
154 162
 	private function extractString($pos) {
155 163
 		$char = $this->str[$pos];
156 164
 		$end = strpos($this->str, $char, $pos+1);
157
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
165
+		while ($end !== false && $this->str[$end-1] == '\\') {
166
+			$end = strpos($this->str, $char, $end+1);
167
+		}
158 168
 
159 169
 		return substr($this->str, $pos+1, $end-$pos-1);
160 170
 	}
@@ -163,18 +173,26 @@  discard block
 block discarded – undo
163 173
 		$close = strpos($this->str, $closeBracket, $open);
164 174
 
165 175
 		$cPos = $open+1;
166
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
176
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
177
+			$close = strpos($this->str, $closeBracket, $close+1);
178
+		}
167 179
 		return substr($this->str, $open+1, $close-$open-1);
168 180
 	}
169 181
 
170 182
 	private function identifyChar($chr) {
171
-		if (isset($this->chars[$chr])) return $this->chars[$chr];
172
-		else return self::NAME;
183
+		if (isset($this->chars[$chr])) {
184
+			return $this->chars[$chr];
185
+		} else {
186
+			return self::NAME;
187
+		}
173 188
 	}
174 189
 
175 190
 	private function getChar($num) {
176 191
 		$chars = array_reverse($this->chars);
177
-		if (isset($chars[$num])) return $chars[$num];
178
-		else return false;
192
+		if (isset($chars[$num])) {
193
+			return $chars[$num];
194
+		} else {
195
+			return false;
196
+		}
179 197
 	}
180 198
 }
Please login to merge, or discard this patch.