Completed
Push — master ( 4ed61c...926afa )
by Tom
03:17
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/TSSFunction/Json.php 3 patches
Indentation   +12 added lines, -12 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);
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 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
-                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.
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 (!is_callable([$this->functionSet, $name])) return true;
23
+		if (!is_callable([$this->functionSet, $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   +48 added lines, -30 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
 	public function parse($str, $element = null, $returnTokens = false) {
53 53
 		$tokenizer = new Tokenizer($str);
54 54
 		$tokens = $tokenizer->getTokens();
55
-		if ($returnTokens) return $tokens;
55
+		if ($returnTokens) {
56
+			return $tokens;
57
+		}
56 58
 		$this->result = $this->parseTokens($tokens, $element, $this->baseData);
57 59
 		return $this->result;
58 60
 	}
@@ -64,7 +66,9 @@  discard block
 block discarded – undo
64 66
 		$this->last = null;
65 67
 		$this->element = $element;
66 68
 
67
-		if (empty($tokens)) return [$this->data];
69
+		if (empty($tokens)) {
70
+			return [$this->data];
71
+		}
68 72
 		
69 73
 		foreach ($tokens as $token) {
70 74
 			$this->{$this->tokenFuncs[$token['type']]}($token);	
@@ -78,27 +82,36 @@  discard block
 block discarded – undo
78 82
 
79 83
 		if ($this->mode == Tokenizer::NOT && $token['type'] == Tokenizer::EQUALS) {
80 84
 			$this->mode = Tokenizer::NOT;
85
+		} else {
86
+			$this->mode = $token['type'];
81 87
 		}
82
-		else $this->mode = $token['type'];
83 88
 	}
84 89
 
85 90
 
86 91
 	//Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value
87 92
 	private function moveLastToData() {
88
-		if (isset($this->data->{$this->last})) $this->data = $this->data->{$this->last};
89
-		else if (is_array($this->data) && isset($this->data[$this->last])) $this->data = $this->data[$this->last];
93
+		if (isset($this->data->{$this->last})) {
94
+			$this->data = $this->data->{$this->last};
95
+		} else if (is_array($this->data) && isset($this->data[$this->last])) {
96
+			$this->data = $this->data[$this->last];
97
+		}
90 98
 	}
91 99
 
92 100
 	//Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar`
93 101
 	private function processDot($token) {
94
-		if ($this->last !== null) $this->moveLastToData();
95
-		else $this->data = array_pop($this->result);
102
+		if ($this->last !== null) {
103
+			$this->moveLastToData();
104
+		} else {
105
+			$this->data = array_pop($this->result);
106
+		}
96 107
 
97 108
 		$this->last = null;
98 109
 	}
99 110
 
100 111
 	private function processSquareBracket($token) {
101
-		if ($this->last !== null) $this->moveLastToData();
112
+		if ($this->last !== null) {
113
+			$this->moveLastToData();
114
+		}
102 115
 
103 116
 		$parser = new Value($this->baseData, $this->autoLookup);
104 117
 		$this->last = $parser->parseTokens($token['value'], $this->element, null)[0];
@@ -121,15 +134,15 @@  discard block
 block discarded – undo
121 134
 	private function processBrackets($token) {
122 135
 		if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) {
123 136
 			$this->callTransphpormFunctions($token);
124
-		}
125
-		else if ($this->data instanceof \Transphporm\Functionset) {
137
+		} else if ($this->data instanceof \Transphporm\Functionset) {
126 138
 			$this->result = $this->processValue($this->data->{$this->last}($token['value'], $this->element));
127 139
 			$this->last = null;
128
-		}
129
-		else {
140
+		} else {
130 141
 			$parser = new Value($this->baseData, $this->autoLookup);
131 142
 			$args = $parser->parseTokens($token['value'], $this->element, $this->data);
132
-			if ($args[0] == $this->data) $args = [];
143
+			if ($args[0] == $this->data) {
144
+				$args = [];
145
+			}
133 146
 			$funcResult = $this->callFunc($this->last, $args, $this->element, $this->data);
134 147
 			$this->result = $this->processValue($funcResult);
135 148
 			$this->last = null;
@@ -140,9 +153,12 @@  discard block
 block discarded – undo
140 153
 		$this->result = $this->processValue($this->baseData->{$this->last}($token['value'], $this->element));
141 154
 		foreach ($this->result as $i => $value) {
142 155
 			if (is_array($this->data)) {
143
-				if (isset($this->data[$value])) $this->result[$i] = $this->data[$value];
156
+				if (isset($this->data[$value])) {
157
+					$this->result[$i] = $this->data[$value];
158
+				}
159
+			} else if (is_scalar($value) && isset($this->data->$value)) {
160
+				$this->result[$i] = $this->data->$value;
144 161
 			}
145
-			else if (is_scalar($value) && isset($this->data->$value)) $this->result[$i] = $this->data->$value;
146 162
 		}
147 163
 		$this->last = null;
148 164
 	}
@@ -152,12 +168,12 @@  discard block
 block discarded – undo
152 168
 		if ($this->last !== null) {
153 169
 			try {
154 170
 				$this->result = $this->extractLast($this->result);
155
-			}
156
-			catch (\UnexpectedValueException $e) {
171
+			} catch (\UnexpectedValueException $e) {
157 172
 				if (!$this->autoLookup) {
158 173
 					$this->result = $this->processValue($this->last);
174
+				} else {
175
+					$this->result = [false];
159 176
 				}
160
-				else $this->result = [false];			
161 177
 			}			
162 178
 		}
163 179
 		return $this->result;
@@ -169,8 +185,7 @@  discard block
 block discarded – undo
169 185
 	private function extractLast($result) {
170 186
 		if ($this->autoLookup && isset($this->data->{$this->last})) {
171 187
 			return $this->processValue($this->data->{$this->last});
172
-		}
173
-		else if (is_array($this->data) && isset($this->data[$this->last])) {
188
+		} else if (is_array($this->data) && isset($this->data[$this->last])) {
174 189
 			return $this->processValue($this->data[$this->last]);
175 190
 		}
176 191
 		throw new \UnexpectedValueException('Not found');
@@ -181,14 +196,11 @@  discard block
 block discarded – undo
181 196
 	private function processValue($newValue) {
182 197
 		if ($this->mode == Tokenizer::ARG) {
183 198
 			$this->result[] = $newValue;
184
-		}
185
-		else if ($this->mode == Tokenizer::CONCAT) {
199
+		} else if ($this->mode == Tokenizer::CONCAT) {
186 200
 				$this->result[count($this->result)-1] .= $newValue;
187
-		}
188
-		else if ($this->mode == Tokenizer::NOT) {
201
+		} else if ($this->mode == Tokenizer::NOT) {
189 202
 			$this->result[count($this->result)-1] = $this->result[count($this->result)-1] != $newValue;
190
-		}
191
-		else if ($this->mode == Tokenizer::EQUALS) {
203
+		} else if ($this->mode == Tokenizer::EQUALS) {
192 204
 			$this->result[count($this->result)-1] = $this->result[count($this->result)-1] == $newValue;
193 205
 		}
194 206
 
@@ -196,12 +208,18 @@  discard block
 block discarded – undo
196 208
 	}
197 209
 
198 210
 	private function callFunc($name, $args, $element, $data) {
199
-		if ($this->data instanceof \Transphporm\FunctionSet) return $this->data->$name($args, $element);
200
-		else return $this->callFuncOnObject($this->data, $name, $args, $element);
211
+		if ($this->data instanceof \Transphporm\FunctionSet) {
212
+			return $this->data->$name($args, $element);
213
+		} else {
214
+			return $this->callFuncOnObject($this->data, $name, $args, $element);
215
+		}
201 216
 	}
202 217
 
203 218
 	private function callFuncOnObject($obj, $func, $args, $element) {
204
-		if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args);
205
-		else return call_user_func_array([$obj, $func], $args);
219
+		if (isset($obj->$func) && is_callable($obj->$func)) {
220
+			return call_user_func_array($obj->$func, $args);
221
+		} else {
222
+			return call_user_func_array([$obj, $func], $args);
223
+		}
206 224
 	}
207 225
 }
Please login to merge, or discard this patch.