Completed
Push — master ( 878197...378399 )
by Tom
07:30
created
src/Hook/PostProcess.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,9 +9,13 @@
 block discarded – undo
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
 	public function runOnImmutableElements(): bool {
Please login to merge, or discard this patch.
src/Property/Repeat.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@  discard block
 block discarded – undo
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
 
25 27
 		$contentMode = (isset($rules['content-mode'])) ? $rules['content-mode']->read() : 'replace';
26 28
 
@@ -38,7 +40,9 @@  discard block
 block discarded – undo
38 40
 		$hook = $this->createHook($rules, $pseudoMatcher, $properties);
39 41
 
40 42
 		foreach ($repeat as $key => $iteration) {
41
-			if ($count+1 > $max) break;
43
+			if ($count+1 > $max) {
44
+				break;
45
+			}
42 46
 			$clone = $this->cloneElement($element, $iteration, $key, $count++);
43 47
 			//Re-run the hook on the new element, but use the iterated data
44 48
 			$hook->run($clone);
@@ -64,7 +68,9 @@  discard block
 block discarded – undo
64 68
 	}
65 69
 
66 70
 	private function fixEmpty($value) {
67
-		if (empty($value[0])) $value[0] = [];
71
+		if (empty($value[0])) {
72
+			$value[0] = [];
73
+		}
68 74
 		return $value;
69 75
 	}
70 76
 
@@ -80,7 +86,9 @@  discard block
 block discarded – undo
80 86
 
81 87
 	private function tagElement($element, $count) {
82 88
 		//Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed
83
-		if ($count > 0) $element->setAttribute('transphporm', 'added');
89
+		if ($count > 0) {
90
+			$element->setAttribute('transphporm', 'added');
91
+		}
84 92
 	}
85 93
 
86 94
 	private function getMax($values) {
@@ -89,7 +97,9 @@  discard block
 block discarded – undo
89 97
 
90 98
 	private function createHook($newRules, $pseudoMatcher, $properties) {
91 99
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $this->line, null, $this->line, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet, $this->filePath);
92
-		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
100
+		foreach ($properties as $name => $property) {
101
+			$hook->registerProperty($name, $property);
102
+		}
93 103
 		return $hook;
94 104
 	}
95 105
 }
Please login to merge, or discard this patch.
src/Template.php 1 patch
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,8 +41,7 @@  discard block
 block discarded – undo
41 41
 			};
42 42
 			$this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc,  LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
43 43
 
44
-		}
45
-		else {
44
+		} else {
46 45
 			$this->document->loadXml($doc);
47 46
 			//XML was loaded, save as XML.
48 47
 			$this->save = function($content = null) {
@@ -79,7 +78,9 @@  discard block
 block discarded – undo
79 78
 	/** Prints out the current DomDocument as HTML */
80 79
 	private function printDocument() {
81 80
 		$output = '';
82
-		foreach ($this->document->documentElement->childNodes as $node) $output .= call_user_func($this->save, $node);
81
+		foreach ($this->document->documentElement->childNodes as $node) {
82
+			$output .= call_user_func($this->save, $node);
83
+		}
83 84
 		return $output;
84 85
 	}
85 86
 
@@ -91,13 +92,18 @@  discard block
 block discarded – undo
91 92
 		//Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags
92 93
 		//TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes?
93 94
 		 //Either return a whole DomDocument or return the output HTML
94
-		if ($document) return $this->document;
95
+		if ($document) {
96
+			return $this->document;
97
+		}
95 98
 
96 99
 		//Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument
97 100
 		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : '';
98 101
 
99
-		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
100
-		else $output = $this->printDocument();
102
+		if ($this->document->documentElement->tagName !== 'template') {
103
+			$output .= call_user_func($this->save, $this->document->documentElement);
104
+		} else {
105
+			$output = $this->printDocument();
106
+		}
101 107
 
102 108
 		//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
103 109
 		$output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output);
Please login to merge, or discard this patch.