Completed
Push — master ( 7023df...5e8065 )
by Tom
01:30
created
src/Parser/Tokenizer/TokenizedString.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
 	}
56 56
 
57 57
 	public function read($offset = 0) {
58
-		return $this->str[$this->pos + $offset];
58
+		return $this->str[$this->pos+$offset];
59 59
 	}
60 60
 
61 61
 	public function identifyChar($offset = 0) {
62
-		$chr = $this->str[$this->pos + $offset];
62
+		$chr = $this->str[$this->pos+$offset];
63 63
 		if (!empty($this->chars[$chr])) return $this->chars[$chr];
64 64
 		else return Tokenizer::NAME;
65 65
 	}
66 66
 
67 67
 	public function has($offset = 0) {
68
-		return isset($this->str[$this->pos + $offset]);
68
+		return isset($this->str[$this->pos+$offset]);
69 69
 	}
70 70
 
71 71
 	public function pos($str) {
72
-		$pos = strpos($this->str,  $str, $this->pos);
72
+		$pos = strpos($this->str, $str, $this->pos);
73 73
 		return $pos ? $pos-$this->pos : false;
74 74
 	}
75 75
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	}
83 83
 
84 84
 	public function extractString($offset = 0) {
85
-		$pos = $this->pos + $offset;
85
+		$pos = $this->pos+$offset;
86 86
 		$char = $this->str[$pos];
87 87
 		$end = strpos($this->str, $char, $pos+1);
88 88
 		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
Please login to merge, or discard this patch.
Braces   +16 added lines, -6 removed lines patch added patch discarded remove patch
@@ -40,8 +40,11 @@  discard block
 block discarded – undo
40 40
 	}
41 41
 
42 42
 	public function move($n) {
43
-		if ($n === false) $this->pos = strlen($this->str)-1;
44
-		else $this->pos += $n;
43
+		if ($n === false) {
44
+			$this->pos = strlen($this->str)-1;
45
+		} else {
46
+			$this->pos += $n;
47
+		}
45 48
 	}
46 49
 
47 50
 	public function next() {
@@ -60,8 +63,11 @@  discard block
 block discarded – undo
60 63
 
61 64
 	public function identifyChar($offset = 0) {
62 65
 		$chr = $this->str[$this->pos + $offset];
63
-		if (!empty($this->chars[$chr])) return $this->chars[$chr];
64
-		else return Tokenizer::NAME;
66
+		if (!empty($this->chars[$chr])) {
67
+			return $this->chars[$chr];
68
+		} else {
69
+			return Tokenizer::NAME;
70
+		}
65 71
 	}
66 72
 
67 73
 	public function has($offset = 0) {
@@ -85,7 +91,9 @@  discard block
 block discarded – undo
85 91
 		$pos = $this->pos + $offset;
86 92
 		$char = $this->str[$pos];
87 93
 		$end = strpos($this->str, $char, $pos+1);
88
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
94
+		while ($end !== false && $this->str[$end-1] == '\\') {
95
+			$end = strpos($this->str, $char, $end+1);
96
+		}
89 97
 
90 98
 		return substr($this->str, $pos+1, $end-$pos-1);
91 99
 	}
@@ -95,7 +103,9 @@  discard block
 block discarded – undo
95 103
 		$close = strpos($this->str, $closeBracket, $open);
96 104
 
97 105
 		$cPos = $open+1;
98
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
106
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
107
+			$close = strpos($this->str, $closeBracket, $close+1);
108
+		}
99 109
 		return substr($this->str, $open+1, $close-$open-1);
100 110
 	}
101 111
 
Please login to merge, or discard this patch.
src/Parser/Tokenizer/Strings.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 			$chr = $str->read();
11 11
 			$string = $str->extractString();
12 12
 			$length = strlen($string)+1;
13
-			$string = str_replace('\\' . $chr, $chr, $string);
13
+			$string = str_replace('\\'.$chr, $chr, $string);
14 14
 			$tokens->add(['type' => Tokenizer::STRING, 'value' => $string, 'line' => $str->lineNo()]);
15 15
 			$str->move($length);
16 16
 		}
Please login to merge, or discard this patch.
src/Parser/CssToXpath.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
 		$this->functionSet = $functionSet;
20 20
 
21 21
 		$this->translators = [
22
-			Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string;	},
23
-			Tokenizer::MULTIPLY => function () { return '*'; },
24
-			'' => function($string) use ($prefix) { return '/' . $prefix . $string;	},
25
-			Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix  . $string; },
26
-			Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; },
27
-			Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; },
28
-			Tokenizer::OPEN_SQUARE_BRACKET => function($string) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' .  $this->id . '")' . ']';	}
22
+			Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; },
23
+			Tokenizer::MULTIPLY => function() { return '*'; },
24
+			'' => function($string) use ($prefix) { return '/'.$prefix.$string; },
25
+			Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; },
26
+			Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; },
27
+			Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; },
28
+			Tokenizer::OPEN_SQUARE_BRACKET => function($string) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$this->id.'")'.']'; }
29 29
 		];
30 30
 	}
31 31
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		$functionSet->setElement($element[0]);
45 45
 
46 46
 		$attributes = [];
47
-		foreach($element[0]->attributes as $name => $node) {
47
+		foreach ($element[0]->attributes as $name => $node) {
48 48
 			$attributes[$name] = $node->nodeValue;
49 49
 		}
50 50
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -69,7 +69,9 @@  discard block
 block discarded – undo
69 69
 				$selector->type = $token['type'];
70 70
 				$selectors[] = $selector;
71 71
 			}
72
-			if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value'];
72
+			if (isset($token['value'])) {
73
+				$selectors[count($selectors)-1]->string = $token['value'];
74
+			}
73 75
 		}
74 76
 		return $selectors;
75 77
 	}
@@ -79,7 +81,9 @@  discard block
 block discarded – undo
79 81
 		$selectors = $this->split($css);
80 82
 		$xpath = '/';
81 83
 		foreach ($selectors as $selector) {
82
-			if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath);
84
+			if (isset($this->translators[$selector->type])) {
85
+				$xpath .= $this->translators[$selector->type]($selector->string, $xpath);
86
+			}
83 87
 		}
84 88
 
85 89
 		$xpath = str_replace('/[', '/*[', $xpath);
@@ -92,11 +96,15 @@  discard block
 block discarded – undo
92 96
 		$split = $css->splitOnToken(Tokenizer::GREATER_THAN);
93 97
 		$numSplits = count($split);
94 98
 
95
-		if ($numSplits <= 1) return $css;
99
+		if ($numSplits <= 1) {
100
+			return $css;
101
+		}
96 102
 
97 103
 		for ($i = 0; $i < $numSplits; $i++) {
98 104
 			$tokens->add($split[$i]->trim());
99
-			if (isset($split[$i+1])) $tokens->add(['type' => Tokenizer::GREATER_THAN]);
105
+			if (isset($split[$i+1])) {
106
+				$tokens->add(['type' => Tokenizer::GREATER_THAN]);
107
+			}
100 108
 		}
101 109
 
102 110
 		return $tokens;
Please login to merge, or discard this patch.
src/Property/ContentPseudo/BeforeAfter.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -4,6 +4,9 @@
 block discarded – undo
4 4
 	private $insertLocation;
5 5
 	private $content;
6 6
 
7
+	/**
8
+	 * @param string $insertLocation
9
+	 */
7 10
 	public function __construct($insertLocation, \Transphporm\Property\Content $content) {
8 11
 		$this->insertLocation = $insertLocation;
9 12
 		$this->content = $content;
Please login to merge, or discard this patch.
src/Property/ContentPseudo/Attr.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@
 block discarded – undo
5 5
 		$implodedValue = implode('', $value);
6 6
 
7 7
 		if ($pseudoMatcher->hasFunction('before')) {
8
-			$attrValue = $implodedValue . $element->getAttribute($pseudoArgs);
8
+			$attrValue = $implodedValue.$element->getAttribute($pseudoArgs);
9 9
 		}
10 10
 		else if ($pseudoMatcher->hasFunction('after')) {
11
-			$attrValue = $element->getAttribute($pseudoArgs) . $implodedValue;
11
+			$attrValue = $element->getAttribute($pseudoArgs).$implodedValue;
12 12
 		}
13 13
 		else {
14 14
 			$attrValue = implode('', $value);
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,11 +6,9 @@
 block discarded – undo
6 6
 
7 7
 		if ($pseudoMatcher->hasFunction('before')) {
8 8
 			$attrValue = $implodedValue . $element->getAttribute($pseudoArgs);
9
-		}
10
-		else if ($pseudoMatcher->hasFunction('after')) {
9
+		} else if ($pseudoMatcher->hasFunction('after')) {
11 10
 			$attrValue = $element->getAttribute($pseudoArgs) . $implodedValue;
12
-		}
13
-		else {
11
+		} else {
14 12
 			$attrValue = implode('', $value);
15 13
 		}
16 14
 
Please login to merge, or discard this patch.
src/Property/ContentPseudo.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,5 +2,5 @@
 block discarded – undo
2 2
 namespace Transphporm\Property;
3 3
 
4 4
 interface ContentPseudo {
5
-    public function run($value, $pseudoArgs, $element, \Transphporm\Hook\PseudoMatcher $pseudoMatcher);
5
+	public function run($value, $pseudoArgs, $element, \Transphporm\Hook\PseudoMatcher $pseudoMatcher);
6 6
 }
Please login to merge, or discard this patch.
src/RunException.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@
 block discarded – undo
6 6
  * @version         1.2                                                             */
7 7
 namespace Transphporm;
8 8
 class RunException extends \Exception {
9
-    public function __construct($operationType, $operationName, \Exception $previous = null) {
10
-        $message = 'TSS Error: Problem carrying out ' . $operationType . ' "' . $operationName . '"';
9
+	public function __construct($operationType, $operationName, \Exception $previous = null) {
10
+		$message = 'TSS Error: Problem carrying out ' . $operationType . ' "' . $operationName . '"';
11 11
 
12
-        parent::__construct($message, 0, $previous);
13
-    }
12
+		parent::__construct($message, 0, $previous);
13
+	}
14 14
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 namespace Transphporm;
8 8
 class RunException extends \Exception {
9 9
     public function __construct($operationType, $operationName, \Exception $previous = null) {
10
-        $message = 'TSS Error: Problem carrying out ' . $operationType . ' "' . $operationName . '"';
10
+        $message = 'TSS Error: Problem carrying out '.$operationType.' "'.$operationName.'"';
11 11
 
12 12
         parent::__construct($message, 0, $previous);
13 13
     }
Please login to merge, or discard this patch.
src/TSSValidator.php 2 patches
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,14 +13,17 @@  discard block
 block discarded – undo
13 13
         $this->error = null;
14 14
         $tokens = $this->tokenize($tss);
15 15
 
16
-        foreach ($tokens as $token)
17
-            if (!$this->validateRule($token)) return false;
16
+        foreach ($tokens as $token) {
17
+                    if (!$this->validateRule($token)) return false;
18
+        }
18 19
 
19 20
         return true;
20 21
     }
21 22
 
22 23
     private function validateRule($token) {
23
-        if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
24
+        if ($token['type'] !== Tokenizer::OPEN_BRACE) {
25
+        	return true;
26
+        }
24 27
 
25 28
         return $this->checkBraces($token) && $this->checkSemicolons($token)
26 29
             && $this->checkParenthesis($token);
@@ -33,8 +36,9 @@  discard block
 block discarded – undo
33 36
     private function checkSemicolons($braceToken) {
34 37
         $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
35 38
         array_shift($splitTokens); array_pop($splitTokens);
36
-        foreach ($splitTokens as $tokens)
37
-            if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
39
+        foreach ($splitTokens as $tokens) {
40
+                    if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
41
+        }
38 42
 
39 43
         return true;
40 44
     }
@@ -44,7 +48,9 @@  discard block
 block discarded – undo
44 48
     }
45 49
 
46 50
     private function tokenize($tss) {
47
-        if (is_file($tss)) $tss = file_get_contents($tss);
51
+        if (is_file($tss)) {
52
+        	$tss = file_get_contents($tss);
53
+        }
48 54
         return (new Parser\Tokenizer($tss))->getTokens();
49 55
     }
50 56
 }
Please login to merge, or discard this patch.
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -7,44 +7,44 @@
 block discarded – undo
7 7
 namespace Transphporm;
8 8
 use Transphporm\Parser\Tokenizer;
9 9
 class TSSValidator {
10
-    private $error;
10
+	private $error;
11 11
 
12
-    public function validate($tss) {
13
-        $this->error = null;
14
-        $tokens = $this->tokenize($tss);
12
+	public function validate($tss) {
13
+		$this->error = null;
14
+		$tokens = $this->tokenize($tss);
15 15
 
16
-        foreach ($tokens as $token)
17
-            if (!$this->validateRule($token)) return false;
16
+		foreach ($tokens as $token)
17
+			if (!$this->validateRule($token)) return false;
18 18
 
19
-        return true;
20
-    }
19
+		return true;
20
+	}
21 21
 
22
-    private function validateRule($token) {
23
-        if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
22
+	private function validateRule($token) {
23
+		if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;
24 24
 
25
-        return $this->checkBraces($token) && $this->checkSemicolons($token)
26
-            && $this->checkParenthesis($token);
27
-    }
25
+		return $this->checkBraces($token) && $this->checkSemicolons($token)
26
+			&& $this->checkParenthesis($token);
27
+	}
28 28
 
29
-    private function checkBraces($token) {
30
-        return strpos($token['string'], '{') === false;
31
-    }
29
+	private function checkBraces($token) {
30
+		return strpos($token['string'], '{') === false;
31
+	}
32 32
 
33
-    private function checkSemicolons($braceToken) {
34
-        $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
35
-        array_shift($splitTokens); array_pop($splitTokens);
36
-        foreach ($splitTokens as $tokens)
37
-            if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
33
+	private function checkSemicolons($braceToken) {
34
+		$splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);
35
+		array_shift($splitTokens); array_pop($splitTokens);
36
+		foreach ($splitTokens as $tokens)
37
+			if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;
38 38
 
39
-        return true;
40
-    }
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
-        return (new Parser\Tokenizer($tss))->getTokens();
49
-    }
46
+	private function tokenize($tss) {
47
+		if (is_file($tss)) $tss = file_get_contents($tss);
48
+		return (new Parser\Tokenizer($tss))->getTokens();
49
+	}
50 50
 }
Please login to merge, or discard this patch.
src/FilePath.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,15 +19,15 @@
 block discarded – undo
19 19
 
20 20
 	public function getFilePath($filePath) {
21 21
 		if (is_file($filePath)) return $filePath;
22
-		else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
22
+		else if (is_file($this->baseDir.DIRECTORY_SEPARATOR.$filePath)) return $this->baseDir.DIRECTORY_SEPARATOR.$filePath;
23 23
 		else return $this->loadFromPaths($filePath);
24 24
 	}
25 25
 
26 26
 	private function loadFromPaths($filePath) {
27 27
 		foreach ($this->paths as $path) {
28
-			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
28
+			if (is_file($path.DIRECTORY_SEPARATOR.$filePath)) return $path.DIRECTORY_SEPARATOR.$filePath;
29 29
 		}
30 30
 
31
-		throw new \Exception('File ' . $filePath . ' not found in paths (' . implode(', ', $this->paths) . ')');
31
+		throw new \Exception('File '.$filePath.' not found in paths ('.implode(', ', $this->paths).')');
32 32
 	}
33 33
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,14 +18,20 @@
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function getFilePath($filePath) {
21
-		if (is_file($filePath)) return $filePath;
22
-		else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
23
-		else return $this->loadFromPaths($filePath);
21
+		if (is_file($filePath)) {
22
+			return $filePath;
23
+		} else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) {
24
+			return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
25
+		} else {
26
+			return $this->loadFromPaths($filePath);
27
+		}
24 28
 	}
25 29
 
26 30
 	private function loadFromPaths($filePath) {
27 31
 		foreach ($this->paths as $path) {
28
-			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
32
+			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) {
33
+				return $path . DIRECTORY_SEPARATOR . $filePath;
34
+			}
29 35
 		}
30 36
 
31 37
 		throw new \Exception('File ' . $filePath . ' not found in paths (' . implode(', ', $this->paths) . ')');
Please login to merge, or discard this patch.