Completed
Push — master ( 94ad02...ce2496 )
by Richard
02:55
created
src/Parser/Value.php 1 patch
Braces   +22 added lines, -16 removed lines patch added patch discarded remove patch
@@ -50,10 +50,14 @@  discard block
 block discarded – undo
50 50
 		$this->data = new ValueData($data ? $data : $this->baseData);
51 51
 		$this->last = null;
52 52
 
53
-		if (empty($tokens)) return [$data];
53
+		if (empty($tokens)) {
54
+			return [$data];
55
+		}
54 56
 
55 57
 		foreach ($tokens as $token) {
56
-			if ($token['type'] !== Tokenizer::WHITESPACE) $this->{$this->tokenFuncs[$token['type']]}($token);
58
+			if ($token['type'] !== Tokenizer::WHITESPACE) {
59
+				$this->{$this->tokenFuncs[$token['type']]}($token);
60
+			}
57 61
 		}
58 62
 
59 63
 		$this->processLast();
@@ -72,13 +76,15 @@  discard block
 block discarded – undo
72 76
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
73 77
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
74 78
 	private function processDot($token) {
75
-		if ($this->last !== null) $this->data->traverse($this->last);
76
-		else {
79
+		if ($this->last !== null) {
80
+			$this->data->traverse($this->last);
81
+		} else {
77 82
 			//When . is not preceeded by anything, treat it as part of the string instead of an operator
78 83
 			// foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo"
79 84
 			$lastResult = $this->result->pop();
80
-			if ($lastResult) $this->data = new ValueData($lastResult);
81
-			else {
85
+			if ($lastResult) {
86
+				$this->data = new ValueData($lastResult);
87
+			} else {
82 88
 				$this->processString(['value' => '.']);
83 89
 				$this->result->setMode(Tokenizer::CONCAT);
84 90
 			}
@@ -91,9 +97,10 @@  discard block
 block discarded – undo
91 97
 		$parser = new Value($this->baseData, $this->autoLookup);
92 98
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
93 99
 			$this->callTransphpormFunctions($token);
94
-		}
95
-		else {
96
-			if ($this->last !== null) $this->data->traverse($this->last);
100
+		} else {
101
+			if ($this->last !== null) {
102
+				$this->data->traverse($this->last);
103
+			}
97 104
 			$this->last = $parser->parseTokens($token['value'], null)[0];
98 105
 		}
99 106
 	}
@@ -113,8 +120,7 @@  discard block
 block discarded – undo
113 120
 	private function processBrackets($token) {
114 121
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
115 122
 			$this->callTransphpormFunctions($token);
116
-		}
117
-		else {
123
+		} else {
118 124
 			$this->processNested($token);
119 125
 		}
120 126
 	}
@@ -131,7 +137,9 @@  discard block
 block discarded – undo
131 137
 		foreach ($this->result->getResult() as $i => $value) {
132 138
 			if (is_scalar($value)) {
133 139
 				$val = $this->data->read($value);
134
-				if ($val) $this->result[$i] = $val;
140
+				if ($val) {
141
+					$this->result[$i] = $val;
142
+				}
135 143
 			}
136 144
 		}
137 145
 		$this->last = null;
@@ -143,12 +151,10 @@  discard block
 block discarded – undo
143 151
 			try {
144 152
 				$value = $this->data->extract($this->last, $this->autoLookup);
145 153
 				$this->result->processValue($value);
146
-			}
147
-			catch (\UnexpectedValueException $e) {
154
+			} catch (\UnexpectedValueException $e) {
148 155
 				if (!$this->autoLookup) {
149 156
 					$this->result->processValue($this->last);
150
-				}
151
-				else {
157
+				} else {
152 158
 					$this->result->clear();
153 159
 					$this->result[0] = false;
154 160
 				}
Please login to merge, or discard this patch.
src/Parser/Sheet.php 1 patch
Braces   +26 added lines, -11 removed lines patch added patch discarded remove patch
@@ -33,9 +33,13 @@  discard block
 block discarded – undo
33 33
 			$rules = $this->writeRule($rules, $newRules);
34 34
 		}
35 35
 		//there may be processing instructions at the end
36
-		if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) $rules = array_merge($rules, $processing['rules']);
36
+		if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) {
37
+			$rules = array_merge($rules, $processing['rules']);
38
+		}
37 39
 		usort($rules, [$this, 'sortRules']);
38
-		if (empty($rules) && !empty($this->tss)) throw new \Exception("No TSS rules parsed");
40
+		if (empty($rules) && !empty($this->tss)) {
41
+			throw new \Exception("No TSS rules parsed");
42
+		}
39 43
 		return $rules;
40 44
 	}
41 45
 
@@ -69,8 +73,7 @@  discard block
 block discarded – undo
69 73
 				$pos = strpos($tss, ';', $spacePos);
70 74
 				$args = substr($tss, $spacePos+1, $pos-$spacePos-1);
71 75
 				$rules = array_merge($rules, $this->$funcName($args, $indexStart));
72
-			}
73
-			else {
76
+			} else {
74 77
 				break;
75 78
 			}
76 79
 		}
@@ -79,15 +82,20 @@  discard block
 block discarded – undo
79 82
 	}
80 83
 
81 84
 	private function import($args, $indexStart) {
82
-		if (is_file(trim($args,'\'" '))) $fileName = trim($args,'\'" ');
83
-		else $fileName = $this->valueParser->parse($args)[0];
85
+		if (is_file(trim($args,'\'" '))) {
86
+			$fileName = trim($args,'\'" ');
87
+		} else {
88
+			$fileName = $this->valueParser->parse($args)[0];
89
+		}
84 90
 		$sheet = new Sheet(file_get_contents($this->baseDir . $fileName), dirname(realpath($this->baseDir . $fileName)) . DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser);
85 91
 		return $sheet->parse(0, [], $indexStart);
86 92
 	}
87 93
 
88 94
 	private function sortRules($a, $b) {
89 95
 		//If they have the same depth, compare on index
90
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
96
+		if ($a->depth === $b->depth) {
97
+			return $a->index < $b->index ? -1 : 1;
98
+		}
91 99
 
92 100
 		return ($a->depth < $b->depth) ? -1 : 1;
93 101
 	}
@@ -96,7 +104,9 @@  discard block
 block discarded – undo
96 104
 		$pos = 0;
97 105
 		while (($pos = strpos($str, $open, $pos)) !== false) {
98 106
 			$end = strpos($str, $close, $pos);
99
-			if ($end === false) break;
107
+			if ($end === false) {
108
+				break;
109
+			}
100 110
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
101 111
 		}
102 112
 
@@ -110,13 +120,18 @@  discard block
 block discarded – undo
110 120
 		$rules = [];
111 121
 		$i = 0;
112 122
 		foreach ($tokens as $token) {
113
-			if ($token['type'] === Tokenizer::SEMI_COLON) $i++;
114
-			else if ($token['type'] !== Tokenizer::WHITESPACE) $rules[$i][] = $token;
123
+			if ($token['type'] === Tokenizer::SEMI_COLON) {
124
+				$i++;
125
+			} else if ($token['type'] !== Tokenizer::WHITESPACE) {
126
+				$rules[$i][] = $token;
127
+			}
115 128
 		}
116 129
 
117 130
 		$return = [];
118 131
 		foreach ($rules as $rule) {
119
-			if ($rule[1]['type'] === Tokenizer::COLON) $return[$rule[0]['value']] = array_slice($rule, 2);
132
+			if ($rule[1]['type'] === Tokenizer::COLON) {
133
+				$return[$rule[0]['value']] = array_slice($rule, 2);
134
+			}
120 135
 		}
121 136
 
122 137
 		return $return;
Please login to merge, or discard this patch.