Completed
Branch tokens-class (c88dd8)
by Tom
03:17
created
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/TSSFunction/Data.php 2 patches
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.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,11 @@
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	public function run(array $args, \DomElement $element = null) {
21
-		if ($this->dataKey === "root") $data = $this->data->getData(null, 'data');
22
-		else $data = $this->data->getData($element, $this->dataKey);
21
+		if ($this->dataKey === "root") {
22
+			$data = $this->data->getData(null, 'data');
23
+		} else {
24
+			$data = $this->data->getData($element, $this->dataKey);
25
+		}
23 26
 		$parser = new \Transphporm\Parser\Value($this->functionSet, true);
24 27
 		$return = $parser->parseTokens($args, $data);
25 28
 		return $return[0];
Please login to merge, or discard this patch.
src/Hook/PropertyHook.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -31,6 +31,9 @@  discard block
 block discarded – undo
31 31
 		}
32 32
 	}
33 33
 
34
+	/**
35
+	 * @param \DOMElement $element
36
+	 */
34 37
 	private function getArgs($value, $element) {
35 38
 		return $this->valueParser->parse($value, $element);
36 39
 	}
@@ -39,6 +42,9 @@  discard block
 block discarded – undo
39 42
 		$this->properties[$name] = $property;
40 43
 	}
41 44
 
45
+	/**
46
+	 * @param \DOMElement $element
47
+	 */
42 48
 	private function callProperty($name, $element, $value) {
43 49
 		if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
44 50
 		return false;
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,13 +26,19 @@  discard block
 block discarded – undo
26 26
 
27 27
 	public function run(\DomElement $element) {
28 28
 		$this->functionSet->setElement($element);
29
-		if ($this->origBaseDir !== $this->newBaseDir) $this->origBaseDir = $this->newBaseDir;
29
+		if ($this->origBaseDir !== $this->newBaseDir) {
30
+			$this->origBaseDir = $this->newBaseDir;
31
+		}
30 32
 		//Don't run if there's a pseudo element like nth-child() and this element doesn't match it
31
-		if (!$this->pseudoMatcher->matches($element)) return;
33
+		if (!$this->pseudoMatcher->matches($element)) {
34
+			return;
35
+		}
32 36
 
33 37
 		foreach ($this->rules as $name => $value) {
34 38
 			$result = $this->callProperty($name, $element, $this->getArgs($value, $element));
35
-			if ($result === false) break;
39
+			if ($result === false) {
40
+				break;
41
+			}
36 42
 		}
37 43
 	}
38 44
 
@@ -45,8 +51,12 @@  discard block
 block discarded – undo
45 51
 	}
46 52
 
47 53
 	private function callProperty($name, $element, $value) {
48
-		if (empty($value[0])) $value[0] = [];
49
-		if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
54
+		if (empty($value[0])) {
55
+			$value[0] = [];
56
+		}
57
+		if (isset($this->properties[$name])) {
58
+			return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
59
+		}
50 60
 		return false;
51 61
 	}
52 62
 }
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.
src/Config.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,12 +67,16 @@
 block discarded – undo
67 67
 	}
68 68
 
69 69
 	public function loadProperties(Hook\PropertyHook $hook) {
70
-		foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property);
70
+		foreach ($this->properties as $name => $property) {
71
+			$hook->registerProperty($name, $property);
72
+		}
71 73
 	}
72 74
 
73 75
 	public function createPseudoMatcher($pseudo) {
74 76
 		$pseudoMatcher = new Hook\PseudoMatcher($pseudo);
75
-		foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction);
77
+		foreach ($this->pseudo as $pseudoFunction) {
78
+			$pseudoMatcher->registerFunction($pseudoFunction);
79
+		}
76 80
 		return $pseudoMatcher;
77 81
 	}
78 82
 
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/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.
src/Pseudo/Nth.php 1 patch
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,7 +9,9 @@  discard block
 block discarded – undo
9 9
 class Nth implements \Transphporm\Pseudo {
10 10
 
11 11
 	public function match($name, $args, \DomElement $element) {
12
-		if ($name !== 'nth-child') return true;
12
+		if ($name !== 'nth-child') {
13
+			return true;
14
+		}
13 15
 
14 16
 		$criteria = $args[0];
15 17
 
@@ -18,8 +20,11 @@  discard block
 block discarded – undo
18 20
 		$pseudo = $tokenizer->getTokens();
19 21
 		$num = end($pseudo)['value'][0]['value'];
20 22
 
21
-		if (is_callable([$this, $criteria])) return $this->$criteria($num);
22
-		else return $num == $criteria;
23
+		if (is_callable([$this, $criteria])) {
24
+			return $this->$criteria($num);
25
+		} else {
26
+			return $num == $criteria;
27
+		}
23 28
 	}
24 29
 
25 30
 	private function odd($num) {
Please login to merge, or discard this patch.
src/Pseudo/Not.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
 	}
17 17
 
18 18
 	public function match($name, $args, \DomElement $element) {
19
-		if ($name !== 'not') return true;
19
+		if ($name !== 'not') {
20
+			return true;
21
+		}
20 22
 		
21 23
 		$xpath = new \DomXpath($element->ownerDocument);
22 24
 		return $this->notElement($args, $xpath, $element);
@@ -29,7 +31,9 @@  discard block
 block discarded – undo
29 31
 			//Find all nodes matched by the expressions in the brackets :not(EXPR)
30 32
 			foreach ($xpath->query($xpathString) as $matchedElement) {
31 33
 				//Check to see whether this node was matched by the not query
32
-				if ($element->isSameNode($matchedElement)) return false;
34
+				if ($element->isSameNode($matchedElement)) {
35
+					return false;
36
+				}
33 37
 			}
34 38
 		}
35 39
 		return true;
Please login to merge, or discard this patch.