@@ -155,6 +155,10 @@ |
||
| 155 | 155 | |
| 156 | 156 | //Extracts $last from $data. If "last" is "bar" from value "foo.bar", |
| 157 | 157 | //$data contains "foo" and this function reads $data[$bar] or $data->$bar |
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param ValueResult|null $result |
|
| 161 | + */ |
|
| 158 | 162 | private function extractLast($result) { |
| 159 | 163 | if ($this->autoLookup && isset($this->data->{$this->last})) { |
| 160 | 164 | return $this->result->processValue($this->data->{$this->last}); |
@@ -51,7 +51,9 @@ discard block |
||
| 51 | 51 | $this->data = $data; |
| 52 | 52 | $this->last = null; |
| 53 | 53 | |
| 54 | - if (empty($tokens)) return [$this->data]; |
|
| 54 | + if (empty($tokens)) { |
|
| 55 | + return [$this->data]; |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | foreach ($tokens as $token) { |
| 57 | 59 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -66,27 +68,36 @@ discard block |
||
| 66 | 68 | |
| 67 | 69 | if ($this->result->getMode() == Tokenizer::NOT && $token['type'] == Tokenizer::EQUALS) { |
| 68 | 70 | $this->result->setMode(Tokenizer::NOT); |
| 71 | + } else { |
|
| 72 | + $this->result->setMode($token['type']); |
|
| 69 | 73 | } |
| 70 | - else $this->result->setMode($token['type']); |
|
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | |
| 74 | 77 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
| 75 | 78 | private function moveLastToData() { |
| 76 | - if (isset($this->data->{$this->last})) $this->data = $this->data->{$this->last}; |
|
| 77 | - else if (is_array($this->data) && isset($this->data[$this->last])) $this->data = $this->data[$this->last]; |
|
| 79 | + if (isset($this->data->{$this->last})) { |
|
| 80 | + $this->data = $this->data->{$this->last}; |
|
| 81 | + } else if (is_array($this->data) && isset($this->data[$this->last])) { |
|
| 82 | + $this->data = $this->data[$this->last]; |
|
| 83 | + } |
|
| 78 | 84 | } |
| 79 | 85 | |
| 80 | 86 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
| 81 | 87 | private function processDot($token) { |
| 82 | - if ($this->last !== null) $this->moveLastToData(); |
|
| 83 | - else $this->data = $this->result->pop(); |
|
| 88 | + if ($this->last !== null) { |
|
| 89 | + $this->moveLastToData(); |
|
| 90 | + } else { |
|
| 91 | + $this->data = $this->result->pop(); |
|
| 92 | + } |
|
| 84 | 93 | |
| 85 | 94 | $this->last = null; |
| 86 | 95 | } |
| 87 | 96 | |
| 88 | 97 | private function processSquareBracket($token) { |
| 89 | - if ($this->last !== null) $this->moveLastToData(); |
|
| 98 | + if ($this->last !== null) { |
|
| 99 | + $this->moveLastToData(); |
|
| 100 | + } |
|
| 90 | 101 | $parser = new Value($this->baseData, $this->autoLookup); |
| 91 | 102 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
| 92 | 103 | } |
@@ -108,15 +119,15 @@ discard block |
||
| 108 | 119 | private function processBrackets($token) { |
| 109 | 120 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
| 110 | 121 | $this->callTransphpormFunctions($token); |
| 111 | - } |
|
| 112 | - else if ($this->data instanceof \Transphporm\Functionset) { |
|
| 122 | + } else if ($this->data instanceof \Transphporm\Functionset) { |
|
| 113 | 123 | $this->result = $this->result->processValue($this->data->{$this->last}($token['value'])); |
| 114 | 124 | $this->last = null; |
| 115 | - } |
|
| 116 | - else { |
|
| 125 | + } else { |
|
| 117 | 126 | $parser = new Value($this->baseData, $this->autoLookup); |
| 118 | 127 | $args = $parser->parseTokens($token['value'], $this->data); |
| 119 | - if ($args[0] == $this->data) $args = []; |
|
| 128 | + if ($args[0] == $this->data) { |
|
| 129 | + $args = []; |
|
| 130 | + } |
|
| 120 | 131 | $funcResult = $this->callFunc($this->last, $args, $this->data); |
| 121 | 132 | $this->result->processValue($funcResult); |
| 122 | 133 | $this->last = null; |
@@ -127,9 +138,12 @@ discard block |
||
| 127 | 138 | $this->result->processValue($this->baseData->{$this->last}($token['value'])); |
| 128 | 139 | foreach ($this->result->getResult() as $i => $value) { |
| 129 | 140 | if (is_array($this->data)) { |
| 130 | - if (isset($this->data[$value])) $this->result[$i] = $this->data[$value]; |
|
| 141 | + if (isset($this->data[$value])) { |
|
| 142 | + $this->result[$i] = $this->data[$value]; |
|
| 143 | + } |
|
| 144 | + } else if (is_scalar($value) && isset($this->data->$value)) { |
|
| 145 | + $this->result[$i] = $this->data->$value; |
|
| 131 | 146 | } |
| 132 | - else if (is_scalar($value) && isset($this->data->$value)) $this->result[$i] = $this->data->$value; |
|
| 133 | 147 | } |
| 134 | 148 | $this->last = null; |
| 135 | 149 | } |
@@ -139,12 +153,10 @@ discard block |
||
| 139 | 153 | if ($this->last !== null) { |
| 140 | 154 | try { |
| 141 | 155 | $this->extractLast($this->result); |
| 142 | - } |
|
| 143 | - catch (\UnexpectedValueException $e) { |
|
| 156 | + } catch (\UnexpectedValueException $e) { |
|
| 144 | 157 | if (!$this->autoLookup) { |
| 145 | 158 | $this->result->processValue($this->last); |
| 146 | - } |
|
| 147 | - else { |
|
| 159 | + } else { |
|
| 148 | 160 | $this->result->clear(); |
| 149 | 161 | $this->result[0] = false; |
| 150 | 162 | } |
@@ -158,8 +170,7 @@ discard block |
||
| 158 | 170 | private function extractLast($result) { |
| 159 | 171 | if ($this->autoLookup && isset($this->data->{$this->last})) { |
| 160 | 172 | return $this->result->processValue($this->data->{$this->last}); |
| 161 | - } |
|
| 162 | - else if (is_array($this->data) && isset($this->data[$this->last])) { |
|
| 173 | + } else if (is_array($this->data) && isset($this->data[$this->last])) { |
|
| 163 | 174 | return $this->result->processValue($this->data[$this->last]); |
| 164 | 175 | } |
| 165 | 176 | throw new \UnexpectedValueException('Not found'); |
@@ -170,7 +181,10 @@ discard block |
||
| 170 | 181 | } |
| 171 | 182 | |
| 172 | 183 | private function callFuncOnObject($obj, $func, $args) { |
| 173 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
| 174 | - else return call_user_func_array([$obj, $func], $args); |
|
| 184 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
| 185 | + return call_user_func_array($obj->$func, $args); |
|
| 186 | + } else { |
|
| 187 | + return call_user_func_array([$obj, $func], $args); |
|
| 188 | + } |
|
| 175 | 189 | } |
| 176 | 190 | } |
| 177 | 191 | \ No newline at end of file |