Completed
Push — master ( 479b8e...e72ae9 )
by Richard
02:38
created
src/Hook/Formatter.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 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();
Please login to merge, or discard this patch.
src/Hook/PseudoMatcher.php 1 patch
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,31 +39,37 @@
 block discarded – undo
39 39
 		$parts['name'] = $this->getFuncName($tokens);
40 40
 		if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) {
41 41
 			$parts['args'] = $this->valueParser->parseTokens($tokens);
42
-		}
43
-		else if (count($tokens) > 1) {
42
+		} else if (count($tokens) > 1) {
44 43
 			$tokens->rewind();
45 44
 			$tokens->next();
46 45
 			$parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']);
46
+		} else {
47
+			$parts['args'] = [['']];
47 48
 		}
48
-		else $parts['args'] = [['']];
49 49
 		return $parts;
50 50
 	}
51 51
 
52 52
 	private function getFuncName($tokens) {
53
-		if ($tokens->type() === Tokenizer::NAME) return $tokens->read();
53
+		if ($tokens->type() === Tokenizer::NAME) {
54
+			return $tokens->read();
55
+		}
54 56
 		return null;
55 57
 	}
56 58
 
57 59
 	public function hasFunction($name) {
58 60
 		foreach ($this->pseudo as $tokens) {
59
-			if ($name === $this->getFuncName($tokens)) return true;
61
+			if ($name === $this->getFuncName($tokens)) {
62
+				return true;
63
+			}
60 64
 		}
61 65
 	}
62 66
 
63 67
 	public function getFuncArgs($name) {
64 68
 		foreach ($this->pseudo as $tokens) {
65 69
 			$parts = $this->getFuncParts($tokens);
66
-			if ($name === $parts['name']) return $parts['args'];
70
+			if ($name === $parts['name']) {
71
+				return $parts['args'];
72
+			}
67 73
 		}
68 74
 	}
69 75
 }
Please login to merge, or discard this patch.
src/FunctionSet.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@
 block discarded – undo
20 20
 			$tokens = $args[0];
21 21
 			$parser = new \Transphporm\Parser\Value($this);
22 22
 			$args[0] = $parser->parseTokens($tokens, $this->elementData->getData($this->element));
23
-		}
24
-		else if ($args[0] instanceof Parser\Tokens) {
23
+		} else if ($args[0] instanceof Parser\Tokens) {
25 24
 			$args[0] = iterator_to_array($args[0]);
26 25
 		}
27 26
 		if (isset($this->functions[$name])) {
Please login to merge, or discard this patch.
src/Parser/Tokens.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
 			if ($token['type'] === $tokenType) $i++;
79 79
 			else $splitTokens[$i][] = $token;
80 80
 		}
81
-        return array_map(function ($tokens) {
81
+        return array_map(function($tokens) {
82 82
             return new Tokens($tokens);
83 83
         }, $splitTokens);
84 84
 		//return $splitTokens;
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -6,28 +6,28 @@  discard block
 block discarded – undo
6 6
  * @version         1.0                                                             */
7 7
 namespace Transphporm\Parser;
8 8
 class Tokens implements \Iterator, \Countable {
9
-    private $tokens;
10
-    private $iterator = 0;
9
+	private $tokens;
10
+	private $iterator = 0;
11 11
 
12
-    public function __construct(array $tokens) {
13
-        $this->tokens = $tokens;
14
-    }
12
+	public function __construct(array $tokens) {
13
+		$this->tokens = $tokens;
14
+	}
15 15
 
16
-    public function count() {
17
-        return count($this->tokens);
18
-    }
16
+	public function count() {
17
+		return count($this->tokens);
18
+	}
19 19
 
20
-    // Iterator Functions
21
-    public function current() {
22
-        return $this->tokens[$this->iterator];
23
-    }
20
+	// Iterator Functions
21
+	public function current() {
22
+		return $this->tokens[$this->iterator];
23
+	}
24 24
 
25
-    public function key() {
26
-        return $this->iterator;
27
-    }
25
+	public function key() {
26
+		return $this->iterator;
27
+	}
28 28
 
29
-    public function next() {
30
-        ++$this->iterator;
29
+	public function next() {
30
+		++$this->iterator;
31 31
 	}
32 32
 
33 33
 	public function valid() {
@@ -38,67 +38,67 @@  discard block
 block discarded – undo
38 38
 		$this->iterator = 0;
39 39
 	}
40 40
 
41
-    private function getKeysOfTokenType($tokenType) {
42
-        return array_keys(array_column($this->tokens, 'type'), $tokenType);
43
-    }
44
-
45
-    private function getKeyToSlice($tokenType) {
46
-        $keys = $this->getKeysOfTokenType($tokenType);
47
-        if (empty($keys)) return false;
48
-        $key = $keys[0];
49
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
50
-        return $key;
51
-    }
52
-
53
-    public function from($tokenType, $inclusive = false) {
54
-        $key = $this->getKeyToSlice($tokenType);
55
-        if ($key === false) return new Tokens([]);
56
-        if (!$inclusive) $key++;
57
-        return new Tokens(array_slice($this->tokens, $key));
58
-    }
59
-
60
-    public function to($tokenType, $inclusive = false) {
61
-        $key = $this->getKeyToSlice($tokenType);
62
-        if ($key === false) return new Tokens([]);
63
-        if ($inclusive) $key++;
64
-        return new Tokens(array_slice($this->tokens, 0, $key));
65
-    }
66
-
67
-    public function skip($count) {
68
-        $this->iterator += $count;
69
-    }
70
-
71
-    public function splitOnToken($tokenType) {
72
-        $splitTokens = [];
41
+	private function getKeysOfTokenType($tokenType) {
42
+		return array_keys(array_column($this->tokens, 'type'), $tokenType);
43
+	}
44
+
45
+	private function getKeyToSlice($tokenType) {
46
+		$keys = $this->getKeysOfTokenType($tokenType);
47
+		if (empty($keys)) return false;
48
+		$key = $keys[0];
49
+		for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
50
+		return $key;
51
+	}
52
+
53
+	public function from($tokenType, $inclusive = false) {
54
+		$key = $this->getKeyToSlice($tokenType);
55
+		if ($key === false) return new Tokens([]);
56
+		if (!$inclusive) $key++;
57
+		return new Tokens(array_slice($this->tokens, $key));
58
+	}
59
+
60
+	public function to($tokenType, $inclusive = false) {
61
+		$key = $this->getKeyToSlice($tokenType);
62
+		if ($key === false) return new Tokens([]);
63
+		if ($inclusive) $key++;
64
+		return new Tokens(array_slice($this->tokens, 0, $key));
65
+	}
66
+
67
+	public function skip($count) {
68
+		$this->iterator += $count;
69
+	}
70
+
71
+	public function splitOnToken($tokenType) {
72
+		$splitTokens = [];
73 73
 		$i = 0;
74 74
 		foreach ($this->tokens as $token) {
75 75
 			if ($token['type'] === $tokenType) $i++;
76 76
 			else $splitTokens[$i][] = $token;
77 77
 		}
78
-        return array_map(function ($tokens) {
79
-            return new Tokens($tokens);
80
-        }, $splitTokens);
78
+		return array_map(function ($tokens) {
79
+			return new Tokens($tokens);
80
+		}, $splitTokens);
81 81
 		//return $splitTokens;
82
-    }
83
-
84
-    public function trim() {
85
-        $tokens = $this->tokens;
86
-        // Remove end whitespace
87
-        while (end($tokens)['type'] === Tokenizer::WHITESPACE) {
88
-            array_pop($tokens);
89
-        }
90
-        // Remove begining whitespace
91
-        while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) {
92
-            array_shift($tokens);
93
-        }
94
-        return new Tokens($tokens);
95
-    }
96
-
97
-    public function read($offset = 0) {
98
-        return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false;
99
-    }
100
-
101
-    public function type($offset = 0) {
102
-        return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false;
103
-    }
82
+	}
83
+
84
+	public function trim() {
85
+		$tokens = $this->tokens;
86
+		// Remove end whitespace
87
+		while (end($tokens)['type'] === Tokenizer::WHITESPACE) {
88
+			array_pop($tokens);
89
+		}
90
+		// Remove begining whitespace
91
+		while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) {
92
+			array_shift($tokens);
93
+		}
94
+		return new Tokens($tokens);
95
+	}
96
+
97
+	public function read($offset = 0) {
98
+		return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false;
99
+	}
100
+
101
+	public function type($offset = 0) {
102
+		return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false;
103
+	}
104 104
 }
Please login to merge, or discard this patch.
Braces   +23 added lines, -8 removed lines patch added patch discarded remove patch
@@ -44,23 +44,35 @@  discard block
 block discarded – undo
44 44
 
45 45
     private function getKeyToSlice($tokenType) {
46 46
         $keys = $this->getKeysOfTokenType($tokenType);
47
-        if (empty($keys)) return false;
47
+        if (empty($keys)) {
48
+        	return false;
49
+        }
48 50
         $key = $keys[0];
49
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
51
+        for ($i = 0; $key < $this->iterator; $i++) {
52
+        	$key = $keys[$i];
53
+        }
50 54
         return $key;
51 55
     }
52 56
 
53 57
     public function from($tokenType, $inclusive = false) {
54 58
         $key = $this->getKeyToSlice($tokenType);
55
-        if ($key === false) return new Tokens([]);
56
-        if (!$inclusive) $key++;
59
+        if ($key === false) {
60
+        	return new Tokens([]);
61
+        }
62
+        if (!$inclusive) {
63
+        	$key++;
64
+        }
57 65
         return new Tokens(array_slice($this->tokens, $key));
58 66
     }
59 67
 
60 68
     public function to($tokenType, $inclusive = false) {
61 69
         $key = $this->getKeyToSlice($tokenType);
62
-        if ($key === false) return new Tokens([]);
63
-        if ($inclusive) $key++;
70
+        if ($key === false) {
71
+        	return new Tokens([]);
72
+        }
73
+        if ($inclusive) {
74
+        	$key++;
75
+        }
64 76
         return new Tokens(array_slice($this->tokens, 0, $key));
65 77
     }
66 78
 
@@ -72,8 +84,11 @@  discard block
 block discarded – undo
72 84
         $splitTokens = [];
73 85
 		$i = 0;
74 86
 		foreach ($this->tokens as $token) {
75
-			if ($token['type'] === $tokenType) $i++;
76
-			else $splitTokens[$i][] = $token;
87
+			if ($token['type'] === $tokenType) {
88
+				$i++;
89
+			} else {
90
+				$splitTokens[$i][] = $token;
91
+			}
77 92
 		}
78 93
         return array_map(function ($tokens) {
79 94
             return new Tokens($tokens);
Please login to merge, or discard this patch.
src/Property/Repeat.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,12 +18,16 @@  discard block
 block discarded – undo
18 18
 
19 19
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
20 20
 		$values = $this->fixEmpty($values);
21
-		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
21
+		if ($element->getAttribute('transphporm') === 'added') {
22
+			return $element->parentNode->removeChild($element);
23
+		}
22 24
 		$max = $this->getMax($values);
23 25
 		$count = 0;
24 26
 
25 27
 		foreach ($values[0] as $key => $iteration) {
26
-			if ($count+1 > $max) break;
28
+			if ($count+1 > $max) {
29
+				break;
30
+			}
27 31
 			$clone = $this->cloneElement($element, $iteration, $key, $count++);
28 32
 			//Re-run the hook on the new element, but use the iterated data
29 33
 			//Don't run repeat on the clones element or it will loop forever
@@ -36,7 +40,9 @@  discard block
 block discarded – undo
36 40
 	}
37 41
 
38 42
 	private function fixEmpty($value) {
39
-		if (empty($value[0])) $value[0] = [];
43
+		if (empty($value[0])) {
44
+			$value[0] = [];
45
+		}
40 46
 		return $value;
41 47
 	}
42 48
 
@@ -52,7 +58,9 @@  discard block
 block discarded – undo
52 58
 
53 59
 	private function tagElement($element, $count) {
54 60
 		//Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed
55
-		if ($count > 0) $element->setAttribute('transphporm', 'added');
61
+		if ($count > 0) {
62
+			$element->setAttribute('transphporm', 'added');
63
+		}
56 64
 	}
57 65
 
58 66
 	private function getMax($values) {
@@ -61,7 +69,9 @@  discard block
 block discarded – undo
61 69
 
62 70
 	private function createHook($newRules, $pseudoMatcher, $properties) {
63 71
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $this->baseDir, $this->baseDir, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet);
64
-		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
72
+		foreach ($properties as $name => $property) {
73
+			$hook->registerProperty($name, $property);
74
+		}
65 75
 		return $hook;
66 76
 	}
67 77
 }
Please login to merge, or discard this patch.
src/Parser/Value.php 1 patch
Braces   +19 added lines, -15 removed lines patch added patch discarded remove patch
@@ -49,7 +49,9 @@  discard block
 block discarded – undo
49 49
 		$this->data = new ValueData($data ? $data : $this->baseData);
50 50
 		$this->last = null;
51 51
 
52
-		if (count($tokens) <= 0) return [$data];
52
+		if (count($tokens) <= 0) {
53
+			return [$data];
54
+		}
53 55
 
54 56
 		foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE]) as $token) {
55 57
 			$this->{$this->tokenFuncs[$token['type']]}($token);
@@ -71,13 +73,15 @@  discard block
 block discarded – undo
71 73
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
72 74
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
73 75
 	private function processDot($token) {
74
-		if ($this->last !== null) $this->data->traverse($this->last);
75
-		else {
76
+		if ($this->last !== null) {
77
+			$this->data->traverse($this->last);
78
+		} else {
76 79
 			//When . is not preceeded by anything, treat it as part of the string instead of an operator
77 80
 			// foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo"
78 81
 			$lastResult = $this->result->pop();
79
-			if ($lastResult) $this->data = new ValueData($lastResult);
80
-			else {
82
+			if ($lastResult) {
83
+				$this->data = new ValueData($lastResult);
84
+			} else {
81 85
 				$this->processString(['value' => '.']);
82 86
 				$this->result->setMode(Tokenizer::CONCAT);
83 87
 			}
@@ -90,9 +94,10 @@  discard block
 block discarded – undo
90 94
 		$parser = new Value($this->baseData, $this->autoLookup);
91 95
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
92 96
 			$this->callTransphpormFunctions($token);
93
-		}
94
-		else {
95
-			if ($this->last !== null) $this->data->traverse($this->last);
97
+		} else {
98
+			if ($this->last !== null) {
99
+				$this->data->traverse($this->last);
100
+			}
96 101
 			$this->last = $parser->parseTokens($token['value'], null)[0];
97 102
 		}
98 103
 	}
@@ -112,8 +117,7 @@  discard block
 block discarded – undo
112 117
 	private function processBrackets($token) {
113 118
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
114 119
 			$this->callTransphpormFunctions($token);
115
-		}
116
-		else {
120
+		} else {
117 121
 			$this->processNested($token);
118 122
 		}
119 123
 	}
@@ -130,7 +134,9 @@  discard block
 block discarded – undo
130 134
 		foreach ($this->result->getResult() as $i => $value) {
131 135
 			if (is_scalar($value)) {
132 136
 				$val = $this->data->read($value);
133
-				if ($val) $this->result[$i] = $val;
137
+				if ($val) {
138
+					$this->result[$i] = $val;
139
+				}
134 140
 			}
135 141
 		}
136 142
 		$this->last = null;
@@ -142,12 +148,10 @@  discard block
 block discarded – undo
142 148
 			try {
143 149
 				$value = $this->data->extract($this->last, $this->autoLookup);
144 150
 				$this->result->processValue($value);
145
-			}
146
-			catch (\UnexpectedValueException $e) {
151
+			} catch (\UnexpectedValueException $e) {
147 152
 				if (!$this->autoLookup) {
148 153
 					$this->result->processValue($this->last);
149
-				}
150
-				else {
154
+				} else {
151 155
 					$this->result->clear();
152 156
 					$this->result[0] = false;
153 157
 				}
Please login to merge, or discard this patch.
src/Config.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,12 +67,16 @@
 block discarded – undo
67 67
 	}
68 68
 
69 69
 	public function loadProperties(Hook\PropertyHook $hook) {
70
-		foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property);
70
+		foreach ($this->properties as $name => $property) {
71
+			$hook->registerProperty($name, $property);
72
+		}
71 73
 	}
72 74
 
73 75
 	public function createPseudoMatcher($pseudo) {
74 76
 		$pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser);
75
-		foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction);
77
+		foreach ($this->pseudo as $pseudoFunction) {
78
+			$pseudoMatcher->registerFunction(clone $pseudoFunction);
79
+		}
76 80
 		return $pseudoMatcher;
77 81
 	}
78 82
 
Please login to merge, or discard this patch.
src/Pseudo/Nth.php 1 patch
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,14 +11,19 @@
 block discarded – undo
11 11
 
12 12
 	public function match($name, $args, \DomElement $element) {
13 13
 		
14
-		if ($name !== 'nth-child') return true;
14
+		if ($name !== 'nth-child') {
15
+			return true;
16
+		}
15 17
 
16 18
 		$this->count++;
17 19
 		$criteria = $args[0];
18 20
 
19 21
 
20
-		if (is_callable([$this, $criteria])) return $this->$criteria($this->count);
21
-		else return $this->count == $criteria;
22
+		if (is_callable([$this, $criteria])) {
23
+			return $this->$criteria($this->count);
24
+		} else {
25
+			return $this->count == $criteria;
26
+		}
22 27
 	}
23 28
 
24 29
 	private function odd($num) {
Please login to merge, or discard this patch.
src/Parser/TokenFilterIterator.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
  * @version         1.0                                                             */
7 7
 namespace Transphporm\Parser;
8 8
 class TokenFilterIterator implements \Iterator {
9
-    private $ignore;
10
-    private $tokens;
9
+	private $ignore;
10
+	private $tokens;
11 11
 
12
-    public function __construct(Tokens $tokens, array $ignore) {
13
-        $this->ignore = $ignore;
14
-        $this->tokens = $tokens;
15
-    }
12
+	public function __construct(Tokens $tokens, array $ignore) {
13
+		$this->ignore = $ignore;
14
+		$this->tokens = $tokens;
15
+	}
16 16
 
17
-    public function current() {
18
-        return $this->tokens->current();
19
-    }
17
+	public function current() {
18
+		return $this->tokens->current();
19
+	}
20 20
 
21
-    public function key() {
22
-        return $this->tokens->key();
23
-    }
21
+	public function key() {
22
+		return $this->tokens->key();
23
+	}
24 24
 
25
-    public function valid() {
26
-        return $this->tokens->valid();
27
-    }
25
+	public function valid() {
26
+		return $this->tokens->valid();
27
+	}
28 28
 
29
-    public function next() {
30
-        do {
31
-            $this->tokens->next();
32
-        }
33
-        while ($this->shouldContinue());
34
-    }
29
+	public function next() {
30
+		do {
31
+			$this->tokens->next();
32
+		}
33
+		while ($this->shouldContinue());
34
+	}
35 35
 
36
-    public function rewind() {
37
-        $this->tokens->rewind();
38
-        while ($this->shouldContinue()) $this->tokens->next();
39
-    }
36
+	public function rewind() {
37
+		$this->tokens->rewind();
38
+		while ($this->shouldContinue()) $this->tokens->next();
39
+	}
40 40
 
41
-    private function shouldContinue() {
42
-        return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore);
43
-    }
41
+	private function shouldContinue() {
42
+		return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore);
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@
 block discarded – undo
35 35
 
36 36
     public function rewind() {
37 37
         $this->tokens->rewind();
38
-        while ($this->shouldContinue()) $this->tokens->next();
38
+        while ($this->shouldContinue()) {
39
+        	$this->tokens->next();
40
+        }
39 41
     }
40 42
 
41 43
     private function shouldContinue() {
Please login to merge, or discard this patch.