Completed
Pull Request — master (#175)
by Tom
05:04 queued 04:06
created
src/Parser/Value.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@
 block discarded – undo
148 148
 		}
149 149
 		else $parsedVal = null;
150 150
         
151
-        $this->result->postProcess($this->data, $val, $parsedVal, $this->allowNullResult);
151
+		$this->result->postProcess($this->data, $val, $parsedVal, $this->allowNullResult);
152 152
 
153 153
 		$this->last->clear();
154 154
 	}
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
 		if ($lastResult) {
86 86
 			$this->last->makeTraversing();
87 87
 		}
88
-		else if ($this->last->isEmpty())  {
88
+		else if ($this->last->isEmpty()) {
89 89
 			$this->processString(['value' => '.']);
90 90
 			$this->result->setMode(Tokenizer::CONCAT);
91 91
 		}
Please login to merge, or discard this patch.
Braces   +11 added lines, -9 removed lines patch added patch discarded remove patch
@@ -56,7 +56,9 @@  discard block
 block discarded – undo
56 56
 		$this->last = new Last($this->data, $this->result, $this->autoLookup);
57 57
 		$this->traversing = false;
58 58
 
59
-		if (count($tokens) <= 0) return [$data];
59
+		if (count($tokens) <= 0) {
60
+			return [$data];
61
+		}
60 62
 
61 63
 		foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) {
62 64
 			$this->{$this->tokenFuncs[$token['type']]}($token);
@@ -84,8 +86,7 @@  discard block
 block discarded – undo
84 86
 		// foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo"
85 87
 		if ($lastResult) {
86 88
 			$this->last->makeTraversing();
87
-		}
88
-		else if ($this->last->isEmpty())  {
89
+		} else if ($this->last->isEmpty())  {
89 90
 			$this->processString(['value' => '.']);
90 91
 			$this->result->setMode(Tokenizer::CONCAT);
91 92
 		}
@@ -100,11 +101,12 @@  discard block
 block discarded – undo
100 101
 	private function processSquareBracket($token) {
101 102
 		if ($this->hasFunction($this->last->read())) {
102 103
 			$this->callTransphpormFunctions($token);
103
-		}
104
-		else {
104
+		} else {
105 105
 			$this->last->traverse();
106 106
 			$this->last->set($this->getNewParser()->parseTokens($token['value'], null)[0]);
107
-			if (!is_bool($this->last->read())) $this->last->makeTraversing();
107
+			if (!is_bool($this->last->read())) {
108
+				$this->last->makeTraversing();
109
+			}
108 110
 		}
109 111
 	}
110 112
 
@@ -127,8 +129,7 @@  discard block
 block discarded – undo
127 129
 		if ($this->hasFunction($this->last->read())
128 130
 			&& !$this->data->methodExists($this->last->read())) {
129 131
 			$this->callTransphpormFunctions($token);
130
-		}
131
-		else {
132
+		} else {
132 133
 			$this->last->processNested($this->getNewParser(), $token);
133 134
 		}
134 135
 	}
@@ -145,8 +146,9 @@  discard block
 block discarded – undo
145 146
 			$parser = new Value($this->data->getData());
146 147
 			$parsedArr = $parser->parse($val);
147 148
 			$parsedVal = isset($parsedArr[0]) ? $parsedArr[0] : null;
149
+		} else {
150
+			$parsedVal = null;
148 151
 		}
149
-		else $parsedVal = null;
150 152
         
151 153
         $this->result->postProcess($this->data, $val, $parsedVal, $this->allowNullResult);
152 154
 
Please login to merge, or discard this patch.
src/Property/ContentPseudo.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,5 +2,5 @@
 block discarded – undo
2 2
 namespace Transphporm\Property;
3 3
 
4 4
 interface ContentPseudo {
5
-    public function run($value, $pseudoArgs, $element);
5
+	public function run($value, $pseudoArgs, $element);
6 6
 }
Please login to merge, or discard this patch.
src/Property/Content.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,9 +39,9 @@
 block discarded – undo
39 39
 		return (isset($rules['content-mode'])) ? $rules['content-mode']->read() : 'append';
40 40
 	}
41 41
 
42
-    public function addContentPseudo($name, ContentPseudo $contentPseudo) {
43
-        $this->contentPseudo[$name] = $contentPseudo;
44
-    }
42
+	public function addContentPseudo($name, ContentPseudo $contentPseudo) {
43
+		$this->contentPseudo[$name] = $contentPseudo;
44
+	}
45 45
     
46 46
 	private function processPseudo($value, $element, $pseudoMatcher) {
47 47
 		foreach ($this->contentPseudo as $pseudoName => $pseudoFunction) {
Please login to merge, or discard this patch.
Braces   +22 added lines, -11 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
 		}
@@ -69,9 +77,10 @@  discard block
 block discarded – undo
69 77
 			$new = $document->importNode($node, true);
70 78
 			//Removing this might cause problems with caching...
71 79
 			//$new->setAttribute('transphporm', 'added');
72
-		}
73
-		else {
74
-			if ($node instanceof \DomText) $node = $node->nodeValue;
80
+		} else {
81
+			if ($node instanceof \DomText) {
82
+				$node = $node->nodeValue;
83
+			}
75 84
 			$new = $document->createElement('text');
76 85
 
77 86
 			$new->appendChild($document->createTextNode($node));
@@ -95,6 +104,8 @@  discard block
 block discarded – undo
95 104
 	}
96 105
 
97 106
 	private function removeAllChildren($element) {
98
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
107
+		while ($element->hasChildNodes()) {
108
+			$element->removeChild($element->firstChild);
109
+		}
99 110
 	}
100 111
 }
Please login to merge, or discard this patch.
src/Property/ContentPseudo/Attr.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm\Property\ContentPseudo;
3 3
 class Attr implements \Transphporm\Property\ContentPseudo {
4
-    public function run($value, $pseudoArgs, $element) {
5
-        $element->setAttribute($pseudoArgs, implode('', $value));
6
-    }
4
+	public function run($value, $pseudoArgs, $element) {
5
+		$element->setAttribute($pseudoArgs, implode('', $value));
6
+	}
7 7
 }
Please login to merge, or discard this patch.
src/Property/ContentPseudo/BeforeAfter.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm\Property\ContentPseudo;
3 3
 class BeforeAfter implements \Transphporm\Property\ContentPseudo {
4
-    private $insertLocation;
5
-    private $content;
4
+	private $insertLocation;
5
+	private $content;
6 6
 
7
-    public function __construct($insertLocation, \Transphporm\Property\Content $content) {
8
-        $this->insertLocation = $insertLocation;
7
+	public function __construct($insertLocation, \Transphporm\Property\Content $content) {
8
+		$this->insertLocation = $insertLocation;
9 9
 		$this->content = $content;
10 10
 	}
11 11
 
12
-    public function run($value, $pseudoArgs, $element) {
13
-        foreach ($this->content->getNode($value, $element->ownerDocument) as $node) {
12
+	public function run($value, $pseudoArgs, $element) {
13
+		foreach ($this->content->getNode($value, $element->ownerDocument) as $node) {
14 14
 			if ($this->insertLocation === "before") $element->insertBefore($node, $element->firstChild);
15
-            else if ($this->insertLocation === "after") $element->appendChild($node);
15
+			else if ($this->insertLocation === "after") $element->appendChild($node);
16 16
 		}
17
-    }
17
+	}
18 18
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,11 @@
 block discarded – undo
11 11
 
12 12
     public function run($value, $pseudoArgs, $element) {
13 13
         foreach ($this->content->getNode($value, $element->ownerDocument) as $node) {
14
-			if ($this->insertLocation === "before") $element->insertBefore($node, $element->firstChild);
15
-            else if ($this->insertLocation === "after") $element->appendChild($node);
14
+			if ($this->insertLocation === "before") {
15
+				$element->insertBefore($node, $element->firstChild);
16
+			} else if ($this->insertLocation === "after") {
17
+            	$element->appendChild($node);
18
+            }
16 19
 		}
17 20
     }
18 21
 }
Please login to merge, or discard this patch.
src/Property/ContentPseudo/Headers.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm\Property\ContentPseudo;
3 3
 class Headers implements \Transphporm\Property\ContentPseudo {
4
-    private $headers;
4
+	private $headers;
5 5
 
6
-    public function __construct(&$headers) {
6
+	public function __construct(&$headers) {
7 7
 		$this->headers = &$headers;
8 8
 	}
9 9
 
10
-    public function run($value, $pseudoArgs, $element) {
11
-        $this->headers[] = [$pseudoArgs, implode('', $value)];
12
-    }
10
+	public function run($value, $pseudoArgs, $element) {
11
+		$this->headers[] = [$pseudoArgs, implode('', $value)];
12
+	}
13 13
 }
Please login to merge, or discard this patch.
src/Module/Basics.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@
 block discarded – undo
13 13
 		$data = $config->getFunctionSet();
14 14
 		$headers = &$config->getHeaders();
15 15
 
16
-        $content = new \Transphporm\Property\Content($config->getFormatter());
16
+		$content = new \Transphporm\Property\Content($config->getFormatter());
17 17
 		$config->registerProperty('content', $content);
18 18
 		$config->registerProperty('repeat', new \Transphporm\Property\Repeat($data, $config->getElementData(), $config->getLine(), $config->getFilePath()));
19 19
 		$config->registerProperty('display', new \Transphporm\Property\Display);
20 20
 		$config->registerProperty('bind', new \Transphporm\Property\Bind($config->getElementData()));
21 21
 
22
-        $content->addContentPseudo("before", new \Transphporm\Property\ContentPseudo\BeforeAfter("before", $content));
23
-        $content->addContentPseudo("after", new \Transphporm\Property\ContentPseudo\BeforeAfter("after", $content));
24
-        $content->addContentPseudo("attr", new \Transphporm\Property\ContentPseudo\Attr());
25
-        $content->addContentPseudo("header", new \Transphporm\Property\ContentPseudo\Headers($headers));
22
+		$content->addContentPseudo("before", new \Transphporm\Property\ContentPseudo\BeforeAfter("before", $content));
23
+		$content->addContentPseudo("after", new \Transphporm\Property\ContentPseudo\BeforeAfter("after", $content));
24
+		$content->addContentPseudo("attr", new \Transphporm\Property\ContentPseudo\Attr());
25
+		$content->addContentPseudo("header", new \Transphporm\Property\ContentPseudo\Headers($headers));
26 26
 	}
27 27
 }
Please login to merge, or discard this patch.
src/Config.php 2 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,9 @@  discard block
 block discarded – undo
68 68
 	}
69 69
 
70 70
     public function registerContentPseudo($name, Property\ContentPseudo $pseudo) {
71
-        if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo);
71
+        if (isset($this->properties['content'])) {
72
+        	$this->properties['content']->addContentPseudo($name, $pseudo);
73
+        }
72 74
     }
73 75
 
74 76
 	public function registerPseudo(Pseudo $pseudo) {
@@ -76,12 +78,16 @@  discard block
 block discarded – undo
76 78
 	}
77 79
 
78 80
 	public function loadProperties(Hook\PropertyHook $hook) {
79
-		foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property);
81
+		foreach ($this->properties as $name => $property) {
82
+			$hook->registerProperty($name, $property);
83
+		}
80 84
 	}
81 85
 
82 86
 	public function createPseudoMatcher($pseudo) {
83 87
 		$pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser);
84
-		foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction);
88
+		foreach ($this->pseudo as $pseudoFunction) {
89
+			$pseudoMatcher->registerFunction(clone $pseudoFunction);
90
+		}
85 91
 		return $pseudoMatcher;
86 92
 	}
87 93
 
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	}
41 41
 
42 42
 	public function &getLine() {
43
-        $line = &$this->line;
43
+		$line = &$this->line;
44 44
 		return $line;
45 45
 	}
46 46
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 		$this->properties[$name] = $property;
69 69
 	}
70 70
 
71
-    public function registerContentPseudo($name, Property\ContentPseudo $pseudo) {
72
-        if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo);
73
-    }
71
+	public function registerContentPseudo($name, Property\ContentPseudo $pseudo) {
72
+		if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo);
73
+	}
74 74
 
75 75
 	public function registerPseudo(Pseudo $pseudo) {
76 76
 		$this->pseudo[] = $pseudo;
Please login to merge, or discard this patch.
src/Template.php 2 patches
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,7 +66,9 @@  discard block
 block discarded – undo
66 66
 	/** Loops through all assigned hooks, runs the Xpath query and calls the hook */
67 67
 	private function processHooks() {
68 68
 		foreach ($this->hooks as list($query, $hook)) {
69
-			foreach ($this->xpath->query($query) as $element) $hook->run($element);
69
+			foreach ($this->xpath->query($query) as $element) {
70
+				$hook->run($element);
71
+			}
70 72
 		}
71 73
 		$this->hooks = [];
72 74
 	}
@@ -74,7 +76,9 @@  discard block
 block discarded – undo
74 76
 	/** Prints out the current DomDocument as HTML */
75 77
 	private function printDocument() {
76 78
 		$output = '';
77
-		foreach ($this->document->documentElement->childNodes as $node) $output .= call_user_func($this->save, $node);
79
+		foreach ($this->document->documentElement->childNodes as $node) {
80
+			$output .= call_user_func($this->save, $node);
81
+		}
78 82
 		return $output;
79 83
 	}
80 84
 
@@ -86,13 +90,18 @@  discard block
 block discarded – undo
86 90
 		//Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags
87 91
 		//TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes?
88 92
 		 //Either return a whole DomDocument or return the output HTML
89
-		if ($document) return $this->document;
93
+		if ($document) {
94
+			return $this->document;
95
+		}
90 96
 
91 97
 		//Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument
92 98
 		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : '';
93 99
 
94
-		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
95
-		else $output = $this->printDocument();
100
+		if ($this->document->documentElement->tagName !== 'template') {
101
+			$output .= call_user_func($this->save, $this->document->documentElement);
102
+		} else {
103
+			$output = $this->printDocument();
104
+		}
96 105
 
97 106
 		//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 107
 		$output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 				$this->save = function($content = null) {
38 38
 					return $this->document->saveHtml($content);
39 39
 				};
40
-				$this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc,  LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
40
+				$this->document->loadHtml('<'.'?xml encoding="UTF-8">'.$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
41 41
 
42 42
 				if (strpos($doc, '<!') !== 0) {
43 43
 					$templateNode = $this->document->getElementsByTagName('template')[0];
@@ -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.