Completed
Push — master ( ed50b2...c7ae95 )
by Richard
02:27
created
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 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@
 block discarded – undo
94 94
 		if ($lastResult) {
95 95
 			$this->traversing = true;
96 96
 		}
97
-		else if ($this->last === null)  {
97
+		else if ($this->last === null) {
98 98
 			$this->processString(['value' => '.']);
99 99
 			$this->result->setMode(Tokenizer::CONCAT);
100 100
 		}
Please login to merge, or discard this patch.
Braces   +11 added lines, -12 removed lines patch added patch discarded remove patch
@@ -56,7 +56,9 @@  discard block
 block discarded – undo
56 56
 		$this->last = null;
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->traversing = true;
87
-		}
88
-		else if ($this->last === null)  {
89
+		} else if ($this->last === null)  {
89 90
 			$this->processString(['value' => '.']);
90 91
 			$this->result->setMode(Tokenizer::CONCAT);
91 92
 		}
@@ -101,11 +102,12 @@  discard block
 block discarded – undo
101 102
 		$parser = new Value($this->baseData, $this->autoLookup);
102 103
 		if ($this->hasFunction($this->last)) {
103 104
 			$this->callTransphpormFunctions($token);
104
-		}
105
-		else {
105
+		} else {
106 106
 			$this->data->traverse($this->last, $this->result);
107 107
 			$this->last = $parser->parseTokens($token['value'], null)[0];
108
-			if (!is_bool($this->last)) $this->traversing = true;
108
+			if (!is_bool($this->last)) {
109
+				$this->traversing = true;
110
+			}
109 111
 		}
110 112
 	}
111 113
 
@@ -125,8 +127,7 @@  discard block
 block discarded – undo
125 127
 		if ($this->hasFunction($this->last)
126 128
 			&& !$this->data->methodExists($this->last)) {
127 129
 			$this->callTransphpormFunctions($token);
128
-		}
129
-		else {
130
+		} else {
130 131
 			$this->processNested($token);
131 132
 		}
132 133
 	}
@@ -156,8 +157,7 @@  discard block
 block discarded – undo
156 157
 			try {
157 158
 				$value = $this->data->extract($this->last, $this->autoLookup, $this->traversing);
158 159
 				$this->result->processValue($value);
159
-			}
160
-			catch (\UnexpectedValueException $e) {
160
+			} catch (\UnexpectedValueException $e) {
161 161
 				$this->processLastUnexpected();
162 162
 			}
163 163
 		}
@@ -166,8 +166,7 @@  discard block
 block discarded – undo
166 166
 	private function processLastUnexpected() {
167 167
 		if (!($this->autoLookup || $this->traversing)) {
168 168
 			$this->result->processValue($this->last);
169
-		}
170
-		else {
169
+		} else {
171 170
 			$this->result->clear();
172 171
 			$this->result->write(0, false);
173 172
 		}
Please login to merge, or discard this patch.
src/Hook/PseudoMatcher.php 1 patch
Braces   +19 added lines, -10 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@  discard block
 block discarded – undo
25 25
 		foreach ($this->pseudo as $tokens) {
26 26
 			foreach ($this->functions as $function) {
27 27
 				$matches = $this->match($tokens, $function, $element);
28
-				if ($matches === false) return false;
28
+				if ($matches === false) {
29
+					return false;
30
+				}
29 31
 			}
30 32
 		}
31 33
 		return true;
@@ -35,9 +37,10 @@  discard block
 block discarded – undo
35 37
 		try {
36 38
 			$parts = $this->getFuncParts($tokens);
37 39
 			$matches = $function->match($parts['name'], $parts['args'], $element);
38
-			if ($matches === false) return false;
39
-		}
40
-		catch (\Exception $e) {
40
+			if ($matches === false) {
41
+				return false;
42
+			}
43
+		} catch (\Exception $e) {
41 44
 			throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e);
42 45
 		}
43 46
 	}
@@ -46,31 +49,37 @@  discard block
 block discarded – undo
46 49
 		$parts['name'] = $this->getFuncName($tokens);
47 50
 		if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) {
48 51
 			$parts['args'] = $this->valueParser->parseTokens($tokens);
49
-		}
50
-		else if (count($tokens) > 1) {
52
+		} else if (count($tokens) > 1) {
51 53
 			$tokens->rewind();
52 54
 			$tokens->next();
53 55
 			$parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']);
56
+		} else {
57
+			$parts['args'] = [['']];
54 58
 		}
55
-		else $parts['args'] = [['']];
56 59
 		return $parts;
57 60
 	}
58 61
 
59 62
 	private function getFuncName($tokens) {
60
-		if ($tokens->type() === Tokenizer::NAME) return $tokens->read();
63
+		if ($tokens->type() === Tokenizer::NAME) {
64
+			return $tokens->read();
65
+		}
61 66
 		return null;
62 67
 	}
63 68
 
64 69
 	public function hasFunction($name) {
65 70
 		foreach ($this->pseudo as $tokens) {
66
-			if ($name === $this->getFuncName($tokens)) return true;
71
+			if ($name === $this->getFuncName($tokens)) {
72
+				return true;
73
+			}
67 74
 		}
68 75
 	}
69 76
 
70 77
 	public function getFuncArgs($name) {
71 78
 		foreach ($this->pseudo as $tokens) {
72 79
 			$parts = $this->getFuncParts($tokens);
73
-			if ($name === $parts['name']) return $parts['args'];
80
+			if ($name === $parts['name']) {
81
+				return $parts['args'];
82
+			}
74 83
 		}
75 84
 	}
76 85
 }
Please login to merge, or discard this patch.
src/Property/Repeat.php 3 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -11,6 +11,9 @@  discard block
 block discarded – undo
11 11
 	private $line;
12 12
     private $filePath;
13 13
 
14
+	/**
15
+	 * @param integer $line
16
+	 */
14 17
 	public function __construct(\Transphporm\FunctionSet $functionSet, \Transphporm\Hook\ElementData $elementData, &$line, \Transphporm\FilePath $filePath) {
15 18
 		$this->functionSet = $functionSet;
16 19
 		$this->elementData = $elementData;
@@ -58,6 +61,12 @@  discard block
 block discarded – undo
58 61
 		return $value;
59 62
 	}
60 63
 
64
+	/**
65
+	 * @param \DOMElement $element
66
+	 * @param integer $count
67
+	 *
68
+	 * @return \DOMElement
69
+	 */
61 70
 	private function cloneElement($element, $iteration, $key, $count) {
62 71
 		$clone = $element->cloneNode(true);
63 72
 		$this->tagElement($clone, $count);
@@ -77,6 +86,9 @@  discard block
 block discarded – undo
77 86
 		return isset($values[1]) ? $values[1] : PHP_INT_MAX;
78 87
 	}
79 88
 
89
+	/**
90
+	 * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher
91
+	 */
80 92
 	private function createHook($newRules, $pseudoMatcher, $properties) {
81 93
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $this->line, null, $this->line, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet, $this->filePath);
82 94
 		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@
 block discarded – undo
9 9
 	private $functionSet;
10 10
 	private $elementData;
11 11
 	private $line;
12
-    private $filePath;
12
+	private $filePath;
13 13
 
14 14
 	public function __construct(\Transphporm\FunctionSet $functionSet, \Transphporm\Hook\ElementData $elementData, &$line, \Transphporm\FilePath $filePath) {
15 15
 		$this->functionSet = $functionSet;
16 16
 		$this->elementData = $elementData;
17 17
 		$this->line = &$line;
18
-        $this->filePath = $filePath;
18
+		$this->filePath = $filePath;
19 19
 	}
20 20
 
21 21
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
Please login to merge, or discard this patch.
Braces   +18 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
22 22
 		$values = $this->fixEmpty($values);
23
-		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
23
+		if ($element->getAttribute('transphporm') === 'added') {
24
+			return $element->parentNode->removeChild($element);
25
+		}
24 26
 		$max = $this->getMax($values);
25 27
 		$count = 0;
26 28
 		$repeat = $this->getRepeatValue($values, $max);
@@ -29,7 +31,9 @@  discard block
 block discarded – undo
29 31
 		$hook = $this->createHook($rules, $pseudoMatcher, $properties);
30 32
 
31 33
 		foreach ($repeat as $key => $iteration) {
32
-			if ($count+1 > $max) break;
34
+			if ($count+1 > $max) {
35
+				break;
36
+			}
33 37
 			$clone = $this->cloneElement($element, $iteration, $key, $count++);
34 38
 			//Re-run the hook on the new element, but use the iterated data
35 39
 			$hook->run($clone);
@@ -41,8 +45,9 @@  discard block
 block discarded – undo
41 45
 
42 46
 	private function getRepeatValue($values, &$max) {
43 47
 		$mode = $this->getMode($values);
44
-		if ($mode === 'each') $repeat = $values[0];
45
-		else if ($mode === 'loop') {
48
+		if ($mode === 'each') {
49
+			$repeat = $values[0];
50
+		} else if ($mode === 'loop') {
46 51
 			$repeat = range($values[0], $max);
47 52
 			$max++;
48 53
 		}
@@ -54,7 +59,9 @@  discard block
 block discarded – undo
54 59
 	}
55 60
 
56 61
 	private function fixEmpty($value) {
57
-		if (empty($value[0])) $value[0] = [];
62
+		if (empty($value[0])) {
63
+			$value[0] = [];
64
+		}
58 65
 		return $value;
59 66
 	}
60 67
 
@@ -70,7 +77,9 @@  discard block
 block discarded – undo
70 77
 
71 78
 	private function tagElement($element, $count) {
72 79
 		//Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed
73
-		if ($count > 0) $element->setAttribute('transphporm', 'added');
80
+		if ($count > 0) {
81
+			$element->setAttribute('transphporm', 'added');
82
+		}
74 83
 	}
75 84
 
76 85
 	private function getMax($values) {
@@ -79,7 +88,9 @@  discard block
 block discarded – undo
79 88
 
80 89
 	private function createHook($newRules, $pseudoMatcher, $properties) {
81 90
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $this->line, null, $this->line, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet, $this->filePath);
82
-		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
91
+		foreach ($properties as $name => $property) {
92
+			$hook->registerProperty($name, $property);
93
+		}
83 94
 		return $hook;
84 95
 	}
85 96
 }
Please login to merge, or discard this patch.
src/Hook/PropertyHook.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 	private $functionSet;
18 18
 
19 19
 	public function __construct(array $rules, &$configLine, $file, $line, PseudoMatcher $pseudoMatcher,
20
-            \Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) {
20
+			\Transphporm\Parser\Value $valueParser, \Transphporm\FunctionSet $functionSet, \Transphporm\FilePath $filePath) {
21 21
 		$this->rules = $rules;
22 22
 		$this->configLine = &$configLine;
23 23
 		$this->file = $file;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 		$this->valueParser = $valueParser;
26 26
 		$this->pseudoMatcher = $pseudoMatcher;
27 27
 		$this->functionSet = $functionSet;
28
-		if ($this->file !== null) $filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR);
28
+		if ($this->file !== null) $filePath->setBaseDir(dirname(realpath($this->file)).DIRECTORY_SEPARATOR);
29 29
 	}
30 30
 
31 31
 	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
@@ -25,7 +25,9 @@  discard block
 block discarded – undo
25 25
 		$this->valueParser = $valueParser;
26 26
 		$this->pseudoMatcher = $pseudoMatcher;
27 27
 		$this->functionSet = $functionSet;
28
-		if ($this->file !== null) $filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR);
28
+		if ($this->file !== null) {
29
+			$filePath->setBaseDir(dirname(realpath($this->file)) . DIRECTORY_SEPARATOR);
30
+		}
29 31
 	}
30 32
 
31 33
 	public function run(\DomElement $element) {
@@ -33,10 +35,11 @@  discard block
 block discarded – undo
33 35
 		$this->configLine = $this->line;
34 36
 		try {
35 37
 			//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
36
-			if (!$this->pseudoMatcher->matches($element)) return;
38
+			if (!$this->pseudoMatcher->matches($element)) {
39
+				return;
40
+			}
37 41
 			$this->callProperties($element);
38
-		}
39
-		catch (\Transphporm\RunException $e) {
42
+		} catch (\Transphporm\RunException $e) {
40 43
 			throw new \Transphporm\Exception($e, $this->file, $this->line);
41 44
 		}
42 45
 	}
@@ -47,7 +50,9 @@  discard block
 block discarded – undo
47 50
 	private function callProperties($element) {
48 51
 		foreach ($this->rules as $name => $value) {
49 52
 			$result = $this->callProperty($name, $element, $this->getArgs($value));
50
-			if ($result === false) break;
53
+			if ($result === false) {
54
+				break;
55
+			}
51 56
 		}
52 57
 	}
53 58
 	private function getArgs($value) {
@@ -62,9 +67,10 @@  discard block
 block discarded – undo
62 67
 		if (isset($this->properties[$name])) {
63 68
 			try {
64 69
 				return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
65
-			}
66
-			catch (\Exception $e) {
67
-				if ($e instanceof \Transphporm\RunException) throw $e;
70
+			} catch (\Exception $e) {
71
+				if ($e instanceof \Transphporm\RunException) {
72
+					throw $e;
73
+				}
68 74
 				throw new \Transphporm\RunException(\Transphporm\Exception::PROPERTY, $name, $e);
69 75
 			}
70 76
 		}
Please login to merge, or discard this patch.
src/Parser/Last.php 1 patch
Braces   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,8 +28,9 @@  discard block
 block discarded – undo
28 28
 
29 29
 
30 30
 	public function traverse() {
31
-		if ($this->last !== null) $this->data->traverse($this->last);
32
-		else {
31
+		if ($this->last !== null) {
32
+			$this->data->traverse($this->last);
33
+		} else {
33 34
 			$lastResult = $this->result->pop();
34 35
 			if ($lastResult) {
35 36
 				$this->data = new ValueData($lastResult);
@@ -67,8 +68,7 @@  discard block
 block discarded – undo
67 68
 			try {
68 69
 				$value = $this->data->extract($this->last, $this->autoLookup, $this->traversing);
69 70
 				$this->result->processValue($value);
70
-			}
71
-			catch (\UnexpectedValueException $e) {
71
+			} catch (\UnexpectedValueException $e) {
72 72
 				$this->processLastUnexpected();
73 73
 			}
74 74
 		}
@@ -77,8 +77,7 @@  discard block
 block discarded – undo
77 77
 	private function processLastUnexpected() {
78 78
 		if (!($this->autoLookup || $this->traversing)) {
79 79
 			$this->result->processValue($this->last);
80
-		}
81
-		else {
80
+		} else {
82 81
 			$this->result->clear();
83 82
 			$this->result[0] = false;
84 83
 		}
Please login to merge, or discard this patch.
src/Parser/Tokenizer.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@
 block discarded – undo
145 145
 			$string = $this->extractString($i);
146 146
 			$length = strlen($string)+1;
147 147
 			$char = $this->getChar($char);
148
-			$string = str_replace('\\' . $char, $char, $string);
148
+			$string = str_replace('\\'.$char, $char, $string);
149 149
 			$tokens[] = ['type' => self::STRING, 'value' => $string, 'line' => $this->lineNo];
150 150
 			return $length;
151 151
 		}
Please login to merge, or discard this patch.
Braces   +30 added lines, -12 removed lines patch added patch discarded remove patch
@@ -79,8 +79,11 @@  discard block
 block discarded – undo
79 79
 			$i += $this->doStrings($tokens, $char, $i);
80 80
 			$i += $this->doBrackets($tokens, $char, $i);
81 81
 		}
82
-		if ($returnObj) return new Tokens($tokens);
83
-		else return $tokens;
82
+		if ($returnObj) {
83
+			return new Tokens($tokens);
84
+		} else {
85
+			return $tokens;
86
+		}
84 87
 	}
85 88
 
86 89
 	private function doSimpleTokens(&$tokens, $char) {
@@ -117,10 +120,15 @@  discard block
 block discarded – undo
117 120
 	}
118 121
 
119 122
 	private function processLiterals(&$tokens, $name) {
120
-		if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name];
121
-		else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true];
122
-		else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false];
123
-		else $tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo];
123
+		if (is_numeric($name)) {
124
+			$tokens[] = ['type' => self::NUMERIC, 'value' => $name];
125
+		} else if ($name == 'true') {
126
+			$tokens[] = ['type' => self::BOOL, 'value' => true];
127
+		} else if ($name == 'false') {
128
+			$tokens[] = ['type' => self::BOOL, 'value' => false];
129
+		} else {
130
+			$tokens[] = ['type' => self::NAME, 'value' => $name, 'line' => $this->lineNo];
131
+		}
124 132
 	}
125 133
 
126 134
 	private function doBrackets(&$tokens, $char, $i) {
@@ -154,7 +162,9 @@  discard block
 block discarded – undo
154 162
 	private function extractString($pos) {
155 163
 		$char = $this->str[$pos];
156 164
 		$end = strpos($this->str, $char, $pos+1);
157
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
165
+		while ($end !== false && $this->str[$end-1] == '\\') {
166
+			$end = strpos($this->str, $char, $end+1);
167
+		}
158 168
 
159 169
 		return substr($this->str, $pos+1, $end-$pos-1);
160 170
 	}
@@ -163,18 +173,26 @@  discard block
 block discarded – undo
163 173
 		$close = strpos($this->str, $closeBracket, $open);
164 174
 
165 175
 		$cPos = $open+1;
166
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
176
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
177
+			$close = strpos($this->str, $closeBracket, $close+1);
178
+		}
167 179
 		return substr($this->str, $open+1, $close-$open-1);
168 180
 	}
169 181
 
170 182
 	private function identifyChar($chr) {
171
-		if (isset($this->chars[$chr])) return $this->chars[$chr];
172
-		else return self::NAME;
183
+		if (isset($this->chars[$chr])) {
184
+			return $this->chars[$chr];
185
+		} else {
186
+			return self::NAME;
187
+		}
173 188
 	}
174 189
 
175 190
 	private function getChar($num) {
176 191
 		$chars = array_reverse($this->chars);
177
-		if (isset($chars[$num])) return $chars[$num];
178
-		else return false;
192
+		if (isset($chars[$num])) {
193
+			return $chars[$num];
194
+		} else {
195
+			return false;
196
+		}
179 197
 	}
180 198
 }
Please login to merge, or discard this patch.