@@ -25,7 +25,9 @@ discard block |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function parse($indexStart = 0) { |
| 28 | - if (!empty($this->rules)) return $this->rules['rules']; |
|
| 28 | + if (!empty($this->rules)) { |
|
| 29 | + return $this->rules['rules']; |
|
| 30 | + } |
|
| 29 | 31 | $rules = $this->parseTokens($indexStart); |
| 30 | 32 | $this->checkError($rules); |
| 31 | 33 | return $rules; |
@@ -36,8 +38,9 @@ discard block |
||
| 36 | 38 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
| 37 | 39 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
| 38 | 40 | $this->rules = array_merge($this->rules, $processing); |
| 41 | + } else if (!in_array($token['type'], [Tokenizer::NEW_LINE, Tokenizer::AT_SIGN])) { |
|
| 42 | + $this->addRules($token, $indexStart++); |
|
| 39 | 43 | } |
| 40 | - else if (!in_array($token['type'], [Tokenizer::NEW_LINE, Tokenizer::AT_SIGN])) $this->addRules($token, $indexStart++); |
|
| 41 | 44 | } |
| 42 | 45 | |
| 43 | 46 | return $this->rules; |
@@ -47,13 +50,17 @@ discard block |
||
| 47 | 50 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
| 48 | 51 | |
| 49 | 52 | $this->tss->skip(count($selector)); |
| 50 | - if (count($selector) === 0) return; |
|
| 53 | + if (count($selector) === 0) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 51 | 56 | $newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']); |
| 52 | 57 | $this->rules = $this->writeRule($this->rules, $newRules); |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | 60 | private function checkError($rules) { |
| 56 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
| 61 | + if (empty($rules) && count($this->tss) > 0) { |
|
| 62 | + throw new \Exception('No TSS rules parsed'); |
|
| 63 | + } |
|
| 57 | 64 | } |
| 58 | 65 | |
| 59 | 66 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -80,7 +87,9 @@ discard block |
||
| 80 | 87 | } |
| 81 | 88 | |
| 82 | 89 | private function processingInstructions($token, $indexStart) { |
| 83 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
| 90 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
| 91 | + return false; |
|
| 92 | + } |
|
| 84 | 93 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
| 85 | 94 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
| 86 | 95 | $funcToks = $tokens->from(Tokenizer::NAME); |
@@ -110,7 +119,9 @@ discard block |
||
| 110 | 119 | foreach ($rules as $rule) { |
| 111 | 120 | $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
| 112 | 121 | $tokens = $rule->from(Tokenizer::COLON)->trim(); |
| 113 | - if (count($tokens) > 0) $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
| 122 | + if (count($tokens) > 0) { |
|
| 123 | + $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
| 124 | + } |
|
| 114 | 125 | } |
| 115 | 126 | |
| 116 | 127 | return $return; |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 24 | 24 | $values = $this->fixEmpty($values); |
| 25 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
| 25 | + if ($element->getAttribute('transphporm') === 'added') { |
|
| 26 | + return $element->parentNode->removeChild($element); |
|
| 27 | + } |
|
| 26 | 28 | $this->handleContentModeAppend($element, $rules); |
| 27 | 29 | $max = $this->getMax($values); |
| 28 | 30 | $count = 0; |
@@ -36,10 +38,14 @@ discard block |
||
| 36 | 38 | |
| 37 | 39 | |
| 38 | 40 | foreach ($repeat as $key => $iteration) { |
| 39 | - if ($count+1 > $max) break; |
|
| 41 | + if ($count+1 > $max) { |
|
| 42 | + break; |
|
| 43 | + } |
|
| 40 | 44 | $clone = $this->cloneElement($element, $iteration, $key, $count++); |
| 41 | 45 | //Re-run the hook on the new element, but use the iterated data |
| 42 | - if ($hook) $hook->run($clone); |
|
| 46 | + if ($hook) { |
|
| 47 | + $hook->run($clone); |
|
| 48 | + } |
|
| 43 | 49 | } |
| 44 | 50 | |
| 45 | 51 | //Remove the original element |
@@ -73,7 +79,9 @@ discard block |
||
| 73 | 79 | } |
| 74 | 80 | |
| 75 | 81 | private function fixEmpty($value) { |
| 76 | - if (empty($value[0])) $value[0] = []; |
|
| 82 | + if (empty($value[0])) { |
|
| 83 | + $value[0] = []; |
|
| 84 | + } |
|
| 77 | 85 | return $value; |
| 78 | 86 | } |
| 79 | 87 | |
@@ -89,7 +97,9 @@ discard block |
||
| 89 | 97 | |
| 90 | 98 | private function tagElement($element, $count) { |
| 91 | 99 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
| 92 | - if ($count > 0) $element->setAttribute('transphporm', 'added'); |
|
| 100 | + if ($count > 0) { |
|
| 101 | + $element->setAttribute('transphporm', 'added'); |
|
| 102 | + } |
|
| 93 | 103 | } |
| 94 | 104 | |
| 95 | 105 | private function getMax($values) { |
@@ -101,10 +111,14 @@ discard block |
||
| 101 | 111 | // for this rule e.g. repeat: data(); content: "foo" |
| 102 | 112 | // The content property still needs to be used |
| 103 | 113 | // But for rules that are just { repeat: data(); } this can be skipped. |
| 104 | - if (empty($newRules)) return false; |
|
| 114 | + if (empty($newRules)) { |
|
| 115 | + return false; |
|
| 116 | + } |
|
| 105 | 117 | |
| 106 | 118 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $this->line, null, $this->line, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet), $this->functionSet, $this->filePath); |
| 107 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
| 119 | + foreach ($properties as $name => $property) { |
|
| 120 | + $hook->registerProperty($name, $property); |
|
| 121 | + } |
|
| 108 | 122 | return $hook; |
| 109 | 123 | } |
| 110 | 124 | } |