@@ -16,7 +16,9 @@ discard block |
||
16 | 16 | } |
17 | 17 | |
18 | 18 | public function match($name, $args, \DomElement $element) { |
19 | - if ($name !== 'not') return true; |
|
19 | + if ($name !== 'not') { |
|
20 | + return true; |
|
21 | + } |
|
20 | 22 | |
21 | 23 | $xpath = new \DomXpath($element->ownerDocument); |
22 | 24 | return $this->notElement($args, $xpath, $element); |
@@ -29,7 +31,9 @@ discard block |
||
29 | 31 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
30 | 32 | foreach ($xpath->query($xpathString) as $matchedElement) { |
31 | 33 | //Check to see whether this node was matched by the not query |
32 | - if ($element->isSameNode($matchedElement)) return false; |
|
34 | + if ($element->isSameNode($matchedElement)) { |
|
35 | + return false; |
|
36 | + } |
|
33 | 37 | } |
34 | 38 | } |
35 | 39 | return true; |
@@ -14,7 +14,9 @@ |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function match($name, $args, \DomElement $element) { |
17 | - if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) return true; |
|
17 | + if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) { |
|
18 | + return true; |
|
19 | + } |
|
18 | 20 | return $args[0]; |
19 | 21 | } |
20 | 22 | } |
@@ -28,6 +28,9 @@ discard block |
||
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | + /** |
|
32 | + * @param \DOMElement $element |
|
33 | + */ |
|
31 | 34 | private function shouldRun($element) { |
32 | 35 | do { |
33 | 36 | if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
@@ -40,6 +43,10 @@ discard block |
||
40 | 43 | return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append'; |
41 | 44 | } |
42 | 45 | |
46 | + /** |
|
47 | + * @param \DOMElement $element |
|
48 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
49 | + */ |
|
43 | 50 | private function processPseudo($value, $element, $pseudoMatcher) { |
44 | 51 | $pseudoContent = ['attr', 'header', 'before', 'after']; |
45 | 52 | foreach ($pseudoContent as $pseudo) { |
@@ -96,6 +103,9 @@ discard block |
||
96 | 103 | } |
97 | 104 | } |
98 | 105 | |
106 | + /** |
|
107 | + * @param \DOMElement $element |
|
108 | + */ |
|
99 | 109 | private function replaceContent($element, $content) { |
100 | 110 | //If this rule was cached, the elements that were added last time need to be removed prior to running the rule again. |
101 | 111 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
@@ -104,12 +114,18 @@ discard block |
||
104 | 114 | $element->setAttribute('transphporm', 'remove'); |
105 | 115 | } |
106 | 116 | |
117 | + /** |
|
118 | + * @param \DOMElement $element |
|
119 | + */ |
|
107 | 120 | private function appendContent($element, $content) { |
108 | 121 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
109 | 122 | $element->appendChild($node); |
110 | 123 | } |
111 | 124 | } |
112 | 125 | |
126 | + /** |
|
127 | + * @param \DOMElement $element |
|
128 | + */ |
|
113 | 129 | private function removeAllChildren($element) { |
114 | 130 | while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
115 | 131 | } |
@@ -16,21 +16,28 @@ discard block |
||
16 | 16 | } |
17 | 17 | |
18 | 18 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
19 | - if (!$this->shouldRun($element)) return false; |
|
19 | + if (!$this->shouldRun($element)) { |
|
20 | + return false; |
|
21 | + } |
|
20 | 22 | $values = $this->formatter->format($values, $rules); |
21 | 23 | |
22 | 24 | if (!$this->processPseudo($values, $element, $pseudoMatcher)) { |
23 | 25 | //Remove the current contents |
24 | 26 | $this->removeAllChildren($element); |
25 | 27 | //Now make a text node |
26 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
27 | - else $this->appendContent($element, $values); |
|
28 | + if ($this->getContentMode($rules) === 'replace') { |
|
29 | + $this->replaceContent($element, $values); |
|
30 | + } else { |
|
31 | + $this->appendContent($element, $values); |
|
32 | + } |
|
28 | 33 | } |
29 | 34 | } |
30 | 35 | |
31 | 36 | private function shouldRun($element) { |
32 | 37 | do { |
33 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
38 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
39 | + return false; |
|
40 | + } |
|
34 | 41 | } |
35 | 42 | while (($element = $element->parentNode) instanceof \DomElement); |
36 | 43 | return true; |
@@ -54,16 +61,18 @@ discard block |
||
54 | 61 | private function getNode($node, $document) { |
55 | 62 | foreach ($node as $n) { |
56 | 63 | if (is_array($n)) { |
57 | - foreach ($this->getNode($n, $document) as $new) yield $new; |
|
58 | - } |
|
59 | - else { |
|
64 | + foreach ($this->getNode($n, $document) as $new) { |
|
65 | + yield $new; |
|
66 | + } |
|
67 | + } else { |
|
60 | 68 | if ($n instanceof \DomElement) { |
61 | 69 | $new = $document->importNode($n, true); |
62 | 70 | //Removing this might cause problems with caching... |
63 | 71 | //$new->setAttribute('transphporm', 'added'); |
64 | - } |
|
65 | - else { |
|
66 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
72 | + } else { |
|
73 | + if ($n instanceof \DomText) { |
|
74 | + $n = $n->nodeValue; |
|
75 | + } |
|
67 | 76 | $new = $document->createElement('text'); |
68 | 77 | |
69 | 78 | $new->appendChild($document->createTextNode($n)); |
@@ -111,6 +120,8 @@ discard block |
||
111 | 120 | } |
112 | 121 | |
113 | 122 | private function removeAllChildren($element) { |
114 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
123 | + while ($element->hasChildNodes()) { |
|
124 | + $element->removeChild($element->firstChild); |
|
125 | + } |
|
115 | 126 | } |
116 | 127 | } |
@@ -39,27 +39,35 @@ |
||
39 | 39 | $parts['name'] = $this->getFuncName($tokens); |
40 | 40 | if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) { |
41 | 41 | $parts['args'] = $this->valueParser->parseTokens($tokens); |
42 | + } elseif (isset($tokens[1])) { |
|
43 | + $parts['args'] = $this->valueParser->parseTokens($tokens[1]['value']); |
|
44 | + } else { |
|
45 | + $parts['args'] = [['']]; |
|
42 | 46 | } |
43 | - elseif (isset($tokens[1])) $parts['args'] = $this->valueParser->parseTokens($tokens[1]['value']); |
|
44 | - else $parts['args'] = [['']]; |
|
45 | 47 | return $parts; |
46 | 48 | } |
47 | 49 | |
48 | 50 | private function getFuncName($tokens) { |
49 | - if ($tokens[0]['type'] === Tokenizer::NAME) return $tokens[0]['value']; |
|
51 | + if ($tokens[0]['type'] === Tokenizer::NAME) { |
|
52 | + return $tokens[0]['value']; |
|
53 | + } |
|
50 | 54 | return null; |
51 | 55 | } |
52 | 56 | |
53 | 57 | public function hasFunction($name) { |
54 | 58 | foreach ($this->pseudo as $tokens) { |
55 | - if ($name === $this->getFuncName($tokens)) return true; |
|
59 | + if ($name === $this->getFuncName($tokens)) { |
|
60 | + return true; |
|
61 | + } |
|
56 | 62 | } |
57 | 63 | } |
58 | 64 | |
59 | 65 | public function getFuncArgs($name) { |
60 | 66 | foreach ($this->pseudo as $tokens) { |
61 | 67 | $parts = $this->getFuncParts($tokens); |
62 | - if ($name === $parts['name']) return $parts['args']; |
|
68 | + if ($name === $parts['name']) { |
|
69 | + return $parts['args']; |
|
70 | + } |
|
63 | 71 | } |
64 | 72 | } |
65 | 73 | } |
@@ -50,10 +50,14 @@ discard block |
||
50 | 50 | $this->data = new ValueData($data ? $data : $this->baseData); |
51 | 51 | $this->last = null; |
52 | 52 | |
53 | - if (empty($tokens)) return [$data]; |
|
53 | + if (empty($tokens)) { |
|
54 | + return [$data]; |
|
55 | + } |
|
54 | 56 | |
55 | 57 | foreach ($tokens as $token) { |
56 | - if ($token['type'] !== Tokenizer::WHITESPACE) $this->{$this->tokenFuncs[$token['type']]}($token); |
|
58 | + if ($token['type'] !== Tokenizer::WHITESPACE) { |
|
59 | + $this->{$this->tokenFuncs[$token['type']]}($token); |
|
60 | + } |
|
57 | 61 | } |
58 | 62 | |
59 | 63 | $this->processLast(); |
@@ -72,13 +76,15 @@ discard block |
||
72 | 76 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
73 | 77 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
74 | 78 | private function processDot($token) { |
75 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
76 | - else { |
|
79 | + if ($this->last !== null) { |
|
80 | + $this->data->traverse($this->last); |
|
81 | + } else { |
|
77 | 82 | //When . is not preceeded by anything, treat it as part of the string instead of an operator |
78 | 83 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
79 | 84 | $lastResult = $this->result->pop(); |
80 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
81 | - else { |
|
85 | + if ($lastResult) { |
|
86 | + $this->data = new ValueData($lastResult); |
|
87 | + } else { |
|
82 | 88 | $this->processString(['value' => '.']); |
83 | 89 | $this->result->setMode(Tokenizer::CONCAT); |
84 | 90 | } |
@@ -91,9 +97,10 @@ discard block |
||
91 | 97 | $parser = new Value($this->baseData, $this->autoLookup); |
92 | 98 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
93 | 99 | $this->callTransphpormFunctions($token); |
94 | - } |
|
95 | - else { |
|
96 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
100 | + } else { |
|
101 | + if ($this->last !== null) { |
|
102 | + $this->data->traverse($this->last); |
|
103 | + } |
|
97 | 104 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
98 | 105 | } |
99 | 106 | } |
@@ -113,8 +120,7 @@ discard block |
||
113 | 120 | private function processBrackets($token) { |
114 | 121 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
115 | 122 | $this->callTransphpormFunctions($token); |
116 | - } |
|
117 | - else { |
|
123 | + } else { |
|
118 | 124 | $this->processNested($token); |
119 | 125 | } |
120 | 126 | } |
@@ -131,7 +137,9 @@ discard block |
||
131 | 137 | foreach ($this->result->getResult() as $i => $value) { |
132 | 138 | if (is_scalar($value)) { |
133 | 139 | $val = $this->data->read($value); |
134 | - if ($val) $this->result[$i] = $val; |
|
140 | + if ($val) { |
|
141 | + $this->result[$i] = $val; |
|
142 | + } |
|
135 | 143 | } |
136 | 144 | } |
137 | 145 | $this->last = null; |
@@ -143,12 +151,10 @@ discard block |
||
143 | 151 | try { |
144 | 152 | $value = $this->data->extract($this->last, $this->autoLookup); |
145 | 153 | $this->result->processValue($value); |
146 | - } |
|
147 | - catch (\UnexpectedValueException $e) { |
|
154 | + } catch (\UnexpectedValueException $e) { |
|
148 | 155 | if (!$this->autoLookup) { |
149 | 156 | $this->result->processValue($this->last); |
150 | - } |
|
151 | - else { |
|
157 | + } else { |
|
152 | 158 | $this->result->clear(); |
153 | 159 | $this->result[0] = false; |
154 | 160 | } |
@@ -12,6 +12,9 @@ discard block |
||
12 | 12 | private $valueParser; |
13 | 13 | private $xPath; |
14 | 14 | |
15 | + /** |
|
16 | + * @param string $tss |
|
17 | + */ |
|
15 | 18 | public function __construct($tss, $baseDir, CssToXpath $xPath, Value $valueParser) { |
16 | 19 | $this->tss = $this->stripComments($tss, '//', "\n"); |
17 | 20 | $this->tss = $this->stripComments($this->tss, '/*', '*/'); |
@@ -46,6 +49,9 @@ discard block |
||
46 | 49 | return $rules; |
47 | 50 | } |
48 | 51 | |
52 | + /** |
|
53 | + * @param integer $index |
|
54 | + */ |
|
49 | 55 | private function CssToRules($selector, $index, $properties) { |
50 | 56 | //$parts = explode(',', $selector); |
51 | 57 | $parts = $this->splitOnToken($selector, Tokenizer::ARG); |
@@ -70,6 +76,10 @@ discard block |
||
70 | 76 | return $rules; |
71 | 77 | } |
72 | 78 | |
79 | + /** |
|
80 | + * @param integer $key |
|
81 | + * @param integer $indexStart |
|
82 | + */ |
|
73 | 83 | private function processingInstructions($key, $indexStart) { |
74 | 84 | if (isset($this->tss[$key]) && $this->tss[$key]['type'] !== Tokenizer::AT_SIGN) return false; |
75 | 85 | $rules = []; |
@@ -95,6 +105,10 @@ discard block |
||
95 | 105 | return ($a->depth < $b->depth) ? -1 : 1; |
96 | 106 | } |
97 | 107 | |
108 | + /** |
|
109 | + * @param string $open |
|
110 | + * @param string $close |
|
111 | + */ |
|
98 | 112 | private function stripComments($str, $open, $close) { |
99 | 113 | $pos = 0; |
100 | 114 | while (($pos = strpos($str, $open, $pos)) !== false) { |
@@ -84,7 +84,7 @@ |
||
84 | 84 | |
85 | 85 | private function import($args, $indexStart) { |
86 | 86 | $fileName = $args[0]; |
87 | - $sheet = new Sheet(file_get_contents($this->baseDir . $fileName), dirname(realpath($this->baseDir . $fileName)) . DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
87 | + $sheet = new Sheet(file_get_contents($this->baseDir.$fileName), dirname(realpath($this->baseDir.$fileName)).DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
88 | 88 | return $sheet->parse($indexStart); |
89 | 89 | } |
90 | 90 |
@@ -26,7 +26,9 @@ discard block |
||
26 | 26 | $rules = []; |
27 | 27 | $numOfTokens = count($this->tss); |
28 | 28 | for ($i = 0; isset($this->tss[$i]) && $i <= $numOfTokens; $i++) { |
29 | - if ($this->tss[$i]['type'] === Tokenizer::WHITESPACE) continue; |
|
29 | + if ($this->tss[$i]['type'] === Tokenizer::WHITESPACE) { |
|
30 | + continue; |
|
31 | + } |
|
30 | 32 | if ($processing = $this->processingInstructions($i, count($rules)+$indexStart)) { |
31 | 33 | $i = $processing['endPos']+1; |
32 | 34 | $rules = array_merge($rules, $processing['rules']); |
@@ -35,14 +37,20 @@ discard block |
||
35 | 37 | $tokens = array_slice($this->tss, $i); |
36 | 38 | $selector = $this->splitOnToken($tokens, Tokenizer::OPEN_BRACE)[0]; |
37 | 39 | $i += count($selector); |
38 | - if ($selector[count($selector)-1]['type'] === Tokenizer::WHITESPACE) array_pop($selector); |
|
39 | - if (!isset($this->tss[$i])) break; |
|
40 | + if ($selector[count($selector)-1]['type'] === Tokenizer::WHITESPACE) { |
|
41 | + array_pop($selector); |
|
42 | + } |
|
43 | + if (!isset($this->tss[$i])) { |
|
44 | + break; |
|
45 | + } |
|
40 | 46 | |
41 | 47 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss[$i]['value'])); |
42 | 48 | $rules = $this->writeRule($rules, $newRules); |
43 | 49 | } |
44 | 50 | usort($rules, [$this, 'sortRules']); |
45 | - if (empty($rules) && !empty($this->tss)) throw new \Exception("No TSS rules parsed"); |
|
51 | + if (empty($rules) && !empty($this->tss)) { |
|
52 | + throw new \Exception("No TSS rules parsed"); |
|
53 | + } |
|
46 | 54 | return $rules; |
47 | 55 | } |
48 | 56 | |
@@ -69,7 +77,9 @@ discard block |
||
69 | 77 | } |
70 | 78 | |
71 | 79 | private function processingInstructions($key, $indexStart) { |
72 | - if (isset($this->tss[$key]) && $this->tss[$key]['type'] !== Tokenizer::AT_SIGN) return false; |
|
80 | + if (isset($this->tss[$key]) && $this->tss[$key]['type'] !== Tokenizer::AT_SIGN) { |
|
81 | + return false; |
|
82 | + } |
|
73 | 83 | $rules = []; |
74 | 84 | $tokens = array_slice($this->tss, $key+1); |
75 | 85 | $tokens = $this->splitOnToken($tokens, Tokenizer::SEMI_COLON)[0]; |
@@ -88,7 +98,9 @@ discard block |
||
88 | 98 | |
89 | 99 | private function sortRules($a, $b) { |
90 | 100 | //If they have the same depth, compare on index |
91 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
101 | + if ($a->depth === $b->depth) { |
|
102 | + return $a->index < $b->index ? -1 : 1; |
|
103 | + } |
|
92 | 104 | |
93 | 105 | return ($a->depth < $b->depth) ? -1 : 1; |
94 | 106 | } |
@@ -97,7 +109,9 @@ discard block |
||
97 | 109 | $pos = 0; |
98 | 110 | while (($pos = strpos($str, $open, $pos)) !== false) { |
99 | 111 | $end = strpos($str, $close, $pos); |
100 | - if ($end === false) break; |
|
112 | + if ($end === false) { |
|
113 | + break; |
|
114 | + } |
|
101 | 115 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
102 | 116 | } |
103 | 117 | |
@@ -108,8 +122,11 @@ discard block |
||
108 | 122 | $splitTokens = []; |
109 | 123 | $i = 0; |
110 | 124 | foreach ($tokens as $token) { |
111 | - if ($token['type'] === $splitOn) $i++; |
|
112 | - else $splitTokens[$i][] = $token; |
|
125 | + if ($token['type'] === $splitOn) { |
|
126 | + $i++; |
|
127 | + } else { |
|
128 | + $splitTokens[$i][] = $token; |
|
129 | + } |
|
113 | 130 | } |
114 | 131 | return $splitTokens; |
115 | 132 | } |
@@ -117,7 +134,9 @@ discard block |
||
117 | 134 | private function removeWhitespace($tokens) { |
118 | 135 | $newTokens = []; |
119 | 136 | foreach ($tokens as $token) { |
120 | - if ($token['type'] !== Tokenizer::WHITESPACE) $newTokens[] = $token; |
|
137 | + if ($token['type'] !== Tokenizer::WHITESPACE) { |
|
138 | + $newTokens[] = $token; |
|
139 | + } |
|
121 | 140 | } |
122 | 141 | return $newTokens; |
123 | 142 | } |
@@ -127,7 +146,9 @@ discard block |
||
127 | 146 | $return = []; |
128 | 147 | foreach ($rules as $rule) { |
129 | 148 | $rule = $this->removeWhitespace($rule); |
130 | - if (isset($rule[1]) && $rule[1]['type'] === Tokenizer::COLON) $return[$rule[0]['value']] = array_slice($rule, 2); |
|
149 | + if (isset($rule[1]) && $rule[1]['type'] === Tokenizer::COLON) { |
|
150 | + $return[$rule[0]['value']] = array_slice($rule, 2); |
|
151 | + } |
|
131 | 152 | } |
132 | 153 | |
133 | 154 | return $return; |
@@ -49,11 +49,11 @@ |
||
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]; |
@@ -19,12 +19,12 @@ discard block |
||
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 |
||
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 |
@@ -63,8 +63,11 @@ discard block |
||
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 |
||
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 |
||
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); |
@@ -7,8 +7,12 @@ |
||
7 | 7 | namespace Transphporm\Property; |
8 | 8 | class Display implements \Transphporm\Property { |
9 | 9 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
10 | - if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
11 | - else if (strtolower($values[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
12 | - else $element->setAttribute('transphporm', 'show'); |
|
10 | + if ($pseudoMatcher->hasFunction('attr')) { |
|
11 | + $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
12 | + } else if (strtolower($values[0]) === 'none') { |
|
13 | + $element->setAttribute('transphporm', 'remove'); |
|
14 | + } else { |
|
15 | + $element->setAttribute('transphporm', 'show'); |
|
16 | + } |
|
13 | 17 | } |
14 | 18 | } |