Completed
Push — master ( 1ce981...0b7883 )
by Tom
02:21
created
src/Cache.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,8 @@
 block discarded – undo
21 21
 		$key = md5($key);
22 22
 		if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) {
23 23
 			return $this->cache[$key]['content'];
24
+		} else {
25
+			return false;
24 26
 		}
25
-		else return false;
26 27
 	}
27 28
 }
28 29
\ No newline at end of file
Please login to merge, or discard this patch.
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.