Completed
Push — master ( a6fc67...f029dd )
by Tom
03:46 queued 01:29
created
src/Template.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 			$this->save = function($content = null) {
39 39
 				return $this->document->saveHtml($content);
40 40
 			};
41
-			$this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc,  LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
41
+			$this->document->loadHtml('<'.'?xml encoding="UTF-8">'.$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
42 42
 
43 43
 		}
44 44
 		else {
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		if ($document) return $this->document;
90 90
 
91 91
 		//Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument
92
-		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : '';
92
+		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype)."\n" : '';
93 93
 
94 94
 		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
95 95
 		else $output = $this->printDocument();
Please login to merge, or discard this patch.
Braces   +15 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
 			};
41 41
 			$this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc,  LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
42 42
 
43
-		}
44
-		else {
43
+		} else {
45 44
 			$this->document->loadXml($doc);
46 45
 			//XML was loaded, save as XML.
47 46
 			$this->save = function($content = null) {
@@ -66,7 +65,9 @@  discard block
 block discarded – undo
66 65
 	/** Loops through all assigned hooks, runs the Xpath query and calls the hook */
67 66
 	private function processHooks() {
68 67
 		foreach ($this->hooks as list($query, $hook)) {
69
-			foreach ($this->xpath->query($query) as $element) $hook->run($element);
68
+			foreach ($this->xpath->query($query) as $element) {
69
+				$hook->run($element);
70
+			}
70 71
 		}
71 72
 		$this->hooks = [];
72 73
 	}
@@ -74,7 +75,9 @@  discard block
 block discarded – undo
74 75
 	/** Prints out the current DomDocument as HTML */
75 76
 	private function printDocument() {
76 77
 		$output = '';
77
-		foreach ($this->document->documentElement->childNodes as $node) $output .= call_user_func($this->save, $node);
78
+		foreach ($this->document->documentElement->childNodes as $node) {
79
+			$output .= call_user_func($this->save, $node);
80
+		}
78 81
 		return $output;
79 82
 	}
80 83
 
@@ -86,13 +89,18 @@  discard block
 block discarded – undo
86 89
 		//Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags
87 90
 		//TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes?
88 91
 		 //Either return a whole DomDocument or return the output HTML
89
-		if ($document) return $this->document;
92
+		if ($document) {
93
+			return $this->document;
94
+		}
90 95
 
91 96
 		//Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument
92 97
 		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : '';
93 98
 
94
-		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
95
-		else $output = $this->printDocument();
99
+		if ($this->document->documentElement->tagName !== 'template') {
100
+			$output .= call_user_func($this->save, $this->document->documentElement);
101
+		} else {
102
+			$output = $this->printDocument();
103
+		}
96 104
 
97 105
 		//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
98 106
 		$output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output);
Please login to merge, or discard this patch.