Completed
Push — master ( 2fb808...7b88cf )
by Richard
02:59
created
src/Parser/CssToXpath.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@
 block discarded – undo
49 49
 		$functionSet->setElement($element[0]);
50 50
 
51 51
 		$attributes = array();
52
-        foreach($element[0]->attributes as $attribute_name => $attribute_node) {
53
-            $attributes[$attribute_name] = $attribute_node->nodeValue;
54
-        }
52
+		foreach($element[0]->attributes as $attribute_name => $attribute_node) {
53
+			$attributes[$attribute_name] = $attribute_node->nodeValue;
54
+		}
55 55
 
56
-        $parser = new \Transphporm\Parser\Value($functionSet, true);
56
+		$parser = new \Transphporm\Parser\Value($functionSet, true);
57 57
 		$return = $parser->parseTokens($attr, $attributes);
58 58
 
59 59
 		return $return[0] === '' ? false : $return[0];
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -19,12 +19,12 @@  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
-			'' => function($string) use ($prefix) { return '/' . $prefix . $string;	},
24
-			Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix  . $string; },
25
-			Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; },
26
-			Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; },
27
-			Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . json_encode($string) . '\', ., "' . $hash . '")' . ']';	}
22
+			Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; },
23
+			'' => function($string) use ($prefix) { return '/'.$prefix.$string; },
24
+			Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; },
25
+			Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; },
26
+			Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; },
27
+			Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.json_encode($string).'\', ., "'.$hash.'")'.']'; }
28 28
 		];
29 29
 	}
30 30
 
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		$functionSet->setElement($element[0]);
50 50
 
51 51
 		$attributes = array();
52
-        foreach($element[0]->attributes as $attribute_name => $attribute_node) {
52
+        foreach ($element[0]->attributes as $attribute_name => $attribute_node) {
53 53
             $attributes[$attribute_name] = $attribute_node->nodeValue;
54 54
         }
55 55
 
Please login to merge, or discard this patch.
Braces   +17 added lines, -7 removed lines patch added patch discarded remove patch
@@ -63,8 +63,11 @@  discard block
 block discarded – undo
63 63
 		$splitTokens = [];
64 64
 		$i = 0;
65 65
 		foreach ($tokens as $token) {
66
-			if ($token['type'] === $splitOn) $i++;
67
-			else $splitTokens[$i][] = $token;
66
+			if ($token['type'] === $splitOn) {
67
+				$i++;
68
+			} else {
69
+				$splitTokens[$i][] = $token;
70
+			}
68 71
 		}
69 72
 		return $splitTokens;
70 73
 	}
@@ -81,7 +84,9 @@  discard block
 block discarded – undo
81 84
 				$selector->type = $token['type'];
82 85
 				$selectors[] = $selector;
83 86
 			}
84
-			if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value'];
87
+			if (isset($token['value'])) {
88
+				$selectors[count($selectors)-1]->string = $token['value'];
89
+			}
85 90
 		}
86 91
 		return $selectors;
87 92
 	}
@@ -89,15 +94,20 @@  discard block
 block discarded – undo
89 94
 	public function getXpath($css) {
90 95
 		foreach ($css as $key => $token) {
91 96
 			if ($token['type'] === Tokenizer::WHITESPACE &&
92
-				(isset($css[$key+1]) && $css[$key+1]['type'] === Tokenizer::GREATER_THAN)) unset($css[$key]);
93
-			else if ($token['type'] === Tokenizer::WHITESPACE &&
94
-				(isset($css[$key-1]) && $css[$key-1]['type'] === Tokenizer::GREATER_THAN)) unset($css[$key]);
97
+				(isset($css[$key+1]) && $css[$key+1]['type'] === Tokenizer::GREATER_THAN)) {
98
+				unset($css[$key]);
99
+			} else if ($token['type'] === Tokenizer::WHITESPACE &&
100
+				(isset($css[$key-1]) && $css[$key-1]['type'] === Tokenizer::GREATER_THAN)) {
101
+				unset($css[$key]);
102
+			}
95 103
 		}
96 104
 		$css = $this->splitOnToken(array_values($css), Tokenizer::COLON)[0];
97 105
 		$selectors = $this->split($css);
98 106
 		$xpath = '/';
99 107
 		foreach ($selectors as $selector) {
100
-			if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath);
108
+			if (isset($this->translators[$selector->type])) {
109
+				$xpath .= $this->translators[$selector->type]($selector->string, $xpath);
110
+			}
101 111
 		}
102 112
 
103 113
 		$xpath = str_replace('/[', '/*[', $xpath);
Please login to merge, or discard this patch.