Completed
Push — master ( 06f4a4...cfb008 )
by Tom
06:24
created
src/Property/Content.php 1 patch
Braces   +28 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 	}
15 15
 
16 16
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
17
-		if (!$this->shouldRun($element)) return false;
17
+		if (!$this->shouldRun($element)) {
18
+			return false;
19
+		}
18 20
 
19 21
 		$values = $this->formatter->format($values, $rules);
20 22
 
@@ -22,14 +24,19 @@  discard block
 block discarded – undo
22 24
 			//Remove the current contents
23 25
 			$this->removeAllChildren($element);
24 26
 			//Now make a text node
25
-			if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values);
26
-			else $this->appendContent($element, $values);
27
+			if ($this->getContentMode($rules) === 'replace') {
28
+				$this->replaceContent($element, $values);
29
+			} else {
30
+				$this->appendContent($element, $values);
31
+			}
27 32
 		}
28 33
 	}
29 34
 
30 35
 	private function shouldRun($element) {
31 36
 		do {
32
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
37
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
38
+				return false;
39
+			}
33 40
 		}
34 41
 		while (($element = $element->parentNode) instanceof \DomElement);
35 42
 		return true;
@@ -56,9 +63,10 @@  discard block
 block discarded – undo
56 63
 	public function getNode($node, $document) {
57 64
 		foreach ($node as $n) {
58 65
 			if (is_array($n)) {
59
-				foreach ($this->getNode($n, $document) as $new) yield $new;
60
-			}
61
-			else {
66
+				foreach ($this->getNode($n, $document) as $new) {
67
+					yield $new;
68
+				}
69
+			} else {
62 70
 				yield $this->convertNode($n, $document);
63 71
 			}
64 72
 		}
@@ -67,9 +75,10 @@  discard block
 block discarded – undo
67 75
 	private function convertNode($node, $document) {
68 76
 		if ($node instanceof \DomElement || $node instanceof \DOMComment) {
69 77
 			$new = $document->importNode($node, true);
70
-		}
71
-		else {
72
-			if ($node instanceof \DomText) $node = $node->nodeValue;
78
+		} else {
79
+			if ($node instanceof \DomText) {
80
+				$node = $node->nodeValue;
81
+			}
73 82
 			$new = $document->createElement('text');
74 83
 
75 84
 			$new->appendChild($document->createTextNode($node));
@@ -80,14 +89,18 @@  discard block
 block discarded – undo
80 89
 
81 90
 
82 91
 	private function replaceContent($element, $content) {
83
-		if ($element->getAttribute('transphporm') == 'added') return;
92
+		if ($element->getAttribute('transphporm') == 'added') {
93
+			return;
94
+		}
84 95
 		//If this rule was cached, the elements that were added last time need to be removed prior to running the rule again.
85 96
 		if ($element->getAttribute('transphporm')) {
86 97
 			$this->replaceCachedContent($element);
87 98
 		}
88 99
 
89 100
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
90
-			if ($node instanceof \DomElement && !$node->getAttribute('transphporm'))  $node->setAttribute('transphporm', 'added');
101
+			if ($node instanceof \DomElement && !$node->getAttribute('transphporm')) {
102
+				$node->setAttribute('transphporm', 'added');
103
+			}
91 104
 			$element->parentNode->insertBefore($node, $element);
92 105
 		}
93 106
 
@@ -122,6 +135,8 @@  discard block
 block discarded – undo
122 135
 	}
123 136
 
124 137
 	private function removeAllChildren($element) {
125
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
138
+		while ($element->hasChildNodes()) {
139
+			$element->removeChild($element->firstChild);
140
+		}
126 141
 	}
127 142
 }
128 143
\ No newline at end of file
Please login to merge, or discard this patch.