@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function format($value, $rules) { |
17 | - if (!isset($rules['format'])) return $value; |
|
17 | + if (!isset($rules['format'])) { |
|
18 | + return $value; |
|
19 | + } |
|
18 | 20 | $tokens = $rules['format']; |
19 | 21 | |
20 | 22 | $functionName = $tokens->from(\Transphporm\Parser\Tokenizer::NAME, true)->read(); |
@@ -27,15 +29,16 @@ discard block |
||
27 | 29 | |
28 | 30 | try { |
29 | 31 | return $this->processFormat($options, $functionName, $value); |
30 | - } |
|
31 | - catch (\Exception $e) { |
|
32 | + } catch (\Exception $e) { |
|
32 | 33 | throw new \Transphporm\RunException(\Transphporm\Exception::FORMATTER, $functionName, $e); |
33 | 34 | } |
34 | 35 | } |
35 | 36 | |
36 | 37 | //TODO: Abstract all error reporting externally with a method for turning it on/off |
37 | 38 | private function assert($condition, $error) { |
38 | - if (!$condition) throw new \Exception($error); |
|
39 | + if (!$condition) { |
|
40 | + throw new \Exception($error); |
|
41 | + } |
|
39 | 42 | } |
40 | 43 | |
41 | 44 | private function processFormat($format, $functionName, $value) { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $this->save = function($content = null) { |
38 | 38 | return $this->document->saveHtml($content); |
39 | 39 | }; |
40 | - $this->document->loadHtml('<' . '?xml encoding="UTF-8">' .$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
40 | + $this->document->loadHtml('<'.'?xml encoding="UTF-8">'.$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
41 | 41 | |
42 | 42 | if (strpos($doc, '<!') !== 0) { |
43 | 43 | $templateNode = $this->document->getElementsByTagName('template')[0]; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | //Either return a whole DomDocument or return the output HTML |
89 | 89 | if ($document) return $this->document; |
90 | 90 | |
91 | - $output = ($this->document->doctype) ? call_user_func($this->save, $this->document->doctype) . "\n" : ''; |
|
91 | + $output = ($this->document->doctype) ? call_user_func($this->save, $this->document->doctype)."\n" : ''; |
|
92 | 92 | |
93 | 93 | if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement); |
94 | 94 | else $output = $this->printDocument(); |
@@ -66,7 +66,9 @@ discard block |
||
66 | 66 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
67 | 67 | private function processHooks() { |
68 | 68 | foreach ($this->hooks as list($query, $hook)) { |
69 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
69 | + foreach ($this->xpath->query($query) as $element) { |
|
70 | + $hook->run($element); |
|
71 | + } |
|
70 | 72 | } |
71 | 73 | $this->hooks = []; |
72 | 74 | } |
@@ -74,7 +76,9 @@ discard block |
||
74 | 76 | /** Prints out the current DomDocument as HTML */ |
75 | 77 | private function printDocument() { |
76 | 78 | $output = ''; |
77 | - foreach ($this->document->documentElement->childNodes as $node) $output .= call_user_func($this->save, $node); |
|
79 | + foreach ($this->document->documentElement->childNodes as $node) { |
|
80 | + $output .= call_user_func($this->save, $node); |
|
81 | + } |
|
78 | 82 | return $output; |
79 | 83 | } |
80 | 84 | |
@@ -86,12 +90,17 @@ discard block |
||
86 | 90 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
87 | 91 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
88 | 92 | //Either return a whole DomDocument or return the output HTML |
89 | - if ($document) return $this->document; |
|
93 | + if ($document) { |
|
94 | + return $this->document; |
|
95 | + } |
|
90 | 96 | |
91 | 97 | $output = ($this->document->doctype) ? call_user_func($this->save, $this->document->doctype) . "\n" : ''; |
92 | 98 | |
93 | - if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement); |
|
94 | - else $output = $this->printDocument(); |
|
99 | + if ($this->document->documentElement->tagName !== 'template') { |
|
100 | + $output .= call_user_func($this->save, $this->document->documentElement); |
|
101 | + } else { |
|
102 | + $output = $this->printDocument(); |
|
103 | + } |
|
95 | 104 | |
96 | 105 | //repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them |
97 | 106 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |
@@ -11,25 +11,33 @@ |
||
11 | 11 | private $lastParentNode; |
12 | 12 | |
13 | 13 | public function match($name, $args, \DomElement $element) { |
14 | - if ($element->parentNode !== $this->lastParentNode) $this->count = 0; |
|
14 | + if ($element->parentNode !== $this->lastParentNode) { |
|
15 | + $this->count = 0; |
|
16 | + } |
|
15 | 17 | |
16 | 18 | $this->lastParentNode = $element->parentNode; |
17 | 19 | |
18 | 20 | |
19 | 21 | |
20 | - if ($name !== 'nth-child') return true; |
|
22 | + if ($name !== 'nth-child') { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $this->count++; |
23 | 27 | $criteria = $args[0]; |
24 | 28 | |
25 | - if (is_callable([$this, $criteria])) return $this->$criteria($this->count); |
|
29 | + if (is_callable([$this, $criteria])) { |
|
30 | + return $this->$criteria($this->count); |
|
31 | + } |
|
26 | 32 | $this->assert(is_numeric($criteria), "Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
27 | 33 | return $this->count == $criteria; |
28 | 34 | } |
29 | 35 | |
30 | 36 | //TODO: Abstract assertions throughout |
31 | 37 | private function assert($condition, $error) { |
32 | - if (!$condition) throw new \Exception($error); |
|
38 | + if (!$condition) { |
|
39 | + throw new \Exception($error); |
|
40 | + } |
|
33 | 41 | } |
34 | 42 | |
35 | 43 | private function odd($num) { |
@@ -40,7 +40,7 @@ |
||
40 | 40 | private function getTemplateContent($newNode, $tss) { |
41 | 41 | $result = []; |
42 | 42 | foreach ($newNode->childNodes as $node) { |
43 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
43 | + if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
44 | 44 | else $result[] = $this->getClonedElement($node, $tss); |
45 | 45 | } |
46 | 46 | return $result; |
@@ -25,13 +25,18 @@ discard block |
||
25 | 25 | $selector = $this->readArray($args, 1); |
26 | 26 | $tss = $this->readArray($args, 2); |
27 | 27 | |
28 | - if (trim($args[0])[0] === '<') $xml = $args[0]; |
|
29 | - else $xml = $this->filePath->getFilePath($args[0]); |
|
28 | + if (trim($args[0])[0] === '<') { |
|
29 | + $xml = $args[0]; |
|
30 | + } else { |
|
31 | + $xml = $this->filePath->getFilePath($args[0]); |
|
32 | + } |
|
30 | 33 | |
31 | 34 | $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->filePath->getFilePath($tss) : null); |
32 | 35 | |
33 | 36 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
34 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
37 | + if ($selector != '') { |
|
38 | + return $this->templateSubsection($doc, $selector); |
|
39 | + } |
|
35 | 40 | |
36 | 41 | return $this->getTemplateContent($doc->documentElement, $tss); |
37 | 42 | } |
@@ -39,8 +44,11 @@ discard block |
||
39 | 44 | private function getTemplateContent($newNode, $tss) { |
40 | 45 | $result = []; |
41 | 46 | foreach ($newNode->childNodes as $node) { |
42 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
43 | - else $result[] = $this->getClonedElement($node, $tss); |
|
47 | + if (isset($node->tagName) && $node->tagName === 'template') { |
|
48 | + $result[] = $this->getTemplateContent($node, $tss); |
|
49 | + } else { |
|
50 | + $result[] = $this->getClonedElement($node, $tss); |
|
51 | + } |
|
44 | 52 | } |
45 | 53 | return $result; |
46 | 54 | } |
@@ -59,7 +67,9 @@ discard block |
||
59 | 67 | |
60 | 68 | private function getClonedElement($node, $tss) { |
61 | 69 | $clone = $node->cloneNode(true); |
62 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
70 | + if ($tss != null && $clone instanceof \DomElement) { |
|
71 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
72 | + } |
|
63 | 73 | return $clone; |
64 | 74 | } |
65 | 75 | } |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | foreach ($this->pseudo as $tokens) { |
26 | 26 | foreach ($this->functions as $function) { |
27 | 27 | $matches = $this->match($tokens, $function, $element); |
28 | - if ($matches === false) return false; |
|
28 | + if ($matches === false) { |
|
29 | + return false; |
|
30 | + } |
|
29 | 31 | } |
30 | 32 | } |
31 | 33 | return true; |
@@ -35,9 +37,10 @@ discard block |
||
35 | 37 | try { |
36 | 38 | $parts = $this->getFuncParts($tokens); |
37 | 39 | $matches = $function->match($parts['name'], $parts['args'], $element); |
38 | - if ($matches === false) return false; |
|
39 | - } |
|
40 | - catch (\Exception $e) { |
|
40 | + if ($matches === false) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + } catch (\Exception $e) { |
|
41 | 44 | throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e); |
42 | 45 | } |
43 | 46 | } |
@@ -46,31 +49,37 @@ discard block |
||
46 | 49 | $parts['name'] = $this->getFuncName($tokens); |
47 | 50 | if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) { |
48 | 51 | $parts['args'] = $this->valueParser->parseTokens($tokens); |
49 | - } |
|
50 | - else if (count($tokens) > 1) { |
|
52 | + } else if (count($tokens) > 1) { |
|
51 | 53 | $tokens->rewind(); |
52 | 54 | $tokens->next(); |
53 | 55 | $parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']); |
56 | + } else { |
|
57 | + $parts['args'] = [['']]; |
|
54 | 58 | } |
55 | - else $parts['args'] = [['']]; |
|
56 | 59 | return $parts; |
57 | 60 | } |
58 | 61 | |
59 | 62 | private function getFuncName($tokens) { |
60 | - if ($tokens->type() === Tokenizer::NAME) return $tokens->read(); |
|
63 | + if ($tokens->type() === Tokenizer::NAME) { |
|
64 | + return $tokens->read(); |
|
65 | + } |
|
61 | 66 | return null; |
62 | 67 | } |
63 | 68 | |
64 | 69 | public function hasFunction($name) { |
65 | 70 | foreach ($this->pseudo as $tokens) { |
66 | - if ($name === $this->getFuncName($tokens)) return true; |
|
71 | + if ($name === $this->getFuncName($tokens)) { |
|
72 | + return true; |
|
73 | + } |
|
67 | 74 | } |
68 | 75 | } |
69 | 76 | |
70 | 77 | public function getFuncArgs($name) { |
71 | 78 | foreach ($this->pseudo as $tokens) { |
72 | 79 | $parts = $this->getFuncParts($tokens); |
73 | - if ($name === $parts['name']) return $parts['args']; |
|
80 | + if ($name === $parts['name']) { |
|
81 | + return $parts['args']; |
|
82 | + } |
|
74 | 83 | } |
75 | 84 | } |
76 | 85 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | private $functionSet; |
10 | 10 | private $elementData; |
11 | 11 | private $line; |
12 | - private $filePath; |
|
12 | + private $filePath; |
|
13 | 13 | |
14 | 14 | public function __construct(\Transphporm\FunctionSet $functionSet, \Transphporm\Hook\ElementData $elementData, &$line, \Transphporm\FilePath $filePath) { |
15 | 15 | $this->functionSet = $functionSet; |
16 | 16 | $this->elementData = $elementData; |
17 | 17 | $this->line = &$line; |
18 | - $this->filePath = $filePath; |
|
18 | + $this->filePath = $filePath; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
@@ -20,7 +20,9 @@ discard block |
||
20 | 20 | |
21 | 21 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
22 | 22 | $values = $this->fixEmpty($values); |
23 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
23 | + if ($element->getAttribute('transphporm') === 'added') { |
|
24 | + return $element->parentNode->removeChild($element); |
|
25 | + } |
|
24 | 26 | $max = $this->getMax($values); |
25 | 27 | $count = 0; |
26 | 28 | $repeat = $this->getRepeatValue($values, $max); |
@@ -29,7 +31,9 @@ discard block |
||
29 | 31 | $hook = $this->createHook($rules, $pseudoMatcher, $properties); |
30 | 32 | |
31 | 33 | foreach ($repeat as $key => $iteration) { |
32 | - if ($count+1 > $max) break; |
|
34 | + if ($count+1 > $max) { |
|
35 | + break; |
|
36 | + } |
|
33 | 37 | $clone = $this->cloneElement($element, $iteration, $key, $count++); |
34 | 38 | //Re-run the hook on the new element, but use the iterated data |
35 | 39 | $hook->run($clone); |
@@ -55,7 +59,9 @@ discard block |
||
55 | 59 | } |
56 | 60 | |
57 | 61 | private function fixEmpty($value) { |
58 | - if (empty($value[0])) $value[0] = []; |
|
62 | + if (empty($value[0])) { |
|
63 | + $value[0] = []; |
|
64 | + } |
|
59 | 65 | return $value; |
60 | 66 | } |
61 | 67 | |
@@ -71,7 +77,9 @@ discard block |
||
71 | 77 | |
72 | 78 | private function tagElement($element, $count) { |
73 | 79 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
74 | - if ($count > 0) $element->setAttribute('transphporm', 'added'); |
|
80 | + if ($count > 0) { |
|
81 | + $element->setAttribute('transphporm', 'added'); |
|
82 | + } |
|
75 | 83 | } |
76 | 84 | |
77 | 85 | private function getMax($values) { |
@@ -80,7 +88,9 @@ discard block |
||
80 | 88 | |
81 | 89 | private function createHook($newRules, $pseudoMatcher, $properties) { |
82 | 90 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $this->line, null, $this->line, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet, $this->filePath); |
83 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
91 | + foreach ($properties as $name => $property) { |
|
92 | + $hook->registerProperty($name, $property); |
|
93 | + } |
|
84 | 94 | return $hook; |
85 | 95 | } |
86 | 96 | } |
@@ -145,7 +145,7 @@ |
||
145 | 145 | $string = $this->extractString($i); |
146 | 146 | $length = strlen($string)+1; |
147 | 147 | $char = $this->getChar($char); |
148 | - $string = str_replace('\\' . $char, $char, $string); |
|
148 | + $string = str_replace('\\'.$char, $char, $string); |
|
149 | 149 | $tokens[] = ['type' => self::STRING, 'value' => $string, 'line' => $this->lineNo]; |
150 | 150 | return $length; |
151 | 151 | } |
@@ -79,8 +79,11 @@ discard block |
||
79 | 79 | $i += $this->doStrings($tokens, $char, $i); |
80 | 80 | $i += $this->doBrackets($tokens, $char, $i); |
81 | 81 | } |
82 | - if ($returnObj) return new Tokens($tokens); |
|
83 | - else return $tokens; |
|
82 | + if ($returnObj) { |
|
83 | + return new Tokens($tokens); |
|
84 | + } else { |
|
85 | + return $tokens; |
|
86 | + } |
|
84 | 87 | } |
85 | 88 | |
86 | 89 | private function doSimpleTokens(&$tokens, $char) { |
@@ -117,10 +120,15 @@ discard block |
||
117 | 120 | } |
118 | 121 | |
119 | 122 | private function processLiterals(&$tokens, $name) { |
120 | - if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
121 | - else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
122 | - else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
123 | - else $tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo]; |
|
123 | + if (is_numeric($name)) { |
|
124 | + $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
125 | + } else if ($name == 'true') { |
|
126 | + $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
127 | + } else if ($name == 'false') { |
|
128 | + $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
129 | + } else { |
|
130 | + $tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo]; |
|
131 | + } |
|
124 | 132 | } |
125 | 133 | |
126 | 134 | private function doBrackets(&$tokens, $char, $i) { |
@@ -154,7 +162,9 @@ discard block |
||
154 | 162 | private function extractString($pos) { |
155 | 163 | $char = $this->str[$pos]; |
156 | 164 | $end = strpos($this->str, $char, $pos+1); |
157 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
165 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
166 | + $end = strpos($this->str, $char, $end+1); |
|
167 | + } |
|
158 | 168 | |
159 | 169 | return substr($this->str, $pos+1, $end-$pos-1); |
160 | 170 | } |
@@ -163,18 +173,26 @@ discard block |
||
163 | 173 | $close = strpos($this->str, $closeBracket, $open); |
164 | 174 | |
165 | 175 | $cPos = $open+1; |
166 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
176 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
177 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
178 | + } |
|
167 | 179 | return substr($this->str, $open+1, $close-$open-1); |
168 | 180 | } |
169 | 181 | |
170 | 182 | private function identifyChar($chr) { |
171 | - if (isset($this->chars[$chr])) return $this->chars[$chr]; |
|
172 | - else return self::NAME; |
|
183 | + if (isset($this->chars[$chr])) { |
|
184 | + return $this->chars[$chr]; |
|
185 | + } else { |
|
186 | + return self::NAME; |
|
187 | + } |
|
173 | 188 | } |
174 | 189 | |
175 | 190 | private function getChar($num) { |
176 | 191 | $chars = array_reverse($this->chars); |
177 | - if (isset($chars[$num])) return $chars[$num]; |
|
178 | - else return false; |
|
192 | + if (isset($chars[$num])) { |
|
193 | + return $chars[$num]; |
|
194 | + } else { |
|
195 | + return false; |
|
196 | + } |
|
179 | 197 | } |
180 | 198 | } |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | if (isset($this->functions[$name])) { |
21 | 21 | return $this->functions[$name]->run($this->getArgs0($name, $args), $this->element); |
22 | 22 | } |
23 | - } |
|
24 | - catch (\Exception $e) { |
|
23 | + } catch (\Exception $e) { |
|
25 | 24 | throw new RunException(Exception::TSS_FUNCTION, $name, $e); |
26 | 25 | } |
27 | 26 | return false; |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | $tokens = $args[0]; |
33 | 32 | $parser = new \Transphporm\Parser\Value($this); |
34 | 33 | return $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
35 | - } |
|
36 | - else if ($args[0] instanceof Parser\Tokens) { |
|
34 | + } else if ($args[0] instanceof Parser\Tokens) { |
|
37 | 35 | return iterator_to_array($args[0]); |
38 | 36 | } |
39 | 37 |
@@ -7,11 +7,11 @@ discard block |
||
7 | 7 | namespace Transphporm\Pseudo; |
8 | 8 | class Not implements \Transphporm\Pseudo { |
9 | 9 | private $cssToXpath; |
10 | - private $config; |
|
10 | + private $config; |
|
11 | 11 | |
12 | 12 | public function __construct(\Transphporm\Parser\CssToXpath $cssToXpath, \Transphporm\Config $config) { |
13 | 13 | $this->cssToXpath = $cssToXpath; |
14 | - $this->config = $config; |
|
14 | + $this->config = $config; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function match($name, $args, \DomElement $element) { |
@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | foreach ($css as $selector) { |
27 | 27 | $tokenizer = new \Transphporm\Parser\Tokenizer($selector); |
28 | 28 | $xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens()); |
29 | - $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
|
30 | - $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
|
29 | + $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
|
30 | + $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
|
31 | 31 | if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) return false; |
32 | 32 | } |
33 | 33 | return true; |
34 | 34 | } |
35 | 35 | |
36 | - private function matches($foundElements, $element, $pseudoMatcher) { |
|
37 | - //Find all nodes matched by the expressions in the brackets :not(EXPR) |
|
38 | - foreach ($foundElements as $matchedElement) { |
|
39 | - //Check to see whether this node was matched by the not query |
|
40 | - if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
41 | - } |
|
42 | - return false; |
|
43 | - } |
|
36 | + private function matches($foundElements, $element, $pseudoMatcher) { |
|
37 | + //Find all nodes matched by the expressions in the brackets :not(EXPR) |
|
38 | + foreach ($foundElements as $matchedElement) { |
|
39 | + //Check to see whether this node was matched by the not query |
|
40 | + if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
41 | + } |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | } |
@@ -15,7 +15,9 @@ discard block |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | public function match($name, $args, \DomElement $element) { |
18 | - if ($name !== 'not') return true; |
|
18 | + if ($name !== 'not') { |
|
19 | + return true; |
|
20 | + } |
|
19 | 21 | |
20 | 22 | $xpath = new \DomXpath($element->ownerDocument); |
21 | 23 | return $this->notElement($args, $xpath, $element); |
@@ -28,7 +30,9 @@ discard block |
||
28 | 30 | $xpathString = $this->cssToXpath->getXpath($tokenizer->getTokens()); |
29 | 31 | $pseudo = $this->cssToXpath->getPseudo($tokenizer->getTokens()); |
30 | 32 | $pseudoMatcher = $this->config->createPseudoMatcher($pseudo); |
31 | - if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) return false; |
|
33 | + if ($this->matches($xpath->query($xpathString), $element, $pseudoMatcher)) { |
|
34 | + return false; |
|
35 | + } |
|
32 | 36 | } |
33 | 37 | return true; |
34 | 38 | } |
@@ -37,7 +41,9 @@ discard block |
||
37 | 41 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
38 | 42 | foreach ($foundElements as $matchedElement) { |
39 | 43 | //Check to see whether this node was matched by the not query |
40 | - if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) return true; |
|
44 | + if ($pseudoMatcher->matches($matchedElement) && $element->isSameNode($matchedElement)) { |
|
45 | + return true; |
|
46 | + } |
|
41 | 47 | } |
42 | 48 | return false; |
43 | 49 | } |