@@ -20,11 +20,15 @@ discard block |
||
20 | 20 | |
21 | 21 | public function run(\DomElement $element) { |
22 | 22 | //Don't run if there's a pseudo element like nth-child() and this element doesn't match it |
23 | - if (!$this->pseudoMatcher->matches($element)) return; |
|
23 | + if (!$this->pseudoMatcher->matches($element)) { |
|
24 | + return; |
|
25 | + } |
|
24 | 26 | |
25 | 27 | foreach ($this->rules as $name => $value) { |
26 | 28 | $result = $this->callProperty($name, $element, $this->valueParser->parse(trim($value), $element)); |
27 | - if ($result === false) break; |
|
29 | + if ($result === false) { |
|
30 | + break; |
|
31 | + } |
|
28 | 32 | } |
29 | 33 | } |
30 | 34 | |
@@ -45,7 +49,9 @@ discard block |
||
45 | 49 | } |
46 | 50 | |
47 | 51 | private function callProperty($name, $element, $value) { |
48 | - if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
52 | + if (isset($this->properties[$name])) { |
|
53 | + return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties); |
|
54 | + } |
|
49 | 55 | return false; |
50 | 56 | } |
51 | 57 | } |
@@ -14,7 +14,9 @@ |
||
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(); |
@@ -39,31 +39,37 @@ |
||
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 | } |
@@ -20,8 +20,7 @@ |
||
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])) { |
@@ -51,19 +51,31 @@ discard block |
||
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 |
||
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); |
@@ -35,6 +35,8 @@ |
||
35 | 35 | |
36 | 36 | public function rewind() { |
37 | 37 | $this->tokens->rewind(); |
38 | - while ($this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore)) $this->tokens->next(); |
|
38 | + while ($this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore)) { |
|
39 | + $this->tokens->next(); |
|
40 | + } |
|
39 | 41 | } |
40 | 42 | } |
41 | 43 | \ No newline at end of file |
@@ -33,7 +33,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -49,7 +49,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -69,8 +69,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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) { |
@@ -169,8 +187,11 @@ discard block |
||
169 | 187 | |
170 | 188 | private function serializeValue($token) { |
171 | 189 | if (isset($token['value'])) { |
172 | - if ($token['value'] instanceof Tokens) return $this->serialize($token['value']); |
|
173 | - else return $token['value']; |
|
190 | + if ($token['value'] instanceof Tokens) { |
|
191 | + return $this->serialize($token['value']); |
|
192 | + } else { |
|
193 | + return $token['value']; |
|
194 | + } |
|
174 | 195 | } |
175 | 196 | } |
176 | 197 | } |