Completed
Branch tokens-class (82c54a)
by Tom
03:42
created
src/Parser/Sheet.php 4 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 
85 85
 	private function import($args, $indexStart) {
86 86
 		$fileName = $args[0];
87
-		$sheet = new Sheet(file_get_contents($this->baseDir . $fileName), dirname(realpath($this->baseDir . $fileName)) . DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser);
87
+		$sheet = new Sheet(file_get_contents($this->baseDir.$fileName), dirname(realpath($this->baseDir.$fileName)).DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser);
88 88
 		return $sheet->parse($indexStart);
89 89
 	}
90 90
 
Please login to merge, or discard this patch.
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -13,6 +13,9 @@  discard block
 block discarded – undo
13 13
 	private $xPath;
14 14
 	private $tokenizer; 
15 15
 
16
+	/**
17
+	 * @param string $tss
18
+	 */
16 19
 	public function __construct($tss, $baseDir, CssToXpath $xPath, Value $valueParser) {
17 20
 		$this->tss = $this->stripComments($tss, '//', "\n");
18 21
 		$this->tss = $this->stripComments($this->tss, '/*', '*/');
@@ -44,6 +47,9 @@  discard block
 block discarded – undo
44 47
 		return $rules;
45 48
 	}
46 49
 
50
+	/**
51
+	 * @param integer $index
52
+	 */
47 53
 	private function CssToRules($selector, $index, $properties) {
48 54
 		$parts = $selector->trim()->splitOnToken(Tokenizer::ARG);
49 55
 		$rules = [];
@@ -67,6 +73,9 @@  discard block
 block discarded – undo
67 73
 		return $rules;
68 74
 	}
69 75
 
76
+	/**
77
+	 * @param integer $indexStart
78
+	 */
70 79
 	private function processingInstructions($token, $indexStart) {
71 80
 		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
72 81
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
@@ -90,6 +99,10 @@  discard block
 block discarded – undo
90 99
 		return ($a->depth < $b->depth) ? -1 : 1;
91 100
 	}
92 101
 
102
+	/**
103
+	 * @param string $open
104
+	 * @param string $close
105
+	 */
93 106
 	private function stripComments($str, $open, $close) {
94 107
 		$pos = 0;
95 108
 		while (($pos = strpos($str, $open, $pos)) !== false) {
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -102,14 +102,14 @@
 block discarded – undo
102 102
 	}
103 103
 
104 104
 	private function getProperties($tokens) {
105
-        $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON);
105
+		$rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON);
106 106
 
107
-        $return = [];
108
-        foreach ($rules as $rule) {
109
-            $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read();
110
-            $return[$name] = $rule->from(Tokenizer::COLON)->trim();
111
-        }
107
+		$return = [];
108
+		foreach ($rules as $rule) {
109
+			$name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read();
110
+			$return[$name] = $rule->from(Tokenizer::COLON)->trim();
111
+		}
112 112
 
113
-        return $return;
114
-    }
113
+		return $return;
114
+	}
115 115
 }
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,9 @@  discard block
 block discarded – undo
33 33
 			}
34 34
 			$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
35 35
 			$this->tss->skip(count($selector));
36
-			if (count($selector) === 0) break;
36
+			if (count($selector) === 0) {
37
+				break;
38
+			}
37 39
 
38 40
 			$newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value']));
39 41
 			$rules = $this->writeRule($rules, $newRules);
@@ -44,7 +46,9 @@  discard block
 block discarded – undo
44 46
 	}
45 47
 
46 48
 	private function checkError($rules) {
47
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
49
+		if (empty($rules) && count($this->tss) > 0) {
50
+			throw new \Exception('No TSS rules parsed');
51
+		}
48 52
 	}
49 53
 
50 54
 	private function CssToRules($selector, $index, $properties) {
@@ -71,7 +75,9 @@  discard block
 block discarded – undo
71 75
 	}
72 76
 
73 77
 	private function processingInstructions($token, $indexStart) {
74
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
78
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
79
+			return false;
80
+		}
75 81
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
76 82
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
77 83
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -88,7 +94,9 @@  discard block
 block discarded – undo
88 94
 
89 95
 	private function sortRules($a, $b) {
90 96
 		//If they have the same depth, compare on index
91
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
97
+		if ($a->depth === $b->depth) {
98
+			return $a->index < $b->index ? -1 : 1;
99
+		}
92 100
 
93 101
 		return ($a->depth < $b->depth) ? -1 : 1;
94 102
 	}
@@ -97,7 +105,9 @@  discard block
 block discarded – undo
97 105
 		$pos = 0;
98 106
 		while (($pos = strpos($str, $open, $pos)) !== false) {
99 107
 			$end = strpos($str, $close, $pos);
100
-			if ($end === false) break;
108
+			if ($end === false) {
109
+				break;
110
+			}
101 111
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
102 112
 		}
103 113
 
Please login to merge, or discard this patch.
src/Parser/CssToXpath.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@
 block discarded – undo
49 49
 		$functionSet->setElement($element[0]);
50 50
 
51 51
 		$attributes = array();
52
-        foreach($element[0]->attributes as $attribute_name => $attribute_node) {
53
-            $attributes[$attribute_name] = $attribute_node->nodeValue;
54
-        }
52
+		foreach($element[0]->attributes as $attribute_name => $attribute_node) {
53
+			$attributes[$attribute_name] = $attribute_node->nodeValue;
54
+		}
55 55
 
56
-        $parser = new \Transphporm\Parser\Value($functionSet, true);
56
+		$parser = new \Transphporm\Parser\Value($functionSet, true);
57 57
 		$return = $parser->parseTokens($attr, $attributes);
58 58
 
59 59
 		return $return[0] === '' ? false : $return[0];
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
 		$this->functionSet = $functionSet;
19 19
 
20 20
 		$this->translators = [
21
-			Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string;	},
22
-			'' => function($string) use ($prefix) { return '/' . $prefix . $string;	},
23
-			Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix  . $string; },
24
-			Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; },
25
-			Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; },
26
-			Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' . $hash . '")' . ']';	}
21
+			Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; },
22
+			'' => function($string) use ($prefix) { return '/'.$prefix.$string; },
23
+			Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; },
24
+			Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; },
25
+			Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; },
26
+			Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$hash.'")'.']'; }
27 27
 		];
28 28
 	}
29 29
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		$functionSet->setElement($element[0]);
48 48
 
49 49
 		$attributes = array();
50
-        foreach($element[0]->attributes as $attribute_name => $attribute_node) {
50
+        foreach ($element[0]->attributes as $attribute_name => $attribute_node) {
51 51
             $attributes[$attribute_name] = $attribute_node->nodeValue;
52 52
         }
53 53
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		$tokens = [];
79 79
 
80 80
 		foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) {
81
-			foreach ($token->trim() as $t) $tokens[]  = $t;
81
+			foreach ($token->trim() as $t) $tokens[] = $t;
82 82
 			$tokens[] = ['type' => Tokenizer::GREATER_THAN];
83 83
 		}
84 84
 		$tokens = new Tokens(array_slice($tokens, 0, -1));
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -69,7 +69,9 @@  discard block
 block discarded – undo
69 69
 				$selector->type = $token['type'];
70 70
 				$selectors[] = $selector;
71 71
 			}
72
-			if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value'];
72
+			if (isset($token['value'])) {
73
+				$selectors[count($selectors)-1]->string = $token['value'];
74
+			}
73 75
 		}
74 76
 		return $selectors;
75 77
 	}
@@ -78,7 +80,9 @@  discard block
 block discarded – undo
78 80
 		$tokens = [];
79 81
 
80 82
 		foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) {
81
-			foreach ($token->trim() as $t) $tokens[]  = $t;
83
+			foreach ($token->trim() as $t) {
84
+				$tokens[]  = $t;
85
+			}
82 86
 			$tokens[] = ['type' => Tokenizer::GREATER_THAN];
83 87
 		}
84 88
 		$tokens = new Tokens(array_slice($tokens, 0, -1));
@@ -87,7 +91,9 @@  discard block
 block discarded – undo
87 91
 		$selectors = $this->split($css);
88 92
 		$xpath = '/';
89 93
 		foreach ($selectors as $selector) {
90
-			if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath);
94
+			if (isset($this->translators[$selector->type])) {
95
+				$xpath .= $this->translators[$selector->type]($selector->string, $xpath);
96
+			}
91 97
 		}
92 98
 
93 99
 		$xpath = str_replace('/[', '/*[', $xpath);
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')[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')[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/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/Tokenizer.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			$string = $this->extractString($i);
122 122
 			$length = strlen($string)+1;
123 123
 			$char = $this->getChar($char);
124
-			$string = str_replace('\\' . $char, $char, $string);
124
+			$string = str_replace('\\'.$char, $char, $string);
125 125
 			$tokens[] = ['type' => self::STRING, 'value' => $string];
126 126
 			return $length;
127 127
 		}
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 				$str .= $chars[$token['type']];
165 165
 			}
166 166
 			if (isset($token['value'])) {
167
-				if ($token['value'] instanceof Tokens) $str.= $this->serialize($token['value']);
167
+				if ($token['value'] instanceof Tokens) $str .= $this->serialize($token['value']);
168 168
 				else $str .= $token['value'];	
169 169
 			}			
170 170
 		}
Please login to merge, or discard this patch.
Braces   +35 added lines, -14 removed lines patch added patch discarded remove patch
@@ -69,8 +69,11 @@  discard block
 block discarded – undo
69 69
 			$i += $this->doStrings($tokens, $char, $i);
70 70
 			$i += $this->doBrackets($tokens, $char, $i);
71 71
 		}
72
-		if ($returnObj) return new Tokens($tokens);
73
-		else return $tokens;
72
+		if ($returnObj) {
73
+			return new Tokens($tokens);
74
+		} else {
75
+			return $tokens;
76
+		}
74 77
 	}
75 78
 
76 79
 	private function doSimpleTokens(&$tokens, $char) {
@@ -93,10 +96,15 @@  discard block
 block discarded – undo
93 96
 	}
94 97
 
95 98
 	private function processLiterals(&$tokens, $name) {
96
-		if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name];
97
-		else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true];
98
-		else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false];
99
-		else $tokens[] = ['type' => self::NAME, 'value' => $name];
99
+		if (is_numeric($name)) {
100
+			$tokens[] = ['type' => self::NUMERIC, 'value' => $name];
101
+		} else if ($name == 'true') {
102
+			$tokens[] = ['type' => self::BOOL, 'value' => true];
103
+		} else if ($name == 'false') {
104
+			$tokens[] = ['type' => self::BOOL, 'value' => false];
105
+		} else {
106
+			$tokens[] = ['type' => self::NAME, 'value' => $name];
107
+		}
100 108
 	}
101 109
 
102 110
 	private function doBrackets(&$tokens, $char, $i) {
@@ -130,7 +138,9 @@  discard block
 block discarded – undo
130 138
 	private function extractString($pos) {
131 139
 		$char = $this->str[$pos];
132 140
 		$end = strpos($this->str, $char, $pos+1);
133
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
141
+		while ($end !== false && $this->str[$end-1] == '\\') {
142
+			$end = strpos($this->str, $char, $end+1);
143
+		}
134 144
 
135 145
 		return substr($this->str, $pos+1, $end-$pos-1);
136 146
 	}
@@ -139,19 +149,27 @@  discard block
 block discarded – undo
139 149
 		$close = strpos($this->str, $closeBracket, $open);
140 150
 
141 151
 		$cPos = $open+1;
142
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
152
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
153
+			$close = strpos($this->str, $closeBracket, $close+1);
154
+		}
143 155
 		return substr($this->str, $open+1, $close-$open-1);
144 156
 	}
145 157
 
146 158
 	private function identifyChar($chr) {
147
-		if (isset($this->chars[$chr])) return $this->chars[$chr];
148
-		else return self::NAME;
159
+		if (isset($this->chars[$chr])) {
160
+			return $this->chars[$chr];
161
+		} else {
162
+			return self::NAME;
163
+		}
149 164
 	}
150 165
 
151 166
 	private function getChar($num) {
152 167
 		$chars = array_reverse($this->chars);
153
-		if (isset($chars[$num])) return $chars[$num];
154
-		else return false;
168
+		if (isset($chars[$num])) {
169
+			return $chars[$num];
170
+		} else {
171
+			return false;
172
+		}
155 173
 	}
156 174
 
157 175
 	public function serialize($tokens) {
@@ -164,8 +182,11 @@  discard block
 block discarded – undo
164 182
 				$str .= $chars[$token['type']];
165 183
 			}
166 184
 			if (isset($token['value'])) {
167
-				if ($token['value'] instanceof Tokens) $str.= $this->serialize($token['value']);
168
-				else $str .= $token['value'];	
185
+				if ($token['value'] instanceof Tokens) {
186
+					$str.= $this->serialize($token['value']);
187
+				} else {
188
+					$str .= $token['value'];
189
+				}
169 190
 			}			
170 191
 		}
171 192
 
Please login to merge, or discard this patch.
src/Parser/Value.php 1 patch
Braces   +22 added lines, -16 removed lines patch added patch discarded remove patch
@@ -49,10 +49,14 @@  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 ($tokens as $token) {
55
-			if ($token['type'] !== Tokenizer::WHITESPACE) $this->{$this->tokenFuncs[$token['type']]}($token);
57
+			if ($token['type'] !== Tokenizer::WHITESPACE) {
58
+				$this->{$this->tokenFuncs[$token['type']]}($token);
59
+			}
56 60
 		}
57 61
 
58 62
 		$this->processLast();
@@ -71,13 +75,15 @@  discard block
 block discarded – undo
71 75
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
72 76
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
73 77
 	private function processDot($token) {
74
-		if ($this->last !== null) $this->data->traverse($this->last);
75
-		else {
78
+		if ($this->last !== null) {
79
+			$this->data->traverse($this->last);
80
+		} else {
76 81
 			//When . is not preceeded by anything, treat it as part of the string instead of an operator
77 82
 			// foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo"
78 83
 			$lastResult = $this->result->pop();
79
-			if ($lastResult) $this->data = new ValueData($lastResult);
80
-			else {
84
+			if ($lastResult) {
85
+				$this->data = new ValueData($lastResult);
86
+			} else {
81 87
 				$this->processString(['value' => '.']);
82 88
 				$this->result->setMode(Tokenizer::CONCAT);
83 89
 			}
@@ -90,9 +96,10 @@  discard block
 block discarded – undo
90 96
 		$parser = new Value($this->baseData, $this->autoLookup);
91 97
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
92 98
 			$this->callTransphpormFunctions($token);
93
-		}
94
-		else {
95
-			if ($this->last !== null) $this->data->traverse($this->last);
99
+		} else {
100
+			if ($this->last !== null) {
101
+				$this->data->traverse($this->last);
102
+			}
96 103
 			$this->last = $parser->parseTokens($token['value'], null)[0];
97 104
 		}
98 105
 	}
@@ -112,8 +119,7 @@  discard block
 block discarded – undo
112 119
 	private function processBrackets($token) {
113 120
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
114 121
 			$this->callTransphpormFunctions($token);
115
-		}
116
-		else {
122
+		} else {
117 123
 			$this->processNested($token);
118 124
 		}
119 125
 	}
@@ -130,7 +136,9 @@  discard block
 block discarded – undo
130 136
 		foreach ($this->result->getResult() as $i => $value) {
131 137
 			if (is_scalar($value)) {
132 138
 				$val = $this->data->read($value);
133
-				if ($val) $this->result[$i] = $val;
139
+				if ($val) {
140
+					$this->result[$i] = $val;
141
+				}
134 142
 			}
135 143
 		}
136 144
 		$this->last = null;
@@ -142,12 +150,10 @@  discard block
 block discarded – undo
142 150
 			try {
143 151
 				$value = $this->data->extract($this->last, $this->autoLookup);
144 152
 				$this->result->processValue($value);
145
-			}
146
-			catch (\UnexpectedValueException $e) {
153
+			} catch (\UnexpectedValueException $e) {
147 154
 				if (!$this->autoLookup) {
148 155
 					$this->result->processValue($this->last);
149
-				}
150
-				else {
156
+				} else {
151 157
 					$this->result->clear();
152 158
 					$this->result[0] = false;
153 159
 				}
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.
Braces   +23 added lines, -8 removed lines patch added patch discarded remove patch
@@ -51,19 +51,31 @@  discard block
 block discarded – undo
51 51
 
52 52
     public function from($tokenType, $inclusive = false) {
53 53
         $keys = $this->getKeysOfTokenType($tokenType);
54
-        if (count($keys) === 0) return new Tokens([]);
54
+        if (count($keys) === 0) {
55
+        	return new Tokens([]);
56
+        }
55 57
         $key = $keys[0];
56
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
57
-        if (!$inclusive) $key++;
58
+        for ($i = 0; $key < $this->iterator; $i++) {
59
+        	$key = $keys[$i];
60
+        }
61
+        if (!$inclusive) {
62
+        	$key++;
63
+        }
58 64
         return new Tokens(array_slice($this->tokens, $key));
59 65
     }
60 66
 
61 67
     public function to($tokenType, $inclusive = false) {
62 68
         $keys = $this->getKeysOfTokenType($tokenType);
63
-        if (empty($keys)) return new Tokens([]);
69
+        if (empty($keys)) {
70
+        	return new Tokens([]);
71
+        }
64 72
         $key = $keys[0];
65
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
66
-        if ($inclusive) $key++;
73
+        for ($i = 0; $key < $this->iterator; $i++) {
74
+        	$key = $keys[$i];
75
+        }
76
+        if ($inclusive) {
77
+        	$key++;
78
+        }
67 79
         return new Tokens(array_slice($this->tokens, 0, $key));
68 80
     }
69 81
 
@@ -75,8 +87,11 @@  discard block
 block discarded – undo
75 87
         $splitTokens = [];
76 88
 		$i = 0;
77 89
 		foreach ($this->tokens as $token) {
78
-			if ($token['type'] === $tokenType) $i++;
79
-			else $splitTokens[$i][] = $token;
90
+			if ($token['type'] === $tokenType) {
91
+				$i++;
92
+			} else {
93
+				$splitTokens[$i][] = $token;
94
+			}
80 95
 		}
81 96
         return array_map(function ($tokens) {
82 97
             return new Tokens($tokens);
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 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,63 +38,63 @@  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
-    }
41
+	private function getKeysOfTokenType($tokenType) {
42
+		return array_keys(array_column($this->tokens, 'type'), $tokenType);
43
+	}
44 44
 
45
-    public function from($tokenType, $inclusive = false) {
46
-        $keys = $this->getKeysOfTokenType($tokenType);
47
-        if (count($keys) === 0) return new Tokens([]);
48
-        $key = $keys[0];
49
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
50
-        if (!$inclusive) $key++;
51
-        return new Tokens(array_slice($this->tokens, $key));
52
-    }
45
+	public function from($tokenType, $inclusive = false) {
46
+		$keys = $this->getKeysOfTokenType($tokenType);
47
+		if (count($keys) === 0) return new Tokens([]);
48
+		$key = $keys[0];
49
+		for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
50
+		if (!$inclusive) $key++;
51
+		return new Tokens(array_slice($this->tokens, $key));
52
+	}
53 53
 
54
-    public function to($tokenType, $inclusive = false) {
55
-        $keys = $this->getKeysOfTokenType($tokenType);
56
-        if (empty($keys)) return new Tokens([]);
57
-        $key = $keys[0];
58
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
59
-        if ($inclusive) $key++;
60
-        return new Tokens(array_slice($this->tokens, 0, $key));
61
-    }
54
+	public function to($tokenType, $inclusive = false) {
55
+		$keys = $this->getKeysOfTokenType($tokenType);
56
+		if (empty($keys)) return new Tokens([]);
57
+		$key = $keys[0];
58
+		for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
59
+		if ($inclusive) $key++;
60
+		return new Tokens(array_slice($this->tokens, 0, $key));
61
+	}
62 62
 
63
-    public function skip($count) {
64
-        $this->iterator += $count;
65
-    }
63
+	public function skip($count) {
64
+		$this->iterator += $count;
65
+	}
66 66
 
67
-    public function splitOnToken($tokenType) {
68
-        $splitTokens = [];
67
+	public function splitOnToken($tokenType) {
68
+		$splitTokens = [];
69 69
 		$i = 0;
70 70
 		foreach ($this->tokens as $token) {
71 71
 			if ($token['type'] === $tokenType) $i++;
72 72
 			else $splitTokens[$i][] = $token;
73 73
 		}
74
-        return array_map(function ($tokens) {
75
-            return new Tokens($tokens);
76
-        }, $splitTokens);
74
+		return array_map(function ($tokens) {
75
+			return new Tokens($tokens);
76
+		}, $splitTokens);
77 77
 		//return $splitTokens;
78
-    }
78
+	}
79 79
 
80
-    public function trim() {
81
-        $tokens = $this->tokens;
82
-        // Remove end whitespace
83
-        while (end($tokens)['type'] === Tokenizer::WHITESPACE) {
84
-            array_pop($tokens);
85
-        }
86
-        // Remove begining whitespace
87
-        while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) {
88
-            array_shift($tokens);
89
-        }
90
-        return new Tokens($tokens);
91
-    }
80
+	public function trim() {
81
+		$tokens = $this->tokens;
82
+		// Remove end whitespace
83
+		while (end($tokens)['type'] === Tokenizer::WHITESPACE) {
84
+			array_pop($tokens);
85
+		}
86
+		// Remove begining whitespace
87
+		while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) {
88
+			array_shift($tokens);
89
+		}
90
+		return new Tokens($tokens);
91
+	}
92 92
 
93
-    public function read($offset = 0) {
94
-        return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false;
95
-    }
93
+	public function read($offset = 0) {
94
+		return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false;
95
+	}
96 96
 
97
-    public function type($offset = 0) {
98
-        return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false;   
99
-    }
97
+	public function type($offset = 0) {
98
+		return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false;   
99
+	}
100 100
 }
Please login to merge, or discard this patch.