@@ -69,7 +69,7 @@ |
||
| 69 | 69 | |
| 70 | 70 | public function extract($last, $autoLookup, $traversing) { |
| 71 | 71 | $value = $this->read($last); |
| 72 | - if ($value !== null && ($autoLookup || $traversing) ) { |
|
| 72 | + if ($value !== null && ($autoLookup || $traversing)) { |
|
| 73 | 73 | return $value; |
| 74 | 74 | } |
| 75 | 75 | throw new \UnexpectedValueException('Not found'); |
@@ -15,13 +15,17 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | //Read $key from array, $this->data = $this->data[$key] but also works for objects |
| 17 | 17 | private function traverseInto($key) { |
| 18 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
| 19 | - else if ($this->isArray() && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
| 18 | + if (isset($this->data->{$key})) { |
|
| 19 | + $this->data = $this->data->{$key}; |
|
| 20 | + } else if ($this->isArray() && isset($this->data[$key])) { |
|
| 21 | + $this->data = $this->data[$key]; |
|
| 22 | + } |
|
| 20 | 23 | } |
| 21 | 24 | |
| 22 | 25 | public function traverse($key, $result) { |
| 23 | - if ($key !== null) $this->traverseInto($key); |
|
| 24 | - else { |
|
| 26 | + if ($key !== null) { |
|
| 27 | + $this->traverseInto($key); |
|
| 28 | + } else { |
|
| 25 | 29 | //But if the key is null, replace the data structure with the result of the last function call |
| 26 | 30 | $lastResult = $result->pop(); |
| 27 | 31 | if ($lastResult) { |
@@ -41,10 +45,14 @@ discard block |
||
| 41 | 45 | |
| 42 | 46 | public function read($value) { |
| 43 | 47 | if ($this->isArray()) { |
| 44 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
| 48 | + if (isset($this->data[$value])) { |
|
| 49 | + return $this->data[$value]; |
|
| 50 | + } |
|
| 51 | + } else if (isset($this->data->$value)) { |
|
| 52 | + return $this->data->$value; |
|
| 53 | + } else { |
|
| 54 | + return null; |
|
| 45 | 55 | } |
| 46 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
| 47 | - else return null; |
|
| 48 | 56 | } |
| 49 | 57 | |
| 50 | 58 | public function call($func, $args) { |
@@ -57,14 +65,20 @@ discard block |
||
| 57 | 65 | |
| 58 | 66 | public function parseNested($parser, $token, $funcName) { |
| 59 | 67 | $args = $parser->parseTokens($token['value'], $this->data); |
| 60 | - if ($args[0] === $this->data) $args = []; |
|
| 68 | + if ($args[0] === $this->data) { |
|
| 69 | + $args = []; |
|
| 70 | + } |
|
| 61 | 71 | return $this->callFuncOnObject($this->data, $funcName, $args); |
| 62 | 72 | } |
| 63 | 73 | |
| 64 | 74 | private function callFuncOnObject($obj, $func, $args) { |
| 65 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
| 66 | - else if (is_callable([$obj, $func])) return call_user_func_array([$obj, $func], $args); |
|
| 67 | - else return false; |
|
| 75 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
| 76 | + return call_user_func_array($obj->$func, $args); |
|
| 77 | + } else if (is_callable([$obj, $func])) { |
|
| 78 | + return call_user_func_array([$obj, $func], $args); |
|
| 79 | + } else { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 68 | 82 | } |
| 69 | 83 | |
| 70 | 84 | public function extract($last, $autoLookup, $traversing) { |