Completed
Push — master ( d365e4...a09952 )
by Tom
01:39
created
src/Parser/Tokenizer.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@
 block discarded – undo
144 144
 		if ($char === self::STRING) {
145 145
 			$string = $this->extractString($i);
146 146
 			$length = strlen($string)+1;
147
-			$string = str_replace('\\' . $this->str[$i], $this->str[$i], $string);
147
+			$string = str_replace('\\'.$this->str[$i], $this->str[$i], $string);
148 148
 			$tokens[] = ['type' => self::STRING, 'value' => $string, 'line' => $this->lineNo];
149 149
 			return $length;
150 150
 		}
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,8 +73,8 @@
 block discarded – undo
73 73
 		for ($i = 0; $i < strlen($this->str); $i++) {
74 74
 			$char = $this->identifyChar($this->str[$i]);
75 75
 
76
-            $i += $this->doSingleLineComments($tokens, $char, $i);
77
-            $i += $this->doMultiLineComments($tokens, $char, $i);
76
+			$i += $this->doSingleLineComments($tokens, $char, $i);
77
+			$i += $this->doMultiLineComments($tokens, $char, $i);
78 78
 
79 79
 			$this->doNewLine($tokens, $char);
80 80
 			$this->doSimpleTokens($tokens, $char);
Please login to merge, or discard this patch.
Braces   +38 added lines, -15 removed lines patch added patch discarded remove patch
@@ -83,22 +83,30 @@  discard block
 block discarded – undo
83 83
 			$i += $this->doBrackets($tokens, $char, $i);
84 84
 
85 85
 		}
86
-		if ($returnObj) return new Tokens($tokens);
87
-		else return $tokens;
86
+		if ($returnObj) {
87
+			return new Tokens($tokens);
88
+		} else {
89
+			return $tokens;
90
+		}
88 91
 	}
89 92
 
90 93
 	private function doSingleLineComments(&$tokens, $char, $i) {
91 94
 		if ($char == Tokenizer::DIVIDE && isset($this->str[$i+1]) && $this->identifyChar($this->str[$i+1]) == Tokenizer::DIVIDE) {
92 95
 			$pos = strpos($this->str, "\n", $i);
93
-			if ($pos && $i === 0) return $pos;
94
-			else if ($pos) return $pos-2;
96
+			if ($pos && $i === 0) {
97
+				return $pos;
98
+			} else if ($pos) {
99
+				return $pos-2;
100
+			}
95 101
 		}
96 102
 	}
97 103
 
98 104
 	private function doMultiLineComments(&$tokens, $char, $i) {
99 105
 		if ($char == Tokenizer::DIVIDE && isset($this->str[$i+1]) && $this->identifyChar($this->str[$i+1]) == Tokenizer::MULTIPLY) {
100 106
 			$pos = strpos($this->str, '*/', $i)+2;
101
-			if ($this->str[$pos] == "\n") $pos++;
107
+			if ($this->str[$pos] == "\n") {
108
+				$pos++;
109
+			}
102 110
 			return $pos ? $pos : 0;
103 111
 		}
104 112
 	}
@@ -137,10 +145,15 @@  discard block
 block discarded – undo
137 145
 	}
138 146
 
139 147
 	private function processLiterals(&$tokens, $name) {
140
-		if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name];
141
-		else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true];
142
-		else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false];
143
-		else $tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo];
148
+		if (is_numeric($name)) {
149
+			$tokens[] = ['type' => self::NUMERIC, 'value' => $name];
150
+		} else if ($name == 'true') {
151
+			$tokens[] = ['type' => self::BOOL, 'value' => true];
152
+		} else if ($name == 'false') {
153
+			$tokens[] = ['type' => self::BOOL, 'value' => false];
154
+		} else {
155
+			$tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo];
156
+		}
144 157
 	}
145 158
 
146 159
 	private function doBrackets(&$tokens, $char, $i) {
@@ -173,7 +186,9 @@  discard block
 block discarded – undo
173 186
 	private function extractString($pos) {
174 187
 		$char = $this->str[$pos];
175 188
 		$end = strpos($this->str, $char, $pos+1);
176
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
189
+		while ($end !== false && $this->str[$end-1] == '\\') {
190
+			$end = strpos($this->str, $char, $end+1);
191
+		}
177 192
 
178 193
 		return substr($this->str, $pos+1, $end-$pos-1);
179 194
 	}
@@ -182,18 +197,26 @@  discard block
 block discarded – undo
182 197
 		$close = strpos($this->str, $closeBracket, $open);
183 198
 
184 199
 		$cPos = $open+1;
185
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
200
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
201
+			$close = strpos($this->str, $closeBracket, $close+1);
202
+		}
186 203
 		return substr($this->str, $open+1, $close-$open-1);
187 204
 	}
188 205
 
189 206
 	private function identifyChar($chr) {
190
-		if (isset($this->chars[$chr])) return $this->chars[$chr];
191
-		else return self::NAME;
207
+		if (isset($this->chars[$chr])) {
208
+			return $this->chars[$chr];
209
+		} else {
210
+			return self::NAME;
211
+		}
192 212
 	}
193 213
 
194 214
 	private function getChar($num) {
195 215
 		$chars = array_reverse($this->chars);
196
-		if (isset($chars[$num])) return $chars[$num];
197
-		else return false;
216
+		if (isset($chars[$num])) {
217
+			return $chars[$num];
218
+		} else {
219
+			return false;
220
+		}
198 221
 	}
199 222
 }
Please login to merge, or discard this patch.