Completed
Push — master ( 0b7883...3269d2 )
by Tom
02:16
created
src/Hook/PropertyHook.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 		$this->valueParser = $valueParser;
27 27
 		$this->pseudoMatcher = $pseudoMatcher;
28 28
 		$this->functionSet = $functionSet;
29
-		if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR;
29
+		if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)).DIRECTORY_SEPARATOR;
30 30
 	}
31 31
 
32 32
 	public function run(\DomElement $element) {
Please login to merge, or discard this patch.
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,7 +26,9 @@  discard block
 block discarded – undo
26 26
 		$this->valueParser = $valueParser;
27 27
 		$this->pseudoMatcher = $pseudoMatcher;
28 28
 		$this->functionSet = $functionSet;
29
-		if ($this->file !== null) $this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR;
29
+		if ($this->file !== null) {
30
+			$this->baseDir = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR;
31
+		}
30 32
 	}
31 33
 
32 34
 	public function run(\DomElement $element) {
@@ -34,10 +36,11 @@  discard block
 block discarded – undo
34 36
 		$this->configLine = $this->line;
35 37
 		try {
36 38
 			//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
37
-			if (!$this->pseudoMatcher->matches($element)) return;
39
+			if (!$this->pseudoMatcher->matches($element)) {
40
+				return;
41
+			}
38 42
 			$this->callProperties($element);
39
-		}
40
-		catch (\Transphporm\RunException $e) {
43
+		} catch (\Transphporm\RunException $e) {
41 44
 			throw new \Transphporm\Exception($e, $this->file, $this->line);
42 45
 		}
43 46
 	}
@@ -48,7 +51,9 @@  discard block
 block discarded – undo
48 51
 	private function callProperties($element) {
49 52
 		foreach ($this->rules as $name => $value) {
50 53
 			$result = $this->callProperty($name, $element, $this->getArgs($value));
51
-			if ($result === false) break;
54
+			if ($result === false) {
55
+				break;
56
+			}
52 57
 		}
53 58
 	}
54 59
 	private function getArgs($value) {
@@ -63,9 +68,10 @@  discard block
 block discarded – undo
63 68
 		if (isset($this->properties[$name])) {
64 69
 			try {
65 70
 				return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
66
-			}
67
-			catch (\Exception $e) {
68
-				if ($e instanceof \Transphporm\RunException) throw $e;
71
+			} catch (\Exception $e) {
72
+				if ($e instanceof \Transphporm\RunException) {
73
+					throw $e;
74
+				}
69 75
 				throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e);
70 76
 			}
71 77
 		}
Please login to merge, or discard this patch.
src/FunctionSet.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@  discard block
 block discarded – undo
20 20
 			if (isset($this->functions[$name])) {
21 21
 				return $this->functions[$name]->run($this->getArgs0($name, $args), $this->element);
22 22
 			}
23
-		}
24
-		catch (\Exception $e) {
23
+		} catch (\Exception $e) {
25 24
 			throw new RunException(Exception::TSS_FUNCTION, $name, $e);
26 25
 		}
27 26
 		return true;
@@ -32,8 +31,7 @@  discard block
 block discarded – undo
32 31
 			$tokens = $args[0];
33 32
 			$parser = new \Transphporm\Parser\Value($this);
34 33
 			return $parser->parseTokens($tokens, $this->elementData->getData($this->element));
35
-		}
36
-		else if ($args[0] instanceof Parser\Tokens) {
34
+		} else if ($args[0] instanceof Parser\Tokens) {
37 35
 			return iterator_to_array($args[0]);
38 36
 		}
39 37
 
Please login to merge, or discard this patch.
src/Hook/Formatter.php 1 patch
Braces   +7 added lines, -4 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 format($value, $rules) {
17
-		if (!isset($rules['format'])) return $value;
17
+		if (!isset($rules['format'])) {
18
+			return $value;
19
+		}
18 20
 		$tokens = $rules['format'];
19 21
 
20 22
 		$functionName = $tokens->from(\Transphporm\Parser\Tokenizer::NAME, true)->read();
@@ -27,15 +29,16 @@  discard block
 block discarded – undo
27 29
 
28 30
 		try {
29 31
 			return $this->processFormat($options, $functionName, $value);
30
-		}
31
-		catch (\Exception $e) {
32
+		} catch (\Exception $e) {
32 33
 			throw new \Transphporm\RunException(\Transphporm\Exception::FORMATTER, $functionName, $e);
33 34
 		}
34 35
 	}
35 36
 
36 37
 	//TODO: Abstract all error reporting externally with a method for turning it on/off
37 38
 	private function assert($condition, $error) {
38
-		if (!$condition) throw new \Exception($error);
39
+		if (!$condition) {
40
+			throw new \Exception($error);
41
+		}
39 42
 	}
40 43
 
41 44
 	private function processFormat($format, $functionName, $value) {
Please login to merge, or discard this patch.
src/Template.php 2 patches
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];
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 		 //Either return a whole DomDocument or return the output HTML
89 89
 		if ($document) return $this->document;
90 90
 
91
-		$output = ($this->document->doctype) ? call_user_func($this->save, $this->document->doctype) . "\n" : '';
91
+		$output = ($this->document->doctype) ? call_user_func($this->save, $this->document->doctype)."\n" : '';
92 92
 
93 93
 		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
94 94
 		else $output = $this->printDocument();
Please login to merge, or discard this patch.
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,12 +90,17 @@  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
 		$output = ($this->document->doctype) ? call_user_func($this->save, $this->document->doctype) . "\n" : '';
92 98
 
93
-		if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement);
94
-		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
+		}
95 104
 
96 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
97 106
 		$output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output);
Please login to merge, or discard this patch.
src/Pseudo/Nth.php 1 patch
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,25 +11,33 @@
 block discarded – undo
11 11
 	private $lastParentNode;
12 12
 
13 13
 	public function match($name, $args, \DomElement $element) {
14
-		if ($element->parentNode !== $this->lastParentNode) $this->count = 0;
14
+		if ($element->parentNode !== $this->lastParentNode) {
15
+			$this->count = 0;
16
+		}
15 17
 
16 18
 		$this->lastParentNode = $element->parentNode;
17 19
 
18 20
 
19 21
 
20
-		if ($name !== 'nth-child') return true;
22
+		if ($name !== 'nth-child') {
23
+			return true;
24
+		}
21 25
 
22 26
 		$this->count++;
23 27
 		$criteria = $args[0];
24 28
 
25
-		if (is_callable([$this, $criteria])) return $this->$criteria($this->count);
29
+		if (is_callable([$this, $criteria])) {
30
+			return $this->$criteria($this->count);
31
+		}
26 32
 		$this->assert(is_numeric($criteria), "Argument passed to 'nth-child' must be 'odd', 'even', or of type int");
27 33
 		return $this->count == $criteria;
28 34
 	}
29 35
 
30 36
 	//TODO: Abstract assertions throughout
31 37
 	private function assert($condition, $error) {
32
-		if (!$condition) throw new \Exception($error);
38
+		if (!$condition) {
39
+			throw new \Exception($error);
40
+		}
33 41
 	}
34 42
 
35 43
 	private function odd($num) {
Please login to merge, or discard this patch.
src/Parser/Value.php 1 patch
Braces   +23 added lines, -18 removed lines patch added patch discarded remove patch
@@ -54,7 +54,9 @@  discard block
 block discarded – undo
54 54
 		$this->last = null;
55 55
 		$this->traversing = false;
56 56
 
57
-		if (count($tokens) <= 0) return [$data];
57
+		if (count($tokens) <= 0) {
58
+			return [$data];
59
+		}
58 60
 
59 61
 		foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) {
60 62
 			$this->{$this->tokenFuncs[$token['type']]}($token);
@@ -76,16 +78,16 @@  discard block
 block discarded – undo
76 78
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
77 79
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
78 80
 	private function processDot($token) {
79
-		if ($this->last !== null) $this->data->traverse($this->last);
80
-		else {
81
+		if ($this->last !== null) {
82
+			$this->data->traverse($this->last);
83
+		} else {
81 84
 			//When . is not preceeded by anything, treat it as part of the string instead of an operator
82 85
 			// foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo"
83 86
 			$lastResult = $this->result->pop();
84 87
 			if ($lastResult) {
85 88
 				$this->data = new ValueData($lastResult);
86 89
 				$this->traversing = true;
87
-			}
88
-			else {
90
+			} else {
89 91
 				$this->processString(['value' => '.']);
90 92
 				$this->result->setMode(Tokenizer::CONCAT);
91 93
 			}
@@ -102,15 +104,19 @@  discard block
 block discarded – undo
102 104
 		$parser = new Value($this->baseData, $this->autoLookup);
103 105
 		if ($this->hasFunction($this->last)) {
104 106
 			$this->callTransphpormFunctions($token);
105
-		}
106
-		else {
107
-			if ($this->last !== null) $this->data->traverse($this->last);
108
-			else {
107
+		} else {
108
+			if ($this->last !== null) {
109
+				$this->data->traverse($this->last);
110
+			} else {
109 111
 				$lastResult = $this->result->pop();
110
-				if ($lastResult) $this->data = new ValueData($lastResult);
112
+				if ($lastResult) {
113
+					$this->data = new ValueData($lastResult);
114
+				}
111 115
 			}
112 116
 			$this->last = $parser->parseTokens($token['value'], null)[0];
113
-			if (!is_bool($this->last)) $this->traversing = true;
117
+			if (!is_bool($this->last)) {
118
+				$this->traversing = true;
119
+			}
114 120
 		}
115 121
 	}
116 122
 
@@ -130,8 +136,7 @@  discard block
 block discarded – undo
130 136
 		if ($this->hasFunction($this->last)
131 137
 			&& !$this->data->methodExists($this->last)) {
132 138
 			$this->callTransphpormFunctions($token);
133
-		}
134
-		else {
139
+		} else {
135 140
 			$this->processNested($token);
136 141
 		}
137 142
 	}
@@ -148,7 +153,9 @@  discard block
 block discarded – undo
148 153
 		foreach ($this->result->getResult() as $i => $value) {
149 154
 			if (is_scalar($value)) {
150 155
 				$val = $this->data->read($value);
151
-				if ($val) $this->result[$i] = $val;
156
+				if ($val) {
157
+					$this->result[$i] = $val;
158
+				}
152 159
 			}
153 160
 		}
154 161
 		$this->last = null;
@@ -160,8 +167,7 @@  discard block
 block discarded – undo
160 167
 			try {
161 168
 				$value = $this->data->extract($this->last, $this->autoLookup, $this->traversing);
162 169
 				$this->result->processValue($value);
163
-			}
164
-			catch (\UnexpectedValueException $e) {
170
+			} catch (\UnexpectedValueException $e) {
165 171
 				$this->processLastUnexpected();
166 172
 			}
167 173
 		}
@@ -170,8 +176,7 @@  discard block
 block discarded – undo
170 176
 	private function processLastUnexpected() {
171 177
 		if (!($this->autoLookup || $this->traversing)) {
172 178
 			$this->result->processValue($this->last);
173
-		}
174
-		else {
179
+		} else {
175 180
 			$this->result->clear();
176 181
 			$this->result[0] = false;
177 182
 		}
Please login to merge, or discard this patch.