Completed
Push — master ( c7ae95...a264ad )
by Richard
03:01
created
src/TSSValidator.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -2,56 +2,56 @@
 block discarded – undo
2 2
 namespace Transphporm;
3 3
 use Transphporm\Parser\Tokenizer;
4 4
 class TSSValidator {
5
-    private $error;
5
+	private $error;
6 6
 
7
-    public function validate($tss) {
8
-        $this->error = null;
9
-        $tokens = $this->tokenize($tss);
7
+	public function validate($tss) {
8
+		$this->error = null;
9
+		$tokens = $this->tokenize($tss);
10 10
 
11
-        foreach ($tokens as $token)
12
-            if (!$this->validateRule($token)) return false;
11
+		foreach ($tokens as $token)
12
+			if (!$this->validateRule($token)) return false;
13 13
 
14
-        return true;
15
-    }
14
+		return true;
15
+	}
16 16
 
17
-    public function getLastError() {
18
-        return $this->error;
19
-    }
17
+	public function getLastError() {
18
+		return $this->error;
19
+	}
20 20
 
21
-    private function validateRule($token) {
22
-        if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
21
+	private function validateRule($token) {
22
+		if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
23 23
 
24
-        return $this->checkBraces($token) && $this->checkSemicolons($token)
25
-            && $this->checkParenthesis($token);
26
-    }
24
+		return $this->checkBraces($token) && $this->checkSemicolons($token)
25
+			&& $this->checkParenthesis($token);
26
+	}
27 27
 
28
-    private function checkBraces($token) {
29
-        return strpos($token['string'], '{') === false;
30
-    }
28
+	private function checkBraces($token) {
29
+		return strpos($token['string'], '{') === false;
30
+	}
31 31
 
32
-    private function checkSemicolons($braceToken) {
33
-        $prevSemicolon = true;
34
-        foreach ($braceToken['value'] as $token) {
35
-            if ($token['type'] === Tokenizer::SEMI_COLON) $prevSemicolon = true;
36
-            if ($token['type'] === Tokenizer::COLON && !$prevSemicolon) return false;
37
-            else if ($token['type'] === Tokenizer::COLON) $prevSemicolon = false;
38
-        }
39
-        return true;
40
-    }
32
+	private function checkSemicolons($braceToken) {
33
+		$prevSemicolon = true;
34
+		foreach ($braceToken['value'] as $token) {
35
+			if ($token['type'] === Tokenizer::SEMI_COLON) $prevSemicolon = true;
36
+			if ($token['type'] === Tokenizer::COLON && !$prevSemicolon) return false;
37
+			else if ($token['type'] === Tokenizer::COLON) $prevSemicolon = false;
38
+		}
39
+		return true;
40
+	}
41 41
 
42
-    private function checkParenthesis($token) {
43
-        return substr_count($token['string'], '(') === substr_count($token['string'], ')');
44
-    }
42
+	private function checkParenthesis($token) {
43
+		return substr_count($token['string'], '(') === substr_count($token['string'], ')');
44
+	}
45 45
 
46
-    private function tokenize($tss) {
47
-        if (is_file($tss)) $tss = file_get_contents($tss);
48
-        $tss = $this->stripComments($tss, '//', "\n");
46
+	private function tokenize($tss) {
47
+		if (is_file($tss)) $tss = file_get_contents($tss);
48
+		$tss = $this->stripComments($tss, '//', "\n");
49 49
 		$tss = $this->stripComments($tss, '/*', '*/');
50 50
 		$tokenizer = new Tokenizer($tss);
51 51
 		return $tokenizer->getTokens();
52
-    }
52
+	}
53 53
 
54
-    private function stripComments($str, $open, $close) {
54
+	private function stripComments($str, $open, $close) {
55 55
 		$pos = 0;
56 56
 		while (($pos = strpos($str, $open, $pos)) !== false) {
57 57
 			$end = strpos($str, $close, $pos);
Please login to merge, or discard this patch.
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -8,8 +8,9 @@  discard block
 block discarded – undo
8 8
         $this->error = null;
9 9
         $tokens = $this->tokenize($tss);
10 10
 
11
-        foreach ($tokens as $token)
12
-            if (!$this->validateRule($token)) return false;
11
+        foreach ($tokens as $token) {
12
+                    if (!$this->validateRule($token)) return false;
13
+        }
13 14
 
14 15
         return true;
15 16
     }
@@ -19,7 +20,9 @@  discard block
 block discarded – undo
19 20
     }
20 21
 
21 22
     private function validateRule($token) {
22
-        if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
23
+        if ($token['type'] !== Tokenizer::OPEN_BRACE) {
24
+        	return true;
25
+        }
23 26
 
24 27
         return $this->checkBraces($token) && $this->checkSemicolons($token)
25 28
             && $this->checkParenthesis($token);
@@ -32,9 +35,14 @@  discard block
 block discarded – undo
32 35
     private function checkSemicolons($braceToken) {
33 36
         $prevSemicolon = true;
34 37
         foreach ($braceToken['value'] as $token) {
35
-            if ($token['type'] === Tokenizer::SEMI_COLON) $prevSemicolon = true;
36
-            if ($token['type'] === Tokenizer::COLON && !$prevSemicolon) return false;
37
-            else if ($token['type'] === Tokenizer::COLON) $prevSemicolon = false;
38
+            if ($token['type'] === Tokenizer::SEMI_COLON) {
39
+            	$prevSemicolon = true;
40
+            }
41
+            if ($token['type'] === Tokenizer::COLON && !$prevSemicolon) {
42
+            	return false;
43
+            } else if ($token['type'] === Tokenizer::COLON) {
44
+            	$prevSemicolon = false;
45
+            }
38 46
         }
39 47
         return true;
40 48
     }
@@ -44,7 +52,9 @@  discard block
 block discarded – undo
44 52
     }
45 53
 
46 54
     private function tokenize($tss) {
47
-        if (is_file($tss)) $tss = file_get_contents($tss);
55
+        if (is_file($tss)) {
56
+        	$tss = file_get_contents($tss);
57
+        }
48 58
         $tss = $this->stripComments($tss, '//', "\n");
49 59
 		$tss = $this->stripComments($tss, '/*', '*/');
50 60
 		$tokenizer = new Tokenizer($tss);
@@ -55,7 +65,9 @@  discard block
 block discarded – undo
55 65
 		$pos = 0;
56 66
 		while (($pos = strpos($str, $open, $pos)) !== false) {
57 67
 			$end = strpos($str, $close, $pos);
58
-			if ($end === false) break;
68
+			if ($end === false) {
69
+				break;
70
+			}
59 71
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
60 72
 		}
61 73
 
Please login to merge, or discard this patch.