Completed
Pull Request — master (#92)
by
unknown
03:03
created
src/TSSFunction/Template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 	public function run(array $args, \DomElement $element) {
23 23
 		$selector = $this->readArray($args, 1);
24 24
 		$tss = $this->readArray($args, 2);
25
-		$newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss ? $this->baseDir . $tss : null);
25
+		$newTemplate = new \Transphporm\Builder($this->baseDir.$args[0], $tss ? $this->baseDir.$tss : null);
26 26
 
27 27
 		$doc = $newTemplate->output($this->elementData->getData($element), true)->body;
28 28
 		if ($selector != '') return $this->templateSubsection($doc, $selector);
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
 		$newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss ? $this->baseDir . $tss : null);
31 31
 
32 32
 		$doc = $newTemplate->output($this->elementData->getData($element), true)->body;
33
-		if ($selector != '') return $this->templateSubsection($doc, $selector);
33
+		if ($selector != '') {
34
+			return $this->templateSubsection($doc, $selector);
35
+		}
34 36
 
35 37
 		return $this->getTemplateContent($doc, $tss);
36 38
 
@@ -60,7 +62,9 @@  discard block
 block discarded – undo
60 62
 
61 63
 	private function getClonedElement($node, $tss) {
62 64
 		$clone = $node->cloneNode(true);
63
-		if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate');
65
+		if ($tss != null && $clone instanceof \DomElement) {
66
+			$clone->setAttribute('transphporm', 'includedtemplate');
67
+		}
64 68
 		return $clone;
65 69
 	}
66 70
 }
Please login to merge, or discard this patch.
src/Hook/ElementData.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@
 block discarded – undo
31 31
 	/** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/
32 32
 	public function getData(\DomElement $element = null, $type = 'data') {
33 33
 		while ($element) {
34
-			if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) return $this->elementMap[$element][$type];
34
+			if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) {
35
+				return $this->elementMap[$element][$type];
36
+			}
35 37
 			$element = $element->parentNode;
36 38
 		}
37 39
 		return $this->data;
Please login to merge, or discard this patch.
src/Parser/Tokenizer.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@
 block discarded – undo
105 105
 			$string = $this->extractString($i);
106 106
 			$length = strlen($string)+1;
107 107
 			$char = $this->getChar($char);
108
-			$string = str_replace('\\' . $char, $char, $string);
108
+			$string = str_replace('\\'.$char, $char, $string);
109 109
 			$tokens[] = ['type' => self::STRING, 'value' => $string];
110 110
 			return $length;
111 111
 		}
Please login to merge, or discard this patch.
Braces   +25 added lines, -10 removed lines patch added patch discarded remove patch
@@ -76,10 +76,15 @@  discard block
 block discarded – undo
76 76
 				$name .= $this->str[$i+1];
77 77
 				$i++;
78 78
 			}
79
-			if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name];
80
-			else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true];
81
-			else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false];
82
-			else $tokens[] = ['type' => self::NAME, 'value' => $name];
79
+			if (is_numeric($name)) {
80
+				$tokens[] = ['type' => self::NUMERIC, 'value' => $name];
81
+			} else if ($name == 'true') {
82
+				$tokens[] = ['type' => self::BOOL, 'value' => true];
83
+			} else if ($name == 'false') {
84
+				$tokens[] = ['type' => self::BOOL, 'value' => false];
85
+			} else {
86
+				$tokens[] = ['type' => self::NAME, 'value' => $name];
87
+			}
83 88
 		}
84 89
 	}
85 90
 
@@ -114,7 +119,9 @@  discard block
 block discarded – undo
114 119
 	private function extractString($pos) {
115 120
 		$char = $this->str[$pos];
116 121
 		$end = strpos($this->str, $char, $pos+1);
117
-		while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1);
122
+		while ($end !== false && $this->str[$end-1] == '\\') {
123
+			$end = strpos($this->str, $char, $end+1);
124
+		}
118 125
 
119 126
 		return substr($this->str, $pos+1, $end-$pos-1);
120 127
 	}
@@ -123,18 +130,26 @@  discard block
 block discarded – undo
123 130
 		$close = strpos($this->str, $closeBracket, $open);
124 131
 
125 132
 		$cPos = $open+1;
126
-		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1);
133
+		while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) {
134
+			$close = strpos($this->str, $closeBracket, $close+1);
135
+		}
127 136
 		return substr($this->str, $open+1, $close-$open-1);
128 137
 	}
129 138
 
130 139
 	private function identifyChar($chr) {
131
-		if (isset($this->chars[$chr])) return $this->chars[$chr];
132
-		else return self::NAME;
140
+		if (isset($this->chars[$chr])) {
141
+			return $this->chars[$chr];
142
+		} else {
143
+			return self::NAME;
144
+		}
133 145
 	}
134 146
 
135 147
 	private function getChar($num) {
136 148
 		$chars = array_reverse($this->chars);
137
-		if (isset($chars[$num])) return $chars[$num];
138
-		else return false;
149
+		if (isset($chars[$num])) {
150
+			return $chars[$num];
151
+		} else {
152
+			return false;
153
+		}
139 154
 	}
140 155
 }
Please login to merge, or discard this patch.
src/Property/Repeat.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,13 +15,19 @@  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
-		if (empty($values[0])) $values[0] = [];
24
+		if (empty($values[0])) {
25
+			$values[0] = [];
26
+		}
23 27
 		foreach ($values[0] as $key => $iteration) {
24
-			if ($count+1 > $max) break;
28
+			if ($count+1 > $max) {
29
+				break;
30
+			}
25 31
 			$clone = $this->cloneElement($element, $iteration, $key, $count++);
26 32
 			//Re-run the hook on the new element, but use the iterated data
27 33
 			//Don't run repeat on the clones element or it will loop forever
@@ -45,7 +51,9 @@  discard block
 block discarded – undo
45 51
 
46 52
 	private function tagElement($element, $count) {
47 53
 		//Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed
48
-		if ($count > 0) $element->setAttribute('transphporm', 'added');
54
+		if ($count > 0) {
55
+			$element->setAttribute('transphporm', 'added');
56
+		}
49 57
 	}
50 58
 
51 59
 	private function getMax($values) {
@@ -54,7 +62,9 @@  discard block
 block discarded – undo
54 62
 
55 63
 	private function createHook($newRules, $pseudoMatcher, $properties) {
56 64
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet));
57
-		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
65
+		foreach ($properties as $name => $property) {
66
+			$hook->registerProperty($name, $property);
67
+		}
58 68
 		return $hook;
59 69
 	}
60 70
 }
Please login to merge, or discard this patch.
src/Property/Display.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,8 +7,12 @@
 block discarded – undo
7 7
 namespace Transphporm\Property;
8 8
 class Display implements \Transphporm\Property {
9 9
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
10
-		if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr'));
11
-		else if (strtolower($values[0]) === 'none') $element->setAttribute('transphporm', 'remove');
12
-		else $element->setAttribute('transphporm', 'show');
10
+		if ($pseudoMatcher->hasFunction('attr')) {
11
+			$element->removeAttribute($pseudoMatcher->getFuncArgs('attr'));
12
+		} else if (strtolower($values[0]) === 'none') {
13
+			$element->setAttribute('transphporm', 'remove');
14
+		} else {
15
+			$element->setAttribute('transphporm', 'show');
16
+		}
13 17
 	}
14 18
 }
15 19
\ No newline at end of file
Please login to merge, or discard this patch.
src/Pseudo/Attribute.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 
26 26
 		$valueParser = new \Transphporm\Parser\Value($this->functionSet);
27 27
 
28
-		$criteria = $name . '(' . $criteria;
28
+		$criteria = $name.'('.$criteria;
29 29
 
30 30
 		$pos = strpos($pseudo, '!');
31 31
 		if ($pos === false) $pos = strpos($pseudo, '=');
Please login to merge, or discard this patch.
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,10 +15,14 @@  discard block
 block discarded – undo
15 15
 	public function match($pseudo, \DomElement $element) {
16 16
 
17 17
 		$pos = strpos($pseudo, '[');
18
-		if ($pos === false) return true;
18
+		if ($pos === false) {
19
+			return true;
20
+		}
19 21
 
20 22
 		$name = substr($pseudo, 0, $pos);
21
-		if (!$this->functionSet->hasFunction($name)) return true;
23
+		if (!$this->functionSet->hasFunction($name)) {
24
+			return true;
25
+		}
22 26
 
23 27
 		$bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo);
24 28
 		$criteria = $bracketMatcher->match('[', ']');
@@ -28,11 +32,14 @@  discard block
 block discarded – undo
28 32
 		$criteria = $name . '(' . $criteria;
29 33
 
30 34
 		$pos = strpos($pseudo, '!');
31
-		if ($pos === false) $pos = strpos($pseudo, '=');
35
+		if ($pos === false) {
36
+			$pos = strpos($pseudo, '=');
37
+		}
32 38
 		if ($pos === false) {
33 39
 			$criteria .= ')=true';
40
+		} else {
41
+			$criteria = substr_replace($criteria, ')', $pos, 0);
34 42
 		}
35
-		else $criteria = substr_replace($criteria, ')', $pos, 0);
36 43
 
37 44
 		return $valueParser->parse($criteria, $element)[0];
38 45
 	}
Please login to merge, or discard this patch.
src/TSSFunction/Data.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  * @version         1.0                                                             */
7 7
 namespace Transphporm\TSSFunction;
8 8
 /* Handles data() and iteration() function calls from the stylesheet */
9
-class Data implements \Transphporm\TSSFunction{
9
+class Data implements \Transphporm\TSSFunction {
10 10
 	private $data;
11 11
 	private $dataKey;
12 12
 	private $functionSet;
Please login to merge, or discard this patch.
src/Parser/Value.php 1 patch
Braces   +45 added lines, -29 removed lines patch added patch discarded remove patch
@@ -61,7 +61,9 @@  discard block
 block discarded – undo
61 61
 		$this->data = $data;
62 62
 		$this->last = null;
63 63
 
64
-		if (empty($tokens)) return [$this->data];
64
+		if (empty($tokens)) {
65
+			return [$this->data];
66
+		}
65 67
 		
66 68
 		foreach ($tokens as $token) {
67 69
 			$this->{$this->tokenFuncs[$token['type']]}($token);	
@@ -75,27 +77,36 @@  discard block
 block discarded – undo
75 77
 
76 78
 		if ($this->mode == Tokenizer::NOT && $token['type'] == Tokenizer::EQUALS) {
77 79
 			$this->mode = Tokenizer::NOT;
80
+		} else {
81
+			$this->mode = $token['type'];
78 82
 		}
79
-		else $this->mode = $token['type'];
80 83
 	}
81 84
 
82 85
 
83 86
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
84 87
 	private function moveLastToData() {
85
-		if (isset($this->data->{$this->last})) $this->data = $this->data->{$this->last};
86
-		else if (is_array($this->data) && isset($this->data[$this->last])) $this->data = $this->data[$this->last];
88
+		if (isset($this->data->{$this->last})) {
89
+			$this->data = $this->data->{$this->last};
90
+		} else if (is_array($this->data) && isset($this->data[$this->last])) {
91
+			$this->data = $this->data[$this->last];
92
+		}
87 93
 	}
88 94
 
89 95
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
90 96
 	private function processDot($token) {
91
-		if ($this->last !== null) $this->moveLastToData();
92
-		else $this->data = array_pop($this->result);
97
+		if ($this->last !== null) {
98
+			$this->moveLastToData();
99
+		} else {
100
+			$this->data = array_pop($this->result);
101
+		}
93 102
 
94 103
 		$this->last = null;
95 104
 	}
96 105
 
97 106
 	private function processSquareBracket($token) {
98
-		if ($this->last !== null) $this->moveLastToData();
107
+		if ($this->last !== null) {
108
+			$this->moveLastToData();
109
+		}
99 110
 
100 111
 		$parser = new Value($this->baseData, $this->autoLookup);
101 112
 		$this->last = $parser->parseTokens($token['value'], null)[0];
@@ -118,15 +129,15 @@  discard block
 block discarded – undo
118 129
 	private function processBrackets($token) {
119 130
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
120 131
 			$this->callTransphpormFunctions($token);
121
-		}
122
-		else if ($this->data instanceof \Transphporm\Functionset) {
132
+		} else if ($this->data instanceof \Transphporm\Functionset) {
123 133
 			$this->result = $this->processValue($this->data->{$this->last}($token['value']));
124 134
 			$this->last = null;
125
-		}
126
-		else {
135
+		} else {
127 136
 			$parser = new Value($this->baseData, $this->autoLookup);
128 137
 			$args = $parser->parseTokens($token['value'], $this->data);
129
-			if ($args[0] == $this->data) $args = [];
138
+			if ($args[0] == $this->data) {
139
+				$args = [];
140
+			}
130 141
 			$funcResult = $this->callFunc($this->last, $args, $this->data);
131 142
 			$this->result = $this->processValue($funcResult);
132 143
 			$this->last = null;
@@ -137,9 +148,12 @@  discard block
 block discarded – undo
137 148
 		$this->result = $this->processValue($this->baseData->{$this->last}($token['value']));
138 149
 		foreach ($this->result as $i => $value) {
139 150
 			if (is_array($this->data)) {
140
-				if (isset($this->data[$value])) $this->result[$i] = $this->data[$value];
151
+				if (isset($this->data[$value])) {
152
+					$this->result[$i] = $this->data[$value];
153
+				}
154
+			} else if (is_scalar($value) && isset($this->data->$value)) {
155
+				$this->result[$i] = $this->data->$value;
141 156
 			}
142
-			else if (is_scalar($value) && isset($this->data->$value)) $this->result[$i] = $this->data->$value;
143 157
 		}
144 158
 		$this->last = null;
145 159
 	}
@@ -149,12 +163,12 @@  discard block
 block discarded – undo
149 163
 		if ($this->last !== null) {
150 164
 			try {
151 165
 				$this->result = $this->extractLast($this->result);
152
-			}
153
-			catch (\UnexpectedValueException $e) {
166
+			} catch (\UnexpectedValueException $e) {
154 167
 				if (!$this->autoLookup) {
155 168
 					$this->result = $this->processValue($this->last);
169
+				} else {
170
+					$this->result = [false];
156 171
 				}
157
-				else $this->result = [false];			
158 172
 			}			
159 173
 		}
160 174
 		return $this->result;
@@ -166,8 +180,7 @@  discard block
 block discarded – undo
166 180
 	private function extractLast($result) {
167 181
 		if ($this->autoLookup && isset($this->data->{$this->last})) {
168 182
 			return $this->processValue($this->data->{$this->last});
169
-		}
170
-		else if (is_array($this->data) && isset($this->data[$this->last])) {
183
+		} else if (is_array($this->data) && isset($this->data[$this->last])) {
171 184
 			return $this->processValue($this->data[$this->last]);
172 185
 		}
173 186
 		throw new \UnexpectedValueException('Not found');
@@ -178,14 +191,11 @@  discard block
 block discarded – undo
178 191
 	private function processValue($newValue) {
179 192
 		if ($this->mode == Tokenizer::ARG) {
180 193
 			$this->result[] = $newValue;
181
-		}
182
-		else if ($this->mode == Tokenizer::CONCAT) {
194
+		} else if ($this->mode == Tokenizer::CONCAT) {
183 195
 				$this->result[count($this->result)-1] .= $newValue;
184
-		}
185
-		else if ($this->mode == Tokenizer::NOT) {
196
+		} else if ($this->mode == Tokenizer::NOT) {
186 197
 			$this->result[count($this->result)-1] = $this->result[count($this->result)-1] != $newValue;
187
-		}
188
-		else if ($this->mode == Tokenizer::EQUALS) {
198
+		} else if ($this->mode == Tokenizer::EQUALS) {
189 199
 			$this->result[count($this->result)-1] = $this->result[count($this->result)-1] == $newValue;
190 200
 		}
191 201
 
@@ -193,12 +203,18 @@  discard block
 block discarded – undo
193 203
 	}
194 204
 
195 205
 	private function callFunc($name, $args, $data) {
196
-		if ($this->data instanceof \Transphporm\FunctionSet) return $this->data->$name($args);
197
-		else return $this->callFuncOnObject($this->data, $name, $args);
206
+		if ($this->data instanceof \Transphporm\FunctionSet) {
207
+			return $this->data->$name($args);
208
+		} else {
209
+			return $this->callFuncOnObject($this->data, $name, $args);
210
+		}
198 211
 	}
199 212
 
200 213
 	private function callFuncOnObject($obj, $func, $args) {
201
-		if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args);
202
-		else return call_user_func_array([$obj, $func], $args);
214
+		if (isset($obj->$func) && is_callable($obj->$func)) {
215
+			return call_user_func_array($obj->$func, $args);
216
+		} else {
217
+			return call_user_func_array([$obj, $func], $args);
218
+		}
203 219
 	}
204 220
 }
Please login to merge, or discard this patch.
src/TSSFunction/Json.php 3 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,25 +1,25 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Transphporm\TSSFunction;
3 3
 class Json implements \Transphporm\TSSFunction {
4
-    private $baseDir;
4
+	private $baseDir;
5 5
 
6
-    public function __construct(&$baseDir) {
7
-        $this->baseDir = &$baseDir;
8
-    }
6
+	public function __construct(&$baseDir) {
7
+		$this->baseDir = &$baseDir;
8
+	}
9 9
 
10
-    public function run(array $args, \DomElement $element = null) {
11
-        $json = $args[0];
10
+	public function run(array $args, \DomElement $element = null) {
11
+		$json = $args[0];
12 12
 
13
-        if (trim($json)[0] != '{') {
14
-            $path = $this->baseDir . $json;
15
-            if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
16
-            $json = file_get_contents($json);
17
-        }
13
+		if (trim($json)[0] != '{') {
14
+			$path = $this->baseDir . $json;
15
+			if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
16
+			$json = file_get_contents($json);
17
+		}
18 18
 
19
-        $map = json_decode($json, true);
19
+		$map = json_decode($json, true);
20 20
 
21
-        if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
21
+		if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
22 22
 
23
-        return $map;
24
-    }
23
+		return $map;
24
+	}
25 25
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@
 block discarded – undo
11 11
         $json = $args[0];
12 12
 
13 13
         if (trim($json)[0] != '{') {
14
-            $path = $this->baseDir . $json;
15
-            if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
14
+            $path = $this->baseDir.$json;
15
+            if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path);
16 16
             $json = file_get_contents($json);
17 17
         }
18 18
 
19 19
         $map = json_decode($json, true);
20 20
 
21
-        if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
21
+        if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg());
22 22
 
23 23
         return $map;
24 24
     }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,13 +12,17 @@
 block discarded – undo
12 12
 
13 13
         if (trim($json)[0] != '{') {
14 14
             $path = $this->baseDir . $json;
15
-            if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
15
+            if (!file_exists($path)) {
16
+            	throw new \Exception('File does not exist at: ' . $path);
17
+            }
16 18
             $json = file_get_contents($json);
17 19
         }
18 20
 
19 21
         $map = json_decode($json, true);
20 22
 
21
-        if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
23
+        if (!is_array($map)) {
24
+        	throw new \Exception('Could not decode json: ' . json_last_error_msg());
25
+        }
22 26
 
23 27
         return $map;
24 28
     }
Please login to merge, or discard this patch.