Completed
Push — master ( a264ad...237dc5 )
by Richard
02:18
created
src/TSSValidator.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,55 +2,55 @@
 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
-        $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
34
-        array_shift($splitTokens); array_pop($splitTokens);
35
-        foreach ($splitTokens as $tokens)
36
-            if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
32
+	private function checkSemicolons($braceToken) {
33
+		$splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
34
+		array_shift($splitTokens); array_pop($splitTokens);
35
+		foreach ($splitTokens as $tokens)
36
+			if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
37 37
 
38
-        return true;
39
-    }
38
+		return true;
39
+	}
40 40
 
41
-    private function checkParenthesis($token) {
42
-        return substr_count($token['string'], '(') === substr_count($token['string'], ')');
43
-    }
41
+	private function checkParenthesis($token) {
42
+		return substr_count($token['string'], '(') === substr_count($token['string'], ')');
43
+	}
44 44
 
45
-    private function tokenize($tss) {
46
-        if (is_file($tss)) $tss = file_get_contents($tss);
47
-        $tss = $this->stripComments($tss, '//', "\n");
45
+	private function tokenize($tss) {
46
+		if (is_file($tss)) $tss = file_get_contents($tss);
47
+		$tss = $this->stripComments($tss, '//', "\n");
48 48
 		$tss = $this->stripComments($tss, '/*', '*/');
49 49
 		$tokenizer = new Tokenizer($tss);
50 50
 		return $tokenizer->getTokens();
51
-    }
51
+	}
52 52
 
53
-    private function stripComments($str, $open, $close) {
53
+	private function stripComments($str, $open, $close) {
54 54
 		$pos = 0;
55 55
 		while (($pos = strpos($str, $open, $pos)) !== false) {
56 56
 			$end = strpos($str, $close, $pos);
Please login to merge, or discard this patch.
Braces   +15 added lines, -7 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,8 +35,9 @@  discard block
 block discarded – undo
32 35
     private function checkSemicolons($braceToken) {
33 36
         $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
34 37
         array_shift($splitTokens); array_pop($splitTokens);
35
-        foreach ($splitTokens as $tokens)
36
-            if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
38
+        foreach ($splitTokens as $tokens) {
39
+                    if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
40
+        }
37 41
 
38 42
         return true;
39 43
     }
@@ -43,7 +47,9 @@  discard block
 block discarded – undo
43 47
     }
44 48
 
45 49
     private function tokenize($tss) {
46
-        if (is_file($tss)) $tss = file_get_contents($tss);
50
+        if (is_file($tss)) {
51
+        	$tss = file_get_contents($tss);
52
+        }
47 53
         $tss = $this->stripComments($tss, '//', "\n");
48 54
 		$tss = $this->stripComments($tss, '/*', '*/');
49 55
 		$tokenizer = new Tokenizer($tss);
@@ -54,7 +60,9 @@  discard block
 block discarded – undo
54 60
 		$pos = 0;
55 61
 		while (($pos = strpos($str, $open, $pos)) !== false) {
56 62
 			$end = strpos($str, $close, $pos);
57
-			if ($end === false) break;
63
+			if ($end === false) {
64
+				break;
65
+			}
58 66
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
59 67
 		}
60 68
 
Please login to merge, or discard this patch.