@@ -50,7 +50,9 @@ discard block |
||
50 | 50 | $this->data = new ValueData($data ? $data : $this->baseData); |
51 | 51 | $this->last = null; |
52 | 52 | |
53 | - if (count($tokens) <= 0) return [$data]; |
|
53 | + if (count($tokens) <= 0) { |
|
54 | + return [$data]; |
|
55 | + } |
|
54 | 56 | |
55 | 57 | foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) { |
56 | 58 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -72,13 +74,15 @@ discard block |
||
72 | 74 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
73 | 75 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
74 | 76 | private function processDot($token) { |
75 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
76 | - else { |
|
77 | + if ($this->last !== null) { |
|
78 | + $this->data->traverse($this->last); |
|
79 | + } else { |
|
77 | 80 | //When . is not preceeded by anything, treat it as part of the string instead of an operator |
78 | 81 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
79 | 82 | $lastResult = $this->result->pop(); |
80 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
81 | - else { |
|
83 | + if ($lastResult) { |
|
84 | + $this->data = new ValueData($lastResult); |
|
85 | + } else { |
|
82 | 86 | $this->processString(['value' => '.']); |
83 | 87 | $this->result->setMode(Tokenizer::CONCAT); |
84 | 88 | } |
@@ -91,15 +95,19 @@ discard block |
||
91 | 95 | $parser = new Value($this->baseData, $this->autoLookup); |
92 | 96 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
93 | 97 | $this->callTransphpormFunctions($token); |
94 | - } |
|
95 | - else { |
|
96 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
97 | - else { |
|
98 | + } else { |
|
99 | + if ($this->last !== null) { |
|
100 | + $this->data->traverse($this->last); |
|
101 | + } else { |
|
98 | 102 | $lastResult = $this->result->pop(); |
99 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
103 | + if ($lastResult) { |
|
104 | + $this->data = new ValueData($lastResult); |
|
105 | + } |
|
100 | 106 | } |
101 | 107 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
102 | - if (!is_bool($this->last)) $this->accessingArray = true; |
|
108 | + if (!is_bool($this->last)) { |
|
109 | + $this->accessingArray = true; |
|
110 | + } |
|
103 | 111 | } |
104 | 112 | } |
105 | 113 | |
@@ -118,8 +126,7 @@ discard block |
||
118 | 126 | private function processBrackets($token) { |
119 | 127 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
120 | 128 | $this->callTransphpormFunctions($token); |
121 | - } |
|
122 | - else { |
|
129 | + } else { |
|
123 | 130 | $this->processNested($token); |
124 | 131 | } |
125 | 132 | } |
@@ -136,7 +143,9 @@ discard block |
||
136 | 143 | foreach ($this->result->getResult() as $i => $value) { |
137 | 144 | if (is_scalar($value)) { |
138 | 145 | $val = $this->data->read($value); |
139 | - if ($val) $this->result[$i] = $val; |
|
146 | + if ($val) { |
|
147 | + $this->result[$i] = $val; |
|
148 | + } |
|
140 | 149 | } |
141 | 150 | } |
142 | 151 | $this->last = null; |
@@ -148,12 +157,10 @@ discard block |
||
148 | 157 | try { |
149 | 158 | $value = $this->data->extract($this->last, $this->autoLookup); |
150 | 159 | $this->result->processValue($value); |
151 | - } |
|
152 | - catch (\UnexpectedValueException $e) { |
|
160 | + } catch (\UnexpectedValueException $e) { |
|
153 | 161 | if (!($this->autoLookup || $this->accessingArray)) { |
154 | 162 | $this->result->processValue($this->last); |
155 | - } |
|
156 | - else { |
|
163 | + } else { |
|
157 | 164 | $this->result->clear(); |
158 | 165 | $this->result[0] = false; |
159 | 166 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | |
44 | 44 | public function extract($last, $autoLookup) { |
45 | 45 | $value = $this->read($last); |
46 | - if ($value && ($autoLookup || is_array($this->data) || $this->data instanceof \ArrayAccess) ) { |
|
46 | + if ($value && ($autoLookup || is_array($this->data) || $this->data instanceof \ArrayAccess)) { |
|
47 | 47 | return $value; |
48 | 48 | } |
49 | 49 | throw new \UnexpectedValueException('Not found'); |
@@ -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) || $this->data instanceof \ArrayAccess) && 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) || $this->data instanceof \ArrayAccess) && 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) || $this->data instanceof \ArrayAccess)) { |
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 (isset($this->data->$value)) { |
|
30 | + return $this->data->$value; |
|
31 | + } else { |
|
32 | + return false; |
|
24 | 33 | } |
25 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
26 | - else return false; |
|
27 | 34 | } |
28 | 35 | |
29 | 36 | public function call($func, $args) { |
@@ -32,13 +39,18 @@ discard block |
||
32 | 39 | |
33 | 40 | public function parseNested($parser, $token, $funcName) { |
34 | 41 | $args = $parser->parseTokens($token['value'], $this->data); |
35 | - if ($args[0] == $this->data) $args = []; |
|
42 | + if ($args[0] == $this->data) { |
|
43 | + $args = []; |
|
44 | + } |
|
36 | 45 | return $this->callFuncOnObject($this->data, $funcName, $args); |
37 | 46 | } |
38 | 47 | |
39 | 48 | private function callFuncOnObject($obj, $func, $args) { |
40 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
41 | - else return call_user_func_array([$obj, $func], $args); |
|
49 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
50 | + return call_user_func_array($obj->$func, $args); |
|
51 | + } else { |
|
52 | + return call_user_func_array([$obj, $func], $args); |
|
53 | + } |
|
42 | 54 | } |
43 | 55 | |
44 | 56 | public function extract($last, $autoLookup) { |