@@ -94,7 +94,7 @@ |
||
| 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 | } |
@@ -54,7 +54,9 @@ discard block |
||
| 54 | 54 | $this->last = null; |
| 55 | 55 | $this->traversing = false; |
| 56 | 56 | |
| 57 | - if (count($tokens) <= 0) return [$data]; |
|
| 57 | + if (count($tokens) <= 0) { |
|
| 58 | + return [$data]; |
|
| 59 | + } |
|
| 58 | 60 | |
| 59 | 61 | foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) { |
| 60 | 62 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -74,8 +76,9 @@ discard block |
||
| 74 | 76 | } |
| 75 | 77 | |
| 76 | 78 | private function traverseLast() { |
| 77 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
| 78 | - else { |
|
| 79 | + if ($this->last !== null) { |
|
| 80 | + $this->data->traverse($this->last); |
|
| 81 | + } else { |
|
| 79 | 82 | $lastResult = $this->result->pop(); |
| 80 | 83 | if ($lastResult) { |
| 81 | 84 | $this->data = new ValueData($lastResult); |
@@ -93,8 +96,7 @@ discard block |
||
| 93 | 96 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
| 94 | 97 | if ($lastResult) { |
| 95 | 98 | $this->traversing = true; |
| 96 | - } |
|
| 97 | - else if ($this->last === null) { |
|
| 99 | + } else if ($this->last === null) { |
|
| 98 | 100 | $this->processString(['value' => '.']); |
| 99 | 101 | $this->result->setMode(Tokenizer::CONCAT); |
| 100 | 102 | } |
@@ -110,11 +112,12 @@ discard block |
||
| 110 | 112 | $parser = new Value($this->baseData, $this->autoLookup); |
| 111 | 113 | if ($this->hasFunction($this->last)) { |
| 112 | 114 | $this->callTransphpormFunctions($token); |
| 113 | - } |
|
| 114 | - else { |
|
| 115 | + } else { |
|
| 115 | 116 | $this->traverseLast(); |
| 116 | 117 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
| 117 | - if (!is_bool($this->last)) $this->traversing = true; |
|
| 118 | + if (!is_bool($this->last)) { |
|
| 119 | + $this->traversing = true; |
|
| 120 | + } |
|
| 118 | 121 | } |
| 119 | 122 | } |
| 120 | 123 | |
@@ -134,8 +137,7 @@ discard block |
||
| 134 | 137 | if ($this->hasFunction($this->last) |
| 135 | 138 | && !$this->data->methodExists($this->last)) { |
| 136 | 139 | $this->callTransphpormFunctions($token); |
| 137 | - } |
|
| 138 | - else { |
|
| 140 | + } else { |
|
| 139 | 141 | $this->processNested($token); |
| 140 | 142 | } |
| 141 | 143 | } |
@@ -152,7 +154,9 @@ discard block |
||
| 152 | 154 | foreach ($this->result->getResult() as $i => $value) { |
| 153 | 155 | if (is_scalar($value)) { |
| 154 | 156 | $val = $this->data->read($value); |
| 155 | - if ($val) $this->result[$i] = $val; |
|
| 157 | + if ($val) { |
|
| 158 | + $this->result[$i] = $val; |
|
| 159 | + } |
|
| 156 | 160 | } |
| 157 | 161 | } |
| 158 | 162 | $this->last = null; |
@@ -164,8 +168,7 @@ discard block |
||
| 164 | 168 | try { |
| 165 | 169 | $value = $this->data->extract($this->last, $this->autoLookup, $this->traversing); |
| 166 | 170 | $this->result->processValue($value); |
| 167 | - } |
|
| 168 | - catch (\UnexpectedValueException $e) { |
|
| 171 | + } catch (\UnexpectedValueException $e) { |
|
| 169 | 172 | $this->processLastUnexpected(); |
| 170 | 173 | } |
| 171 | 174 | } |
@@ -174,8 +177,7 @@ discard block |
||
| 174 | 177 | private function processLastUnexpected() { |
| 175 | 178 | if (!($this->autoLookup || $this->traversing)) { |
| 176 | 179 | $this->result->processValue($this->last); |
| 177 | - } |
|
| 178 | - else { |
|
| 180 | + } else { |
|
| 179 | 181 | $this->result->clear(); |
| 180 | 182 | $this->result[0] = false; |
| 181 | 183 | } |
@@ -25,7 +25,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |