@@ -34,6 +34,9 @@ discard block |
||
| 34 | 34 | return $this->data->$func(...$args); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | + /** |
|
| 38 | + * @param Value $parser |
|
| 39 | + */ |
|
| 37 | 40 | public function parseNested($parser, $token, $funcName) { |
| 38 | 41 | $args = $parser->parseTokens($token['value'], $this->data); |
| 39 | 42 | if ($args[0] == $this->data) $args = []; |
@@ -49,6 +52,9 @@ discard block |
||
| 49 | 52 | else return call_user_func_array([$obj, $func], $args); |
| 50 | 53 | } |
| 51 | 54 | |
| 55 | + /** |
|
| 56 | + * @param boolean $autoLookup |
|
| 57 | + */ |
|
| 52 | 58 | public function extract($last, $autoLookup) { |
| 53 | 59 | if ($autoLookup && isset($this->data->{$last})) { |
| 54 | 60 | return $this->data->{$last}; |
@@ -14,16 +14,23 @@ discard block |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function traverse($key) { |
| 17 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
| 18 | - else if (is_array($this->data) && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
| 17 | + if (isset($this->data->{$key})) { |
|
| 18 | + $this->data = $this->data->{$key}; |
|
| 19 | + } else if (is_array($this->data) && isset($this->data[$key])) { |
|
| 20 | + $this->data = $this->data[$key]; |
|
| 21 | + } |
|
| 19 | 22 | } |
| 20 | 23 | |
| 21 | 24 | public function read($value) { |
| 22 | 25 | if (is_array($this->data)) { |
| 23 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
| 26 | + if (isset($this->data[$value])) { |
|
| 27 | + return $this->data[$value]; |
|
| 28 | + } |
|
| 29 | + } else if (is_scalar($value) && isset($this->data->$value)) { |
|
| 30 | + return $this->data->$value; |
|
| 31 | + } else { |
|
| 32 | + return false; |
|
| 24 | 33 | } |
| 25 | - else if (is_scalar($value) && isset($this->data->$value)) return $this->data->$value; |
|
| 26 | - else return false; |
|
| 27 | 34 | } |
| 28 | 35 | |
| 29 | 36 | public function isFunctionSet() { |
@@ -36,7 +43,9 @@ discard block |
||
| 36 | 43 | |
| 37 | 44 | public function parseNested($parser, $token, $funcName) { |
| 38 | 45 | $args = $parser->parseTokens($token['value'], $this->data); |
| 39 | - if ($args[0] == $this->data) $args = []; |
|
| 46 | + if ($args[0] == $this->data) { |
|
| 47 | + $args = []; |
|
| 48 | + } |
|
| 40 | 49 | return $this->callFunc($funcName, $args, $this->data); |
| 41 | 50 | } |
| 42 | 51 | |
@@ -45,15 +54,17 @@ discard block |
||
| 45 | 54 | } |
| 46 | 55 | |
| 47 | 56 | private function callFuncOnObject($obj, $func, $args) { |
| 48 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
| 49 | - else return call_user_func_array([$obj, $func], $args); |
|
| 57 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
| 58 | + return call_user_func_array($obj->$func, $args); |
|
| 59 | + } else { |
|
| 60 | + return call_user_func_array([$obj, $func], $args); |
|
| 61 | + } |
|
| 50 | 62 | } |
| 51 | 63 | |
| 52 | 64 | public function extract($last, $autoLookup) { |
| 53 | 65 | if ($autoLookup && isset($this->data->{$last})) { |
| 54 | 66 | return $this->data->{$last}; |
| 55 | - } |
|
| 56 | - else if (is_array($this->data) && isset($this->data[$last])) { |
|
| 67 | + } else if (is_array($this->data) && isset($this->data[$last])) { |
|
| 57 | 68 | return $this->data[$last]; |
| 58 | 69 | } |
| 59 | 70 | throw new \UnexpectedValueException('Not found'); |
@@ -51,7 +51,9 @@ discard block |
||
| 51 | 51 | $this->data = new ValueData($data); |
| 52 | 52 | $this->last = null; |
| 53 | 53 | |
| 54 | - if (empty($tokens)) return [$data]; |
|
| 54 | + if (empty($tokens)) { |
|
| 55 | + return [$data]; |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | foreach ($tokens as $token) { |
| 57 | 59 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -66,8 +68,9 @@ 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 | |
@@ -75,14 +78,19 @@ discard block |
||
| 75 | 78 | |
| 76 | 79 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
| 77 | 80 | private function processDot($token) { |
| 78 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
| 79 | - else $this->data = new ValueData($this->result->pop()); |
|
| 81 | + if ($this->last !== null) { |
|
| 82 | + $this->data->traverse($this->last); |
|
| 83 | + } else { |
|
| 84 | + $this->data = new ValueData($this->result->pop()); |
|
| 85 | + } |
|
| 80 | 86 | |
| 81 | 87 | $this->last = null; |
| 82 | 88 | } |
| 83 | 89 | |
| 84 | 90 | private function processSquareBracket($token) { |
| 85 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
| 91 | + if ($this->last !== null) { |
|
| 92 | + $this->data->traverse($this->last); |
|
| 93 | + } |
|
| 86 | 94 | $parser = new Value($this->baseData, $this->autoLookup); |
| 87 | 95 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
| 88 | 96 | } |
@@ -104,12 +112,10 @@ discard block |
||
| 104 | 112 | private function processBrackets($token) { |
| 105 | 113 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
| 106 | 114 | $this->callTransphpormFunctions($token); |
| 107 | - } |
|
| 108 | - else if ($this->data->isFunctionSet()) { |
|
| 115 | + } else if ($this->data->isFunctionSet()) { |
|
| 109 | 116 | $this->result = $this->result->processValue($this->data->call($this->last, [$token['value']])); |
| 110 | 117 | $this->last = null; |
| 111 | - } |
|
| 112 | - else { |
|
| 118 | + } else { |
|
| 113 | 119 | $this->processNested($token); |
| 114 | 120 | } |
| 115 | 121 | } |
@@ -125,7 +131,9 @@ discard block |
||
| 125 | 131 | $this->result->processValue($this->baseData->{$this->last}($token['value'])); |
| 126 | 132 | foreach ($this->result->getResult() as $i => $value) { |
| 127 | 133 | $val = $this->data->read($value); |
| 128 | - if ($val) $this->result[$i] = $val; |
|
| 134 | + if ($val) { |
|
| 135 | + $this->result[$i] = $val; |
|
| 136 | + } |
|
| 129 | 137 | } |
| 130 | 138 | $this->last = null; |
| 131 | 139 | } |
@@ -136,12 +144,10 @@ discard block |
||
| 136 | 144 | try { |
| 137 | 145 | $value = $this->data->extract($this->last, $this->autoLookup); |
| 138 | 146 | $this->result->processValue($value); |
| 139 | - } |
|
| 140 | - catch (\UnexpectedValueException $e) { |
|
| 147 | + } catch (\UnexpectedValueException $e) { |
|
| 141 | 148 | if (!$this->autoLookup) { |
| 142 | 149 | $this->result->processValue($this->last); |
| 143 | - } |
|
| 144 | - else { |
|
| 150 | + } else { |
|
| 145 | 151 | $this->result->clear(); |
| 146 | 152 | $this->result[0] = false; |
| 147 | 153 | } |