Completed
Pull Request — master (#116)
by Richard
02:24
created
src/Pseudo/Nth.php 1 patch
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,7 +9,9 @@  discard block
 block discarded – undo
9 9
 class Nth implements \Transphporm\Pseudo {
10 10
 
11 11
 	public function match($name, $args, \DomElement $element) {
12
-		if ($name !== 'nth-child') return true;
12
+		if ($name !== 'nth-child') {
13
+			return true;
14
+		}
13 15
 
14 16
 		$criteria = $args[0];
15 17
 
@@ -18,8 +20,11 @@  discard block
 block discarded – undo
18 20
 		$pseudo = $tokenizer->getTokens();
19 21
 		$num = end($pseudo)['value'][0]['value'];
20 22
 
21
-		if (is_callable([$this, $criteria])) return $this->$criteria($num);
22
-		else return $num == $criteria;
23
+		if (is_callable([$this, $criteria])) {
24
+			return $this->$criteria($num);
25
+		} else {
26
+			return $num == $criteria;
27
+		}
23 28
 	}
24 29
 
25 30
 	private function odd($num) {
Please login to merge, or discard this patch.
src/Pseudo/Not.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
 	}
17 17
 
18 18
 	public function match($name, $args, \DomElement $element) {
19
-		if ($name !== 'not') return true;
19
+		if ($name !== 'not') {
20
+			return true;
21
+		}
20 22
 		
21 23
 		$xpath = new \DomXpath($element->ownerDocument);
22 24
 		return $this->notElement($args, $xpath, $element);
@@ -29,7 +31,9 @@  discard block
 block discarded – undo
29 31
 			//Find all nodes matched by the expressions in the brackets :not(EXPR)
30 32
 			foreach ($xpath->query($xpathString) as $matchedElement) {
31 33
 				//Check to see whether this node was matched by the not query
32
-				if ($element->isSameNode($matchedElement)) return false;
34
+				if ($element->isSameNode($matchedElement)) {
35
+					return false;
36
+				}
33 37
 			}
34 38
 		}
35 39
 		return true;
Please login to merge, or discard this patch.
src/Builder.php 1 patch
Braces   +21 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,7 +26,9 @@  discard block
 block discarded – undo
26 26
 		$this->cache = new Cache(new \ArrayObject());
27 27
 
28 28
 		$modules = is_array($modules) ? $modules : $this->defaultModules;
29
-		foreach ($modules as $module) $this->loadModule(new $module);
29
+		foreach ($modules as $module) {
30
+			$this->loadModule(new $module);
31
+		}
30 32
 	}
31 33
 
32 34
 	//Allow setting the time used by Transphporm for caching. This is for testing purposes
@@ -51,7 +53,9 @@  discard block
 block discarded – undo
51 53
 		$valueParser = new Parser\Value($data);
52 54
 		$config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($valueParser, $data, $template->getPrefix()), $headers, $this->baseDir);
53 55
 
54
-		foreach ($this->modules as $module) $module->load($config);
56
+		foreach ($this->modules as $module) {
57
+			$module->load($config);
58
+		}
55 59
 
56 60
 		$this->processRules($template, $config);
57 61
 
@@ -66,7 +70,9 @@  discard block
 block discarded – undo
66 70
 		$rules = $this->getRules($template, $config);
67 71
 
68 72
 		foreach ($rules as $rule) {
69
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
73
+			if ($rule->shouldRun($this->time)) {
74
+				$this->executeTssRule($rule, $template, $config);
75
+			}
70 76
 		}
71 77
 	}
72 78
 
@@ -82,7 +88,9 @@  discard block
 block discarded – undo
82 88
 
83 89
 		// TODO: Once `Sheet` uses tokens this can be removed
84 90
 		$pseudo = [];
85
-		foreach ($rule->pseudo as $pseudoString) $pseudo[] = (new \Transphporm\Parser\Tokenizer($pseudoString))->getTokens();
91
+		foreach ($rule->pseudo as $pseudoString) {
92
+			$pseudo[] = (new \Transphporm\Parser\Tokenizer($pseudoString))->getTokens();
93
+		}
86 94
 
87 95
 		$pseudoMatcher = $config->createPseudoMatcher($pseudo);
88 96
 
@@ -96,8 +104,9 @@  discard block
 block discarded – undo
96 104
 		if (trim($this->template)[0] !== '<') {
97 105
 			$xml = $this->cache->load($this->template, filemtime($this->template));
98 106
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
107
+		} else {
108
+			return ['body' => $this->template, 'headers' => []];
99 109
 		}
100
-		else return ['body' => $this->template, 'headers' => []];
101 110
 	}
102 111
 
103 112
 	//Load the TSS rules either from a file or as a string
@@ -112,10 +121,14 @@  discard block
 block discarded – undo
112 121
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
113 122
 			$rules = $this->cache->load($key, filemtime($this->tss));
114 123
 
115
-			if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse());
116
-			else return $rules;
124
+			if (!$rules) {
125
+				return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse());
126
+			} else {
127
+				return $rules;
128
+			}
129
+		} else {
130
+			return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse();
117 131
 		}
118
-		else return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse();
119 132
 	}
120 133
 
121 134
 	public function setCache(\ArrayAccess $cache) {
Please login to merge, or discard this patch.
src/Hook/PseudoMatcher.php 1 patch
Braces   +13 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,20 +41,26 @@  discard block
 block discarded – undo
41 41
 		$parts['name'] = $this->getFuncName($tokens);
42 42
 		if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) {
43 43
 			$parts['args'] = $this->valueParser->parseTokens($tokens, $this->functionSet);
44
+		} elseif (isset($tokens[1])) {
45
+			$parts['args'] = $this->valueParser->parseTokens($tokens[1]['value'], $this->functionSet);
46
+		} else {
47
+			$parts['args'] = [['']];
44 48
 		}
45
-		elseif (isset($tokens[1])) $parts['args'] = $this->valueParser->parseTokens($tokens[1]['value'], $this->functionSet);
46
-		else $parts['args'] = [['']];
47 49
 		return $parts;
48 50
 	}
49 51
 
50 52
 	private function getFuncName($tokens) {
51
-		if ($tokens[0]['type'] === Tokenizer::NAME) return $tokens[0]['value'];
53
+		if ($tokens[0]['type'] === Tokenizer::NAME) {
54
+			return $tokens[0]['value'];
55
+		}
52 56
 		return null;
53 57
 	}
54 58
 
55 59
 	public function hasFunction($name) {
56 60
 		foreach ($this->pseudo as $tokens) {
57
-			if ($name === $this->getFuncName($tokens)) return true;
61
+			if ($name === $this->getFuncName($tokens)) {
62
+				return true;
63
+			}
58 64
 		}
59 65
 	}
60 66
 
@@ -64,7 +70,9 @@  discard block
 block discarded – undo
64 70
 
65 71
 		foreach ($this->pseudo as $tokens) {
66 72
 			$parts = $this->getFuncParts($tokens);
67
-			if ($name === $parts['name']) return $parts['args'];
73
+			if ($name === $parts['name']) {
74
+				return $parts['args'];
75
+			}
68 76
 		}
69 77
 	}
70 78
 }
Please login to merge, or discard this patch.
src/Property/Content.php 1 patch
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,15 +18,20 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
21
-		if (!$this->shouldRun($element)) return false;
21
+		if (!$this->shouldRun($element)) {
22
+			return false;
23
+		}
22 24
 		$values = $this->fixValues($this->formatter->format($values, $rules));
23 25
 
24 26
 		if (!$this->processPseudo($values, $element, $pseudoMatcher)) {
25 27
 			//Remove the current contents
26 28
 			$this->removeAllChildren($element);
27 29
 			//Now make a text node
28
-			if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values);
29
-			else $this->appendContent($element, $values);
30
+			if ($this->getContentMode($rules) === 'replace') {
31
+				$this->replaceContent($element, $values);
32
+			} else {
33
+				$this->appendContent($element, $values);
34
+			}
30 35
 		}
31 36
 	}
32 37
 
@@ -38,7 +43,9 @@  discard block
 block discarded – undo
38 43
 
39 44
 	private function shouldRun($element) {
40 45
 		do {
41
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
46
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
47
+				return false;
48
+			}
42 49
 		}
43 50
 		while (($element = $element->parentNode) instanceof \DomElement);
44 51
 		return true;
@@ -65,9 +72,10 @@  discard block
 block discarded – undo
65 72
 				$new = $document->importNode($n, true);
66 73
 				//Removing this might cause problems with caching...
67 74
 				//$new->setAttribute('transphporm', 'added');
68
-			}
69
-			else {
70
-				if ($n instanceof \DomText) $n = $n->nodeValue;
75
+			} else {
76
+				if ($n instanceof \DomText) {
77
+					$n = $n->nodeValue;
78
+				}
71 79
 				$new = $document->createElement('text');
72 80
 
73 81
 				$new->appendChild($document->createTextNode($n));
@@ -114,6 +122,8 @@  discard block
 block discarded – undo
114 122
 	}
115 123
 
116 124
 	private function removeAllChildren($element) {
117
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
125
+		while ($element->hasChildNodes()) {
126
+			$element->removeChild($element->firstChild);
127
+		}
118 128
 	}
119 129
 }
Please login to merge, or discard this patch.
src/Property/Display.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,8 +7,12 @@
 block discarded – undo
7 7
 namespace Transphporm\Property;
8 8
 class Display implements \Transphporm\Property {
9 9
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
10
-		if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr', $element)[0]);
11
-		else if (strtolower($values[0]) === 'none') $element->setAttribute('transphporm', 'remove');
12
-		else $element->setAttribute('transphporm', 'show');
10
+		if ($pseudoMatcher->hasFunction('attr')) {
11
+			$element->removeAttribute($pseudoMatcher->getFuncArgs('attr', $element)[0]);
12
+		} else if (strtolower($values[0]) === 'none') {
13
+			$element->setAttribute('transphporm', 'remove');
14
+		} else {
15
+			$element->setAttribute('transphporm', 'show');
16
+		}
13 17
 	}
14 18
 }
Please login to merge, or discard this patch.
src/Pseudo/Attribute.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@
 block discarded – undo
14 14
 	}
15 15
 
16 16
 	public function match($name, $args, \DomElement $element) {
17
-		if (!($name === null || in_array($name, ['data', 'iteration', 'root'])))  return true;
17
+		if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) {
18
+			return true;
19
+		}
18 20
 		return $args[0];
19 21
 	}
20 22
 }
Please login to merge, or discard this patch.