Completed
Branch tokens-class (82c54a)
by Tom
03:42
created
src/Hook/PropertyHook.php 1 patch
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -26,9 +26,13 @@  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
 		// TODO: Have all rule values parsed before running them so that things like `content-append` are not expecting tokens
34 38
 		// problem with this is that anything in data changed by run properties is not shown
@@ -36,7 +40,9 @@  discard block
 block discarded – undo
36 40
 
37 41
 		foreach ($this->rules as $name => $value) {
38 42
 			$result = $this->callProperty($name, $element, $this->getArgs($value, $element));
39
-			if ($result === false) break;
43
+			if ($result === false) {
44
+				break;
45
+			}
40 46
 		}
41 47
 	}
42 48
 
@@ -49,6 +55,8 @@  discard block
 block discarded – undo
49 55
 	}
50 56
 
51 57
 	private function callProperty($name, $element, $value) {
52
-		if (isset($this->properties[$name])) return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
58
+		if (isset($this->properties[$name])) {
59
+			return $this->properties[$name]->run($value, $element, $this->rules, $this->pseudoMatcher, $this->properties);
60
+		}
53 61
 	}
54 62
 }
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
@@ -18,12 +18,16 @@  discard block
 block discarded – undo
18 18
 
19 19
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
20 20
 		$values = $this->fixEmpty($values);
21
-		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
21
+		if ($element->getAttribute('transphporm') === 'added') {
22
+			return $element->parentNode->removeChild($element);
23
+		}
22 24
 		$max = $this->getMax($values);
23 25
 		$count = 0;
24 26
 
25 27
 		foreach ($values[0] as $key => $iteration) {
26
-			if ($count+1 > $max) break;
28
+			if ($count+1 > $max) {
29
+				break;
30
+			}
27 31
 			$clone = $this->cloneElement($element, $iteration, $key, $count++);
28 32
 			//Re-run the hook on the new element, but use the iterated data
29 33
 			//Don't run repeat on the clones element or it will loop forever
@@ -46,13 +50,17 @@  discard block
 block discarded – undo
46 50
 	}
47 51
 
48 52
 	private function fixEmpty($value) {
49
- 		if (empty($value[0])) $value[0] = [];
53
+ 		if (empty($value[0])) {
54
+ 			$value[0] = [];
55
+ 		}
50 56
  		return $value;
51 57
  	}
52 58
 
53 59
 	private function tagElement($element, $count) {
54 60
 		//Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed
55
-		if ($count > 0) $element->setAttribute('transphporm', 'added');
61
+		if ($count > 0) {
62
+			$element->setAttribute('transphporm', 'added');
63
+		}
56 64
 	}
57 65
 
58 66
 	private function getMax($values) {
@@ -61,7 +69,9 @@  discard block
 block discarded – undo
61 69
 
62 70
 	private function createHook($newRules, $pseudoMatcher, $properties) {
63 71
 		$hook = new \Transphporm\Hook\PropertyHook($newRules, $this->baseDir, $this->baseDir, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet);
64
-		foreach ($properties as $name => $property) $hook->registerProperty($name, $property);
72
+		foreach ($properties as $name => $property) {
73
+			$hook->registerProperty($name, $property);
74
+		}
65 75
 		return $hook;
66 76
 	}
67 77
 }
Please login to merge, or discard this patch.
src/Parser/Tokens.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -6,28 +6,28 @@  discard block
 block discarded – undo
6 6
  * @version         1.0                                                             */
7 7
 namespace Transphporm\Parser;
8 8
 class Tokens implements \Iterator, \Countable {
9
-    private $tokens;
10
-    private $iterator = 0;
9
+	private $tokens;
10
+	private $iterator = 0;
11 11
 
12
-    public function __construct(array $tokens) {
13
-        $this->tokens = $tokens;
14
-    }
12
+	public function __construct(array $tokens) {
13
+		$this->tokens = $tokens;
14
+	}
15 15
 
16
-    public function count() {
17
-        return count($this->tokens);
18
-    }
16
+	public function count() {
17
+		return count($this->tokens);
18
+	}
19 19
 
20
-    // Iterator Functions
21
-    public function current() {
22
-        return $this->tokens[$this->iterator];
23
-    }
20
+	// Iterator Functions
21
+	public function current() {
22
+		return $this->tokens[$this->iterator];
23
+	}
24 24
 
25
-    public function key() {
26
-        return $this->iterator;
27
-    }
25
+	public function key() {
26
+		return $this->iterator;
27
+	}
28 28
 
29
-    public function next() {
30
-        ++$this->iterator;
29
+	public function next() {
30
+		++$this->iterator;
31 31
 	}
32 32
 
33 33
 	public function valid() {
@@ -38,63 +38,63 @@  discard block
 block discarded – undo
38 38
 		$this->iterator = 0;
39 39
 	}
40 40
 
41
-    private function getKeysOfTokenType($tokenType) {
42
-        return array_keys(array_column($this->tokens, 'type'), $tokenType);
43
-    }
41
+	private function getKeysOfTokenType($tokenType) {
42
+		return array_keys(array_column($this->tokens, 'type'), $tokenType);
43
+	}
44 44
 
45
-    public function from($tokenType, $inclusive = false) {
46
-        $keys = $this->getKeysOfTokenType($tokenType);
47
-        if (count($keys) === 0) return new Tokens([]);
48
-        $key = $keys[0];
49
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
50
-        if (!$inclusive) $key++;
51
-        return new Tokens(array_slice($this->tokens, $key));
52
-    }
45
+	public function from($tokenType, $inclusive = false) {
46
+		$keys = $this->getKeysOfTokenType($tokenType);
47
+		if (count($keys) === 0) return new Tokens([]);
48
+		$key = $keys[0];
49
+		for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
50
+		if (!$inclusive) $key++;
51
+		return new Tokens(array_slice($this->tokens, $key));
52
+	}
53 53
 
54
-    public function to($tokenType, $inclusive = false) {
55
-        $keys = $this->getKeysOfTokenType($tokenType);
56
-        if (empty($keys)) return new Tokens([]);
57
-        $key = $keys[0];
58
-        for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
59
-        if ($inclusive) $key++;
60
-        return new Tokens(array_slice($this->tokens, 0, $key));
61
-    }
54
+	public function to($tokenType, $inclusive = false) {
55
+		$keys = $this->getKeysOfTokenType($tokenType);
56
+		if (empty($keys)) return new Tokens([]);
57
+		$key = $keys[0];
58
+		for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i];
59
+		if ($inclusive) $key++;
60
+		return new Tokens(array_slice($this->tokens, 0, $key));
61
+	}
62 62
 
63
-    public function skip($count) {
64
-        $this->iterator += $count;
65
-    }
63
+	public function skip($count) {
64
+		$this->iterator += $count;
65
+	}
66 66
 
67
-    public function splitOnToken($tokenType) {
68
-        $splitTokens = [];
67
+	public function splitOnToken($tokenType) {
68
+		$splitTokens = [];
69 69
 		$i = 0;
70 70
 		foreach ($this->tokens as $token) {
71 71
 			if ($token['type'] === $tokenType) $i++;
72 72
 			else $splitTokens[$i][] = $token;
73 73
 		}
74
-        return array_map(function ($tokens) {
75
-            return new Tokens($tokens);
76
-        }, $splitTokens);
74
+		return array_map(function ($tokens) {
75
+			return new Tokens($tokens);
76
+		}, $splitTokens);
77 77
 		//return $splitTokens;
78
-    }
78
+	}
79 79
 
80
-    public function trim() {
81
-        $tokens = $this->tokens;
82
-        // Remove end whitespace
83
-        while (end($tokens)['type'] === Tokenizer::WHITESPACE) {
84
-            array_pop($tokens);
85
-        }
86
-        // Remove begining whitespace
87
-        while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) {
88
-            array_shift($tokens);
89
-        }
90
-        return new Tokens($tokens);
91
-    }
80
+	public function trim() {
81
+		$tokens = $this->tokens;
82
+		// Remove end whitespace
83
+		while (end($tokens)['type'] === Tokenizer::WHITESPACE) {
84
+			array_pop($tokens);
85
+		}
86
+		// Remove begining whitespace
87
+		while (isset($tokens[0]) && $tokens[0]['type'] === Tokenizer::WHITESPACE) {
88
+			array_shift($tokens);
89
+		}
90
+		return new Tokens($tokens);
91
+	}
92 92
 
93
-    public function read($offset = 0) {
94
-        return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false;
95
-    }
93
+	public function read($offset = 0) {
94
+		return isset($this->tokens[$offset]) ? $this->tokens[$offset]['value'] : false;
95
+	}
96 96
 
97
-    public function type($offset = 0) {
98
-        return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false;   
99
-    }
97
+	public function type($offset = 0) {
98
+		return isset($this->tokens[$offset]) ? $this->tokens[$offset]['type'] : false;   
99
+	}
100 100
 }
Please login to merge, or discard this patch.
src/Parser/Sheet.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,9 @@  discard block
 block discarded – undo
33 33
 			}
34 34
 			$selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE);
35 35
 			$this->tss->skip(count($selector));
36
-			if (count($selector) === 0) break;
36
+			if (count($selector) === 0) {
37
+				break;
38
+			}
37 39
 
38 40
 			$newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value']));
39 41
 			$rules = $this->writeRule($rules, $newRules);
@@ -44,7 +46,9 @@  discard block
 block discarded – undo
44 46
 	}
45 47
 
46 48
 	private function checkError($rules) {
47
-		if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed');
49
+		if (empty($rules) && count($this->tss) > 0) {
50
+			throw new \Exception('No TSS rules parsed');
51
+		}
48 52
 	}
49 53
 
50 54
 	private function CssToRules($selector, $index, $properties) {
@@ -71,7 +75,9 @@  discard block
 block discarded – undo
71 75
 	}
72 76
 
73 77
 	private function processingInstructions($token, $indexStart) {
74
-		if ($token['type'] !== Tokenizer::AT_SIGN) return false;
78
+		if ($token['type'] !== Tokenizer::AT_SIGN) {
79
+			return false;
80
+		}
75 81
 		$tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false);
76 82
 		$funcName = $tokens->from(Tokenizer::NAME, true)->read();
77 83
 		$args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME));
@@ -88,7 +94,9 @@  discard block
 block discarded – undo
88 94
 
89 95
 	private function sortRules($a, $b) {
90 96
 		//If they have the same depth, compare on index
91
-		if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1;
97
+		if ($a->depth === $b->depth) {
98
+			return $a->index < $b->index ? -1 : 1;
99
+		}
92 100
 
93 101
 		return ($a->depth < $b->depth) ? -1 : 1;
94 102
 	}
@@ -97,7 +105,9 @@  discard block
 block discarded – undo
97 105
 		$pos = 0;
98 106
 		while (($pos = strpos($str, $open, $pos)) !== false) {
99 107
 			$end = strpos($str, $close, $pos);
100
-			if ($end === false) break;
108
+			if ($end === false) {
109
+				break;
110
+			}
101 111
 			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
102 112
 		}
103 113
 
Please login to merge, or discard this patch.