@@ -56,7 +56,9 @@ discard block |
||
56 | 56 | $this->last = null; |
57 | 57 | $this->traversing = false; |
58 | 58 | |
59 | - if (count($tokens) <= 0) return [$data]; |
|
59 | + if (count($tokens) <= 0) { |
|
60 | + return [$data]; |
|
61 | + } |
|
60 | 62 | |
61 | 63 | foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) { |
62 | 64 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -84,8 +86,7 @@ discard block |
||
84 | 86 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
85 | 87 | if ($lastResult) { |
86 | 88 | $this->traversing = true; |
87 | - } |
|
88 | - else if ($this->last === null) { |
|
89 | + } else if ($this->last === null) { |
|
89 | 90 | $this->processString(['value' => '.']); |
90 | 91 | $this->result->setMode(Tokenizer::CONCAT); |
91 | 92 | } |
@@ -101,11 +102,12 @@ discard block |
||
101 | 102 | $parser = new Value($this->baseData, $this->autoLookup); |
102 | 103 | if ($this->hasFunction($this->last)) { |
103 | 104 | $this->callTransphpormFunctions($token); |
104 | - } |
|
105 | - else { |
|
105 | + } else { |
|
106 | 106 | $this->data->traverse($this->last, $this->result); |
107 | 107 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
108 | - if (!is_bool($this->last)) $this->traversing = true; |
|
108 | + if (!is_bool($this->last)) { |
|
109 | + $this->traversing = true; |
|
110 | + } |
|
109 | 111 | } |
110 | 112 | } |
111 | 113 | |
@@ -125,8 +127,7 @@ discard block |
||
125 | 127 | if ($this->hasFunction($this->last) |
126 | 128 | && !$this->data->methodExists($this->last)) { |
127 | 129 | $this->callTransphpormFunctions($token); |
128 | - } |
|
129 | - else { |
|
130 | + } else { |
|
130 | 131 | $this->processNested($token); |
131 | 132 | } |
132 | 133 | } |
@@ -156,8 +157,7 @@ discard block |
||
156 | 157 | try { |
157 | 158 | $value = $this->data->extract($this->last, $this->autoLookup, $this->traversing); |
158 | 159 | $this->result->processValue($value); |
159 | - } |
|
160 | - catch (\UnexpectedValueException $e) { |
|
160 | + } catch (\UnexpectedValueException $e) { |
|
161 | 161 | $this->processLastUnexpected(); |
162 | 162 | } |
163 | 163 | } |
@@ -166,8 +166,7 @@ discard block |
||
166 | 166 | private function processLastUnexpected() { |
167 | 167 | if (!($this->autoLookup || $this->traversing)) { |
168 | 168 | $this->result->processValue($this->last); |
169 | - } |
|
170 | - else { |
|
169 | + } else { |
|
171 | 170 | $this->result->clear(); |
172 | 171 | $this->result->write(0, false); |
173 | 172 | } |
@@ -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) { |
@@ -37,10 +41,14 @@ discard block |
||
37 | 41 | |
38 | 42 | public function read($value) { |
39 | 43 | if ($this->isArray()) { |
40 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
44 | + if (isset($this->data[$value])) { |
|
45 | + return $this->data[$value]; |
|
46 | + } |
|
47 | + } else if (isset($this->data->$value)) { |
|
48 | + return $this->data->$value; |
|
49 | + } else { |
|
50 | + return null; |
|
41 | 51 | } |
42 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
43 | - else return null; |
|
44 | 52 | } |
45 | 53 | |
46 | 54 | public function call($func, $args) { |
@@ -53,14 +61,20 @@ discard block |
||
53 | 61 | |
54 | 62 | public function parseNested($parser, $token, $funcName) { |
55 | 63 | $args = $parser->parseTokens($token['value'], $this->data); |
56 | - if ($args[0] == $this->data) $args = []; |
|
64 | + if ($args[0] == $this->data) { |
|
65 | + $args = []; |
|
66 | + } |
|
57 | 67 | return $this->callFuncOnObject($this->data, $funcName, $args); |
58 | 68 | } |
59 | 69 | |
60 | 70 | private function callFuncOnObject($obj, $func, $args) { |
61 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
62 | - else if (is_callable([$obj, $func])) return call_user_func_array([$obj, $func], $args); |
|
63 | - else return false; |
|
71 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
72 | + return call_user_func_array($obj->$func, $args); |
|
73 | + } else if (is_callable([$obj, $func])) { |
|
74 | + return call_user_func_array([$obj, $func], $args); |
|
75 | + } else { |
|
76 | + return false; |
|
77 | + } |
|
64 | 78 | } |
65 | 79 | |
66 | 80 | public function extract($last, $autoLookup, $traversing) { |
@@ -18,8 +18,11 @@ |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run(array $args, \DomElement $element = null) { |
21 | - if ($this->dataKey === "root") $data = $this->data->getData(null, 'data'); |
|
22 | - else $data = $this->data->getData($element, $this->dataKey); |
|
21 | + if ($this->dataKey === "root") { |
|
22 | + $data = $this->data->getData(null, 'data'); |
|
23 | + } else { |
|
24 | + $data = $this->data->getData($element, $this->dataKey); |
|
25 | + } |
|
23 | 26 | $parser = new \Transphporm\Parser\Value($this->functionSet, true, true); |
24 | 27 | $return = $parser->parseTokens(new \Transphporm\Parser\Tokens($args), $data); |
25 | 28 | return $return[0]; |