Completed
Push — master ( 7b17ad...a29029 )
by Tom
02:30
created
src/Parser/Value.php 1 patch
Braces   +20 added lines, -17 removed lines patch added patch discarded remove patch
@@ -51,7 +51,9 @@  discard block
 block discarded – undo
51 51
 		$this->data = new ValueData($data);
52 52
 		$this->last = null;
53 53
 
54
-		if (empty($tokens)) return [$data];
54
+		if (empty($tokens)) {
55
+			return [$data];
56
+		}
55 57
 
56 58
 		foreach ($tokens as $token) {
57 59
 			$this->{$this->tokenFuncs[$token['type']]}($token);	
@@ -66,8 +68,7 @@  discard block
 block discarded – undo
66 68
 
67 69
 		if ($this->result->getMode() == Tokenizer::NOT && $token['type'] == Tokenizer::EQUALS) {
68 70
 			$this->result->setMode(Tokenizer::NOT);
69
-		}
70
-		else {
71
+		} else {
71 72
 			$this->result->setMode($token['type']);
72 73
 			$this->last = null;
73 74
 		}
@@ -77,8 +78,11 @@  discard block
 block discarded – undo
77 78
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
78 79
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
79 80
 	private function processDot($token) {
80
-		if ($this->last !== null) $this->data->traverse($this->last);
81
-		else $this->data = new ValueData($this->result->pop());
81
+		if ($this->last !== null) {
82
+			$this->data->traverse($this->last);
83
+		} else {
84
+			$this->data = new ValueData($this->result->pop());
85
+		}
82 86
 
83 87
 		$this->last = null;
84 88
 	}
@@ -87,9 +91,10 @@  discard block
 block discarded – undo
87 91
 		$parser = new Value($this->baseData, $this->autoLookup);
88 92
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
89 93
 			$this->callTransphpormFunctions($token);
90
-		}
91
-		else {
92
-			if ($this->last !== null) $this->data->traverse($this->last);			
94
+		} else {
95
+			if ($this->last !== null) {
96
+				$this->data->traverse($this->last);
97
+			}
93 98
 			$this->last = $parser->parseTokens($token['value'], null)[0];
94 99
 		}
95 100
 	}
@@ -111,12 +116,10 @@  discard block
 block discarded – undo
111 116
 	private function processBrackets($token) {
112 117
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
113 118
 			$this->callTransphpormFunctions($token);
114
-		}
115
-		else if ($this->data->isFunctionSet()) {
119
+		} else if ($this->data->isFunctionSet()) {
116 120
 			$this->result = $this->result->processValue($this->data->call($this->last, [$token['value']]));
117 121
 			$this->last = null;
118
-		}
119
-		else {
122
+		} else {
120 123
 			$this->processNested($token);
121 124
 		}
122 125
 	}
@@ -133,7 +136,9 @@  discard block
 block discarded – undo
133 136
 		foreach ($this->result->getResult() as $i => $value) {
134 137
 			if (is_scalar($value)) {
135 138
 				$val = $this->data->read($value);
136
-				if ($val) $this->result[$i] = $val;
139
+				if ($val) {
140
+					$this->result[$i] = $val;
141
+				}
137 142
 			}
138 143
 		}
139 144
 		$this->last = null;
@@ -145,12 +150,10 @@  discard block
 block discarded – undo
145 150
 			try {
146 151
 				$value = $this->data->extract($this->last, $this->autoLookup);
147 152
 				$this->result->processValue($value);
148
-			}
149
-			catch (\UnexpectedValueException $e) {
153
+			} catch (\UnexpectedValueException $e) {
150 154
 				if (!$this->autoLookup) {
151 155
 					$this->result->processValue($this->last);
152
-				}
153
-				else {
156
+				} else {
154 157
 					$this->result->clear();
155 158
 					$this->result[0] = false;
156 159
 				}
Please login to merge, or discard this patch.
src/Parser/ValueData.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 
52 52
 	public function extract($last, $autoLookup) {
53 53
 		$value = $this->read($last);
54
-		if ($value && ($autoLookup || is_array($this->data)) ) {
54
+		if ($value && ($autoLookup || is_array($this->data))) {
55 55
 			return $value;
56 56
 		}
57 57
 		throw new \UnexpectedValueException('Not found');
Please login to merge, or discard this patch.
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,16 +14,23 @@  discard block
 block discarded – undo
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) && 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) && 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)) {
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 isFunctionSet() {
@@ -36,7 +43,9 @@  discard block
 block discarded – undo
36 43
 
37 44
 	public function parseNested($parser, $token, $funcName) {
38 45
 		$args = $parser->parseTokens($token['value'], $this->data);
39
-		if ($args[0] == $this->data) $args = [];
46
+		if ($args[0] == $this->data) {
47
+			$args = [];
48
+		}
40 49
 		return $this->callFunc($funcName, $args, $this->data);
41 50
 	}
42 51
 
@@ -45,8 +54,11 @@  discard block
 block discarded – undo
45 54
 	}
46 55
 
47 56
 	private function callFuncOnObject($obj, $func, $args) {
48
-		if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args);
49
-		else return call_user_func_array([$obj, $func], $args);
57
+		if (isset($obj->$func) && is_callable($obj->$func)) {
58
+			return call_user_func_array($obj->$func, $args);
59
+		} else {
60
+			return call_user_func_array([$obj, $func], $args);
61
+		}
50 62
 	}
51 63
 
52 64
 	public function extract($last, $autoLookup) {
Please login to merge, or discard this patch.
src/Pseudo/Attribute.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,10 +14,14 @@
 block discarded – undo
14 14
 
15 15
 	public function match($pseudo, \DomElement $element) {
16 16
 		$pos = strpos($pseudo, '[');
17
-		if ($pos === false) return true;
17
+		if ($pos === false) {
18
+			return true;
19
+		}
18 20
 
19 21
 		$name = substr($pseudo, 0, $pos);
20
-		if (!$this->functionSet->hasFunction($name)) return true;
22
+		if (!$this->functionSet->hasFunction($name)) {
23
+			return true;
24
+		}
21 25
 
22 26
 		$this->functionSet->setElement($element);
23 27
 		$valueParser = new \Transphporm\Parser\Value($this->functionSet);
Please login to merge, or discard this patch.
src/Property/Content.php 1 patch
Braces   +21 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,21 +18,28 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
21
-		if (!$this->shouldRun($element)) return false;
21
+		if (!$this->shouldRun($element)) {
22
+			return false;
23
+		}
22 24
 
23 25
 		$values = $this->formatter->format($values, $rules);
24 26
 		if (!$this->processPseudo($values, $element, $pseudoMatcher)) {
25 27
 			//Remove the current contents
26 28
 			$this->removeAllChildren($element);
27 29
 			//Now make a text node
28
-			if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values);
29
-			else $this->appendContent($element, $values);
30
+			if ($this->getContentMode($rules) === 'replace') {
31
+				$this->replaceContent($element, $values);
32
+			} else {
33
+				$this->appendContent($element, $values);
34
+			}
30 35
 		}
31 36
 	}
32 37
 
33 38
 	private function shouldRun($element) {
34 39
 		do {
35
-			if ($element->getAttribute('transphporm') == 'includedtemplate') return false;
40
+			if ($element->getAttribute('transphporm') == 'includedtemplate') {
41
+				return false;
42
+			}
36 43
 		}
37 44
 		while (($element = $element->parentNode) instanceof \DomElement);
38 45
 		return true;
@@ -54,17 +61,20 @@  discard block
 block discarded – undo
54 61
 	}
55 62
 	
56 63
 	private function getNode($node, $document) {
57
-		if (is_array($node[0])) $node = $node[0];
64
+		if (is_array($node[0])) {
65
+			$node = $node[0];
66
+		}
58 67
 		foreach ($node as $n) {
59 68
 
60 69
 			if ($n instanceof \DomElement) {
61 70
 				$new = $document->importNode($n, true);
62 71
 				//Removing this might cause problems with caching... 
63 72
 				//$new->setAttribute('transphporm', 'added');
64
-			}
65
-			else {
73
+			} else {
66 74
 
67
-				if ($n instanceof \DomText) $n = $n->nodeValue;
75
+				if ($n instanceof \DomText) {
76
+					$n = $n->nodeValue;
77
+				}
68 78
 				$new = $document->createElement('text');
69 79
 				
70 80
 				$new->appendChild($document->createTextNode($n));
@@ -111,6 +121,8 @@  discard block
 block discarded – undo
111 121
 	}
112 122
 	
113 123
 	private function removeAllChildren($element) {
114
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
124
+		while ($element->hasChildNodes()) {
125
+			$element->removeChild($element->firstChild);
126
+		}
115 127
 	}
116 128
 }
117 129
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Repeat.php 1 patch
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,14 +15,18 @@  discard block
 block discarded – undo
15 15
 	}
16 16
 
17 17
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
18
-		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
18
+		if ($element->getAttribute('transphporm') === 'added') {
19
+			return $element->parentNode->removeChild($element);
20
+		}
19 21
 		$max = $this->getMax($values);
20 22
 		$count = 0;
21 23
 
22 24
 		//What was this if statement for? removing it breaks nothing
23 25
 		//if (empty($values[0])) $values[0] = [];
24 26
 		foreach ($values[0] as $key => $iteration) {
25
-			if ($count+1 > $max) break;
27
+			if ($count+1 > $max) {
28
+				break;
29
+			}
26 30
 			$clone = $this->cloneElement($element, $iteration, $key, $count++);
27 31
 			//Re-run the hook on the new element, but use the iterated data
28 32
 			//Don't run repeat on the clones element or it will loop forever
@@ -46,7 +50,9 @@  discard block
 block discarded – undo
46 50
 
47 51
 	private function tagElement($element, $count) {
48 52
 		//Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed
49
-		if ($count > 0) $element->setAttribute('transphporm', 'added');
53
+		if ($count > 0) {
54
+			$element->setAttribute('transphporm', 'added');
55
+		}
50 56
 	}
51 57
 
52 58
 	private function getMax($values) {
@@ -55,7 +61,9 @@  discard block
 block discarded – undo
55 61
 
56 62
 	private function createHook($newRules, $pseudoMatcher, $properties) {
57 63
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet);
58
-		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
64
+		foreach ($properties as $name => $property) {
65
+			$hook->registerProperty($name, $property);
66
+		}
59 67
 		return $hook;
60 68
 	}
61 69
 }
Please login to merge, or discard this patch.