@@ -34,6 +34,10 @@ discard block |
||
34 | 34 | return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append'; |
35 | 35 | } |
36 | 36 | |
37 | + /** |
|
38 | + * @param \DOMElement $element |
|
39 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
40 | + */ |
|
37 | 41 | private function processPseudo($value, $element, $pseudoMatcher) { |
38 | 42 | $pseudoContent = ['attr', 'header', 'before', 'after']; |
39 | 43 | foreach ($pseudoContent as $pseudo) { |
@@ -91,6 +95,9 @@ discard block |
||
91 | 95 | foreach ($remove as $r) $r->parentNode->removeChild($r); |
92 | 96 | } |
93 | 97 | |
98 | + /** |
|
99 | + * @param \DOMElement $element |
|
100 | + */ |
|
94 | 101 | private function replaceContent($element, $content) { |
95 | 102 | //If this rule was cached, the elements that were added last time need to be removed prior to running the rule again. |
96 | 103 | $this->removeAdded($element); |
@@ -100,12 +107,18 @@ discard block |
||
100 | 107 | $element->setAttribute('transphporm', 'remove'); |
101 | 108 | } |
102 | 109 | |
110 | + /** |
|
111 | + * @param \DOMElement $element |
|
112 | + */ |
|
103 | 113 | private function appendContent($element, $content) { |
104 | 114 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
105 | 115 | $element->appendChild($node); |
106 | 116 | } |
107 | 117 | } |
108 | 118 | |
119 | + /** |
|
120 | + * @param \DOMElement $element |
|
121 | + */ |
|
109 | 122 | private function removeAllChildren($element) { |
110 | 123 | while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
111 | 124 | } |
@@ -18,15 +18,20 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
21 | - if ($element->getAttribute('transphporm') === 'remove') return; |
|
21 | + if ($element->getAttribute('transphporm') === 'remove') { |
|
22 | + return; |
|
23 | + } |
|
22 | 24 | |
23 | 25 | $value = $this->formatter->format($value, $rules); |
24 | 26 | if (!$this->processPseudo($value, $element, $pseudoMatcher)) { |
25 | 27 | //Remove the current contents |
26 | 28 | $this->removeAllChildren($element); |
27 | 29 | //Now make a text node |
28 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $value); |
|
29 | - else $this->appendContent($element, $value); |
|
30 | + if ($this->getContentMode($rules) === 'replace') { |
|
31 | + $this->replaceContent($element, $value); |
|
32 | + } else { |
|
33 | + $this->appendContent($element, $value); |
|
34 | + } |
|
30 | 35 | } |
31 | 36 | } |
32 | 37 | |
@@ -50,9 +55,10 @@ discard block |
||
50 | 55 | if ($n instanceof \DomElement) { |
51 | 56 | $new = $document->importNode($n, true); |
52 | 57 | $new->setAttribute('transphporm', 'added'); |
53 | - } |
|
54 | - else { |
|
55 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
58 | + } else { |
|
59 | + if ($n instanceof \DomText) { |
|
60 | + $n = $n->nodeValue; |
|
61 | + } |
|
56 | 62 | $new = $document->createElement('text'); |
57 | 63 | $new->appendChild($document->createTextNode($n)); |
58 | 64 | $new->setAttribute('transphporm', 'text'); |
@@ -88,7 +94,9 @@ discard block |
||
88 | 94 | while ($e = $e->previousSibling && !in_array($e->getAttribute('transphporm'), [null, 'remove'])) { |
89 | 95 | $remove[] = $e; |
90 | 96 | } |
91 | - foreach ($remove as $r) $r->parentNode->removeChild($r); |
|
97 | + foreach ($remove as $r) { |
|
98 | + $r->parentNode->removeChild($r); |
|
99 | + } |
|
92 | 100 | } |
93 | 101 | |
94 | 102 | private function replaceContent($element, $content) { |
@@ -107,6 +115,8 @@ discard block |
||
107 | 115 | } |
108 | 116 | |
109 | 117 | private function removeAllChildren($element) { |
110 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
118 | + while ($element->hasChildNodes()) { |
|
119 | + $element->removeChild($element->firstChild); |
|
120 | + } |
|
111 | 121 | } |
112 | 122 | } |
113 | 123 | \ No newline at end of file |
@@ -34,6 +34,9 @@ |
||
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | |
37 | + /** |
|
38 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
39 | + */ |
|
37 | 40 | private function createHook($newRules, $pseudoMatcher, $properties) { |
38 | 41 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->data)); |
39 | 42 | foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
@@ -13,7 +13,9 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
16 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
16 | + if ($element->getAttribute('transphporm') === 'added') { |
|
17 | + return $element->parentNode->removeChild($element); |
|
18 | + } |
|
17 | 19 | |
18 | 20 | foreach ($value as $key => $iteration) { |
19 | 21 | $clone = $element->cloneNode(true); |
@@ -36,7 +38,9 @@ discard block |
||
36 | 38 | |
37 | 39 | private function createHook($newRules, $pseudoMatcher, $properties) { |
38 | 40 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->data)); |
39 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
41 | + foreach ($properties as $name => $property) { |
|
42 | + $hook->registerProperty($name, $property); |
|
43 | + } |
|
40 | 44 | return $hook; |
41 | 45 | } |
42 | 46 | } |
43 | 47 | \ No newline at end of file |
@@ -20,11 +20,15 @@ discard block |
||
20 | 20 | |
21 | 21 | public function run(\DomElement $element) { |
22 | 22 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
23 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
23 | + if (!$this->pseudoMatcher->matches($element)) { |
|
24 | + return; |
|
25 | + } |
|
24 | 26 | |
25 | 27 | foreach ($this->rules as $name => $value) { |
26 | 28 | $result = $this->callProperty($name, $element, $this->valueParser->parse(trim($value), $element)); |
27 | - if ($result === false) break; |
|
29 | + if ($result === false) { |
|
30 | + break; |
|
31 | + } |
|
28 | 32 | } |
29 | 33 | } |
30 | 34 | |
@@ -45,7 +49,9 @@ discard block |
||
45 | 49 | } |
46 | 50 | |
47 | 51 | private function callProperty($name, $element, $value) { |
48 | - if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
52 | + if (isset($this->properties[$name])) { |
|
53 | + return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
54 | + } |
|
49 | 55 | return false; |
50 | 56 | } |
51 | 57 | } |
@@ -31,7 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | public function hasFunction($name) { |
33 | 33 | foreach ($this->pseudo as $pseudo) { |
34 | - if (strpos($pseudo, $name) === 0) return true; |
|
34 | + if (strpos($pseudo, $name) === 0) { |
|
35 | + return true; |
|
36 | + } |
|
35 | 37 | } |
36 | 38 | } |
37 | 39 | |
@@ -50,11 +52,18 @@ discard block |
||
50 | 52 | $parenthesis = strpos($pseudo, '('); |
51 | 53 | $square = strpos($pseudo, ']'); |
52 | 54 | |
53 | - if ($parenthesis === false) $parenthesis = 999; |
|
54 | - if ($square === false) $square = 999; |
|
55 | + if ($parenthesis === false) { |
|
56 | + $parenthesis = 999; |
|
57 | + } |
|
58 | + if ($square === false) { |
|
59 | + $square = 999; |
|
60 | + } |
|
55 | 61 | |
56 | - if ($parenthesis < $square) return ['(', ')']; |
|
57 | - else if ($parenthesis > $square) return ['[', ']']; |
|
62 | + if ($parenthesis < $square) { |
|
63 | + return ['(', ')']; |
|
64 | + } else if ($parenthesis > $square) { |
|
65 | + return ['[', ']']; |
|
66 | + } |
|
58 | 67 | } |
59 | 68 | |
60 | 69 | public function getPseudo() { |
@@ -7,8 +7,12 @@ |
||
7 | 7 | namespace Transphporm\Property; |
8 | 8 | class Display implements \Transphporm\Property { |
9 | 9 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
10 | - if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')); |
|
11 | - else if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
12 | - else $element->setAttribute('transphporm', 'show'); |
|
10 | + if ($pseudoMatcher->hasFunction('attr')) { |
|
11 | + $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')); |
|
12 | + } else if (strtolower($value[0]) === 'none') { |
|
13 | + $element->setAttribute('transphporm', 'remove'); |
|
14 | + } else { |
|
15 | + $element->setAttribute('transphporm', 'show'); |
|
16 | + } |
|
13 | 17 | } |
14 | 18 | } |
15 | 19 | \ No newline at end of file |
@@ -14,10 +14,14 @@ discard block |
||
14 | 14 | |
15 | 15 | public function match($pseudo, \DomElement $element) { |
16 | 16 | $pos = strpos($pseudo, '['); |
17 | - if ($pos === false) return true; |
|
17 | + if ($pos === false) { |
|
18 | + return true; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | $name = substr($pseudo, 0, $pos); |
20 | - if (!is_callable([$this->dataFunction, $name])) return true; |
|
22 | + if (!is_callable([$this->dataFunction, $name])) { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo); |
23 | 27 | $criteria = $bracketMatcher->match('[', ']'); |
@@ -42,16 +46,21 @@ discard block |
||
42 | 46 | } |
43 | 47 | |
44 | 48 | private function parseValue($value) { |
45 | - if ($value == 'true') return true; |
|
46 | - else if ($value == 'false') return false; |
|
47 | - else return $value; |
|
49 | + if ($value == 'true') { |
|
50 | + return true; |
|
51 | + } else if ($value == 'false') { |
|
52 | + return false; |
|
53 | + } else { |
|
54 | + return $value; |
|
55 | + } |
|
48 | 56 | } |
49 | 57 | |
50 | 58 | private function getOperator($field) { |
51 | 59 | if ($field[strlen($field)-1] == '!') { |
52 | 60 | return '!'; |
61 | + } else { |
|
62 | + return ''; |
|
53 | 63 | } |
54 | - else return ''; |
|
55 | 64 | } |
56 | 65 | |
57 | 66 | } |
58 | 67 | \ No newline at end of file |
@@ -24,7 +24,9 @@ |
||
24 | 24 | $xpath = new \DomXpath($element->ownerDocument); |
25 | 25 | |
26 | 26 | foreach ($xpath->query($xpathString) as $matchedElement) { |
27 | - if ($element->isSameNode($matchedElement)) return false; |
|
27 | + if ($element->isSameNode($matchedElement)) { |
|
28 | + return false; |
|
29 | + } |
|
28 | 30 | } |
29 | 31 | } |
30 | 32 | } |
@@ -15,8 +15,11 @@ |
||
15 | 15 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($element->getNodePath()); |
16 | 16 | $num = $bracketMatcher->match('[', ']'); |
17 | 17 | |
18 | - if (is_callable([$this, $criteria])) return $this->$criteria($num); |
|
19 | - else return $num == $criteria; |
|
18 | + if (is_callable([$this, $criteria])) { |
|
19 | + return $this->$criteria($num); |
|
20 | + } else { |
|
21 | + return $num == $criteria; |
|
22 | + } |
|
20 | 23 | } |
21 | 24 | return true; |
22 | 25 | } |