@@ -18,23 +18,34 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 21 | - if ($this->isIncludedTemplate($element)) return; |
|
| 22 | - if ($element->getAttribute('transphporm') === 'remove') return; |
|
| 21 | + if ($this->isIncludedTemplate($element)) { |
|
| 22 | + return; |
|
| 23 | + } |
|
| 24 | + if ($element->getAttribute('transphporm') === 'remove') { |
|
| 25 | + return; |
|
| 26 | + } |
|
| 23 | 27 | |
| 24 | 28 | $value = $this->formatter->format($value, $rules); |
| 25 | 29 | if (!$this->processPseudo($value, $element, $pseudoMatcher)) { |
| 26 | 30 | //Remove the current contents |
| 27 | 31 | $this->removeAllChildren($element); |
| 28 | 32 | //Now make a text node |
| 29 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $value); |
|
| 30 | - else $this->appendContent($element, $value); |
|
| 33 | + if ($this->getContentMode($rules) === 'replace') { |
|
| 34 | + $this->replaceContent($element, $value); |
|
| 35 | + } else { |
|
| 36 | + $this->appendContent($element, $value); |
|
| 37 | + } |
|
| 31 | 38 | } |
| 32 | 39 | } |
| 33 | 40 | |
| 34 | 41 | private function isIncludedTemplate($element) { |
| 35 | 42 | do { |
| 36 | - if ($element instanceof \DomDocument) return false; |
|
| 37 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return true; |
|
| 43 | + if ($element instanceof \DomDocument) { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
| 47 | + return true; |
|
| 48 | + } |
|
| 38 | 49 | } |
| 39 | 50 | while ($element = $element->parentNode); |
| 40 | 51 | return false; |
@@ -60,9 +71,10 @@ discard block |
||
| 60 | 71 | $new = $document->importNode($n, true); |
| 61 | 72 | //Removing this might cause problems with caching... |
| 62 | 73 | //$new->setAttribute('transphporm', 'added'); |
| 63 | - } |
|
| 64 | - else { |
|
| 65 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
| 74 | + } else { |
|
| 75 | + if ($n instanceof \DomText) { |
|
| 76 | + $n = $n->nodeValue; |
|
| 77 | + } |
|
| 66 | 78 | $new = $document->createElement('text'); |
| 67 | 79 | $new->appendChild($document->createTextNode($n)); |
| 68 | 80 | $new->setAttribute('transphporm', 'text'); |
@@ -98,7 +110,9 @@ discard block |
||
| 98 | 110 | while ($e = $e->previousSibling && !in_array($e->getAttribute('transphporm'), [null, 'remove'])) { |
| 99 | 111 | $remove[] = $e; |
| 100 | 112 | } |
| 101 | - foreach ($remove as $r) $r->parentNode->removeChild($r); |
|
| 113 | + foreach ($remove as $r) { |
|
| 114 | + $r->parentNode->removeChild($r); |
|
| 115 | + } |
|
| 102 | 116 | } |
| 103 | 117 | |
| 104 | 118 | private function replaceContent($element, $content) { |
@@ -117,6 +131,8 @@ discard block |
||
| 117 | 131 | } |
| 118 | 132 | |
| 119 | 133 | private function removeAllChildren($element) { |
| 120 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
| 134 | + while ($element->hasChildNodes()) { |
|
| 135 | + $element->removeChild($element->firstChild); |
|
| 136 | + } |
|
| 121 | 137 | } |
| 122 | 138 | } |
| 123 | 139 | \ No newline at end of file |