@@ -26,9 +26,13 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -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 |
@@ -46,13 +50,17 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -33,7 +33,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |