@@ -9,9 +9,13 @@ |
||
9 | 9 | class PostProcess implements \Transphporm\Hook { |
10 | 10 | public function run(\DomElement $element) { |
11 | 11 | $transphporm = $element->getAttribute('transphporm'); |
12 | - if ($transphporm === 'remove') $element->parentNode->removeChild($element); |
|
13 | - else if ($transphporm === 'text') $element->parentNode->replaceChild($element->firstChild, $element); |
|
14 | - else $element->removeAttribute('transphporm'); |
|
12 | + if ($transphporm === 'remove') { |
|
13 | + $element->parentNode->removeChild($element); |
|
14 | + } else if ($transphporm === 'text') { |
|
15 | + $element->parentNode->replaceChild($element->firstChild, $element); |
|
16 | + } else { |
|
17 | + $element->removeAttribute('transphporm'); |
|
18 | + } |
|
15 | 19 | } |
16 | 20 | |
17 | 21 | } |
18 | 22 | \ No newline at end of file |
@@ -19,7 +19,9 @@ |
||
19 | 19 | $close = strpos($this->str, $closingChr, $open); |
20 | 20 | |
21 | 21 | $cPos = $open+1; |
22 | - while (($cPos = strpos($this->str, $openChr, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closingChr, $close+1); |
|
22 | + while (($cPos = strpos($this->str, $openChr, $cPos+1)) !== false && $cPos < $close) { |
|
23 | + $close = strpos($this->str, $closingChr, $close+1); |
|
24 | + } |
|
23 | 25 | |
24 | 26 | $this->startPos = $open; |
25 | 27 | $this->endPos = $close; |
@@ -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 | } |
@@ -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 |
@@ -11,6 +11,9 @@ discard block |
||
11 | 11 | private $formatter; |
12 | 12 | |
13 | 13 | |
14 | + /** |
|
15 | + * @param \Transphporm\Hook\DataFunction $data |
|
16 | + */ |
|
14 | 17 | public function __construct($data, &$headers, \Transphporm\Hook\Formatter $formatter) { |
15 | 18 | $this->data = $data; |
16 | 19 | $this->headers = &$headers; |
@@ -34,6 +37,10 @@ discard block |
||
34 | 37 | return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append'; |
35 | 38 | } |
36 | 39 | |
40 | + /** |
|
41 | + * @param \DOMElement $element |
|
42 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
43 | + */ |
|
37 | 44 | private function processPseudo($value, $element, $pseudoMatcher) { |
38 | 45 | $pseudoContent = ['attr', 'header', 'before', 'after']; |
39 | 46 | foreach ($pseudoContent as $pseudo) { |
@@ -91,6 +98,9 @@ discard block |
||
91 | 98 | foreach ($remove as $r) $r->parentNode->removeChild($r); |
92 | 99 | } |
93 | 100 | |
101 | + /** |
|
102 | + * @param \DOMElement $element |
|
103 | + */ |
|
94 | 104 | private function replaceContent($element, $content) { |
95 | 105 | //If this rule was cached, the elements that were added last time need to be removed prior to running the rule again. |
96 | 106 | $this->removeAdded($element); |
@@ -100,12 +110,18 @@ discard block |
||
100 | 110 | $element->setAttribute('transphporm', 'remove'); |
101 | 111 | } |
102 | 112 | |
113 | + /** |
|
114 | + * @param \DOMElement $element |
|
115 | + */ |
|
103 | 116 | private function appendContent($element, $content) { |
104 | 117 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
105 | 118 | $element->appendChild($node); |
106 | 119 | } |
107 | 120 | } |
108 | 121 | |
122 | + /** |
|
123 | + * @param \DOMElement $element |
|
124 | + */ |
|
109 | 125 | private function removeAllChildren($element) { |
110 | 126 | while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
111 | 127 | } |
@@ -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 |
@@ -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 | } |
@@ -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,10 +52,16 @@ 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 ['(', ')']; |
|
62 | + if ($parenthesis < $square) { |
|
63 | + return ['(', ')']; |
|
64 | + } |
|
57 | 65 | return ['[', ']']; |
58 | 66 | } |
59 | 67 |
@@ -30,7 +30,9 @@ |
||
30 | 30 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
31 | 31 | foreach ($xpath->query($xpathString) as $matchedElement) { |
32 | 32 | //Check to see whether this node was matched by the not query |
33 | - if ($element->isSameNode($matchedElement)) return false; |
|
33 | + if ($element->isSameNode($matchedElement)) { |
|
34 | + return false; |
|
35 | + } |
|
34 | 36 | } |
35 | 37 | } |
36 | 38 | return true; |