@@ -18,12 +18,16 @@ discard block |
||
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 |
@@ -36,7 +40,9 @@ discard block |
||
36 | 40 | } |
37 | 41 | |
38 | 42 | private function fixEmpty($value) { |
39 | - if (empty($value[0])) $value[0] = []; |
|
43 | + if (empty($value[0])) { |
|
44 | + $value[0] = []; |
|
45 | + } |
|
40 | 46 | return $value; |
41 | 47 | } |
42 | 48 | |
@@ -52,7 +58,9 @@ discard block |
||
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 |
||
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 | } |
@@ -35,7 +35,9 @@ |
||
35 | 35 | |
36 | 36 | public function rewind() { |
37 | 37 | $this->tokens->rewind(); |
38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
38 | + while ($this->shouldContinue()) { |
|
39 | + $this->tokens->next(); |
|
40 | + } |
|
39 | 41 | } |
40 | 42 | |
41 | 43 | private function shouldContinue() { |
@@ -44,23 +44,35 @@ discard block |
||
44 | 44 | |
45 | 45 | private function getKeyToSlice($tokenType) { |
46 | 46 | $keys = $this->getKeysOfTokenType($tokenType); |
47 | - if (empty($keys)) return false; |
|
47 | + if (empty($keys)) { |
|
48 | + return false; |
|
49 | + } |
|
48 | 50 | $key = $keys[0]; |
49 | - for ($i = 0; $key < $this->iterator; $i++) $key = $keys[$i]; |
|
51 | + for ($i = 0; $key < $this->iterator; $i++) { |
|
52 | + $key = $keys[$i]; |
|
53 | + } |
|
50 | 54 | return $key; |
51 | 55 | } |
52 | 56 | |
53 | 57 | public function from($tokenType, $inclusive = false) { |
54 | 58 | $key = $this->getKeyToSlice($tokenType); |
55 | - if ($key === false) return new Tokens([]); |
|
56 | - if (!$inclusive) $key++; |
|
59 | + if ($key === false) { |
|
60 | + return new Tokens([]); |
|
61 | + } |
|
62 | + if (!$inclusive) { |
|
63 | + $key++; |
|
64 | + } |
|
57 | 65 | return new Tokens(array_slice($this->tokens, $key)); |
58 | 66 | } |
59 | 67 | |
60 | 68 | public function to($tokenType, $inclusive = false) { |
61 | 69 | $key = $this->getKeyToSlice($tokenType); |
62 | - if ($key === false) return new Tokens([]); |
|
63 | - if ($inclusive) $key++; |
|
70 | + if ($key === false) { |
|
71 | + return new Tokens([]); |
|
72 | + } |
|
73 | + if ($inclusive) { |
|
74 | + $key++; |
|
75 | + } |
|
64 | 76 | return new Tokens(array_slice($this->tokens, 0, $key)); |
65 | 77 | } |
66 | 78 | |
@@ -72,8 +84,11 @@ discard block |
||
72 | 84 | $splitTokens = []; |
73 | 85 | $i = 0; |
74 | 86 | foreach ($this->tokens as $token) { |
75 | - if ($token['type'] === $tokenType) $i++; |
|
76 | - else $splitTokens[$i][] = $token; |
|
87 | + if ($token['type'] === $tokenType) { |
|
88 | + $i++; |
|
89 | + } else { |
|
90 | + $splitTokens[$i][] = $token; |
|
91 | + } |
|
77 | 92 | } |
78 | 93 | return array_map(function ($tokens) { |
79 | 94 | return new Tokens($tokens); |