Completed
Push — master ( e97281...f3b478 )
by Tom
03:18
created
src/Parser/Value.php 1 patch
Braces   +14 added lines, -13 removed lines patch added patch discarded remove patch
@@ -54,7 +54,9 @@  discard block
 block discarded – undo
54 54
 		$this->last = null;
55 55
 		$this->traversing = false;
56 56
 
57
-		if (count($tokens) <= 0) return [$data];
57
+		if (count($tokens) <= 0) {
58
+			return [$data];
59
+		}
58 60
 
59 61
 		foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) {
60 62
 			$this->{$this->tokenFuncs[$token['type']]}($token);
@@ -82,8 +84,7 @@  discard block
 block discarded – undo
82 84
 		// foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo"
83 85
 		if ($lastResult) {
84 86
 			$this->traversing = true;
85
-		}
86
-		else if ($this->last === null)  {
87
+		} else if ($this->last === null)  {
87 88
 			$this->processString(['value' => '.']);
88 89
 			$this->result->setMode(Tokenizer::CONCAT);
89 90
 		}
@@ -99,11 +100,12 @@  discard block
 block discarded – undo
99 100
 		$parser = new Value($this->baseData, $this->autoLookup);
100 101
 		if ($this->hasFunction($this->last)) {
101 102
 			$this->callTransphpormFunctions($token);
102
-		}
103
-		else {
103
+		} else {
104 104
 			$this->data->traverse($this->last, $this->result);
105 105
 			$this->last = $parser->parseTokens($token['value'], null)[0];
106
-			if (!is_bool($this->last)) $this->traversing = true;
106
+			if (!is_bool($this->last)) {
107
+				$this->traversing = true;
108
+			}
107 109
 		}
108 110
 	}
109 111
 
@@ -123,8 +125,7 @@  discard block
 block discarded – undo
123 125
 		if ($this->hasFunction($this->last)
124 126
 			&& !$this->data->methodExists($this->last)) {
125 127
 			$this->callTransphpormFunctions($token);
126
-		}
127
-		else {
128
+		} else {
128 129
 			$this->processNested($token);
129 130
 		}
130 131
 	}
@@ -141,7 +142,9 @@  discard block
 block discarded – undo
141 142
 		foreach ($this->result->getResult() as $i => $value) {
142 143
 			if (is_scalar($value)) {
143 144
 				$val = $this->data->read($value);
144
-				if ($val) $this->result[$i] = $val;
145
+				if ($val) {
146
+					$this->result[$i] = $val;
147
+				}
145 148
 			}
146 149
 		}
147 150
 		$this->last = null;
@@ -153,8 +156,7 @@  discard block
 block discarded – undo
153 156
 			try {
154 157
 				$value = $this->data->extract($this->last, $this->autoLookup, $this->traversing);
155 158
 				$this->result->processValue($value);
156
-			}
157
-			catch (\UnexpectedValueException $e) {
159
+			} catch (\UnexpectedValueException $e) {
158 160
 				$this->processLastUnexpected();
159 161
 			}
160 162
 		}
@@ -163,8 +165,7 @@  discard block
 block discarded – undo
163 165
 	private function processLastUnexpected() {
164 166
 		if (!($this->autoLookup || $this->traversing)) {
165 167
 			$this->result->processValue($this->last);
166
-		}
167
-		else {
168
+		} else {
168 169
 			$this->result->clear();
169 170
 			$this->result[0] = false;
170 171
 		}
Please login to merge, or discard this patch.
src/Parser/ValueData.php 1 patch
Braces   +25 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,13 +15,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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 false;
41 51
 		}
42
-		else if (isset($this->data->$value)) return $this->data->$value;
43
-		else return false;
44 52
 	}
45 53
 
46 54
 	public function call($func, $args) {
@@ -53,14 +61,20 @@  discard block
 block discarded – undo
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) {
Please login to merge, or discard this patch.