@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | $rules = []; |
| 27 | 27 | $numOfTokens = count($this->tss); |
| 28 | 28 | for ($i = 0; isset($this->tss[$i]) && $i <= $numOfTokens; $i++) { |
| 29 | - if ($this->tss[$i]['type'] === Tokenizer::WHITESPACE) continue; |
|
| 29 | + if ($this->tss[$i]['type'] === Tokenizer::WHITESPACE) { |
|
| 30 | + continue; |
|
| 31 | + } |
|
| 30 | 32 | if ($processing = $this->processingInstructions($i, count($rules)+$indexStart)) { |
| 31 | 33 | $i = $processing['endPos']+1; |
| 32 | 34 | $rules = array_merge($rules, $processing['rules']); |
@@ -35,14 +37,20 @@ discard block |
||
| 35 | 37 | $tokens = array_slice($this->tss, $i); |
| 36 | 38 | $selector = $this->splitOnToken($tokens, Tokenizer::OPEN_BRACE)[0]; |
| 37 | 39 | $i += count($selector); |
| 38 | - if ($selector[count($selector)-1]['type'] === Tokenizer::WHITESPACE) array_pop($selector); |
|
| 39 | - if (!isset($this->tss[$i])) break; |
|
| 40 | + if ($selector[count($selector)-1]['type'] === Tokenizer::WHITESPACE) { |
|
| 41 | + array_pop($selector); |
|
| 42 | + } |
|
| 43 | + if (!isset($this->tss[$i])) { |
|
| 44 | + break; |
|
| 45 | + } |
|
| 40 | 46 | |
| 41 | 47 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss[$i]['value'])); |
| 42 | 48 | $rules = $this->writeRule($rules, $newRules); |
| 43 | 49 | } |
| 44 | 50 | usort($rules, [$this, 'sortRules']); |
| 45 | - if (empty($rules) && !empty($this->tss)) throw new \Exception("No TSS rules parsed"); |
|
| 51 | + if (empty($rules) && !empty($this->tss)) { |
|
| 52 | + throw new \Exception("No TSS rules parsed"); |
|
| 53 | + } |
|
| 46 | 54 | return $rules; |
| 47 | 55 | } |
| 48 | 56 | |
@@ -69,7 +77,9 @@ discard block |
||
| 69 | 77 | } |
| 70 | 78 | |
| 71 | 79 | private function processingInstructions($key, $indexStart) { |
| 72 | - if (isset($this->tss[$key]) && $this->tss[$key]['type'] !== Tokenizer::AT_SIGN) return false; |
|
| 80 | + if (isset($this->tss[$key]) && $this->tss[$key]['type'] !== Tokenizer::AT_SIGN) { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 73 | 83 | $rules = []; |
| 74 | 84 | $tokens = array_slice($this->tss, $key+1); |
| 75 | 85 | $tokens = $this->splitOnToken($tokens, Tokenizer::SEMI_COLON)[0]; |
@@ -88,7 +98,9 @@ discard block |
||
| 88 | 98 | |
| 89 | 99 | private function sortRules($a, $b) { |
| 90 | 100 | //If they have the same depth, compare on index |
| 91 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
| 101 | + if ($a->depth === $b->depth) { |
|
| 102 | + return $a->index < $b->index ? -1 : 1; |
|
| 103 | + } |
|
| 92 | 104 | |
| 93 | 105 | return ($a->depth < $b->depth) ? -1 : 1; |
| 94 | 106 | } |
@@ -97,7 +109,9 @@ discard block |
||
| 97 | 109 | $pos = 0; |
| 98 | 110 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 99 | 111 | $end = strpos($str, $close, $pos); |
| 100 | - if ($end === false) break; |
|
| 112 | + if ($end === false) { |
|
| 113 | + break; |
|
| 114 | + } |
|
| 101 | 115 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
| 102 | 116 | } |
| 103 | 117 | |
@@ -108,8 +122,11 @@ discard block |
||
| 108 | 122 | $splitTokens = []; |
| 109 | 123 | $i = 0; |
| 110 | 124 | foreach ($tokens as $token) { |
| 111 | - if ($token['type'] === $splitOn) $i++; |
|
| 112 | - else $splitTokens[$i][] = $token; |
|
| 125 | + if ($token['type'] === $splitOn) { |
|
| 126 | + $i++; |
|
| 127 | + } else { |
|
| 128 | + $splitTokens[$i][] = $token; |
|
| 129 | + } |
|
| 113 | 130 | } |
| 114 | 131 | return $splitTokens; |
| 115 | 132 | } |
@@ -117,7 +134,9 @@ discard block |
||
| 117 | 134 | private function removeWhitespace($tokens) { |
| 118 | 135 | $newTokens = []; |
| 119 | 136 | foreach ($tokens as $token) { |
| 120 | - if ($token['type'] !== Tokenizer::WHITESPACE) $newTokens[] = $token; |
|
| 137 | + if ($token['type'] !== Tokenizer::WHITESPACE) { |
|
| 138 | + $newTokens[] = $token; |
|
| 139 | + } |
|
| 121 | 140 | } |
| 122 | 141 | return $newTokens; |
| 123 | 142 | } |
@@ -127,7 +146,9 @@ discard block |
||
| 127 | 146 | $return = []; |
| 128 | 147 | foreach ($rules as $rule) { |
| 129 | 148 | $rule = $this->removeWhitespace($rule); |
| 130 | - if (isset($rule[1]) && $rule[1]['type'] === Tokenizer::COLON) $return[$rule[0]['value']] = array_slice($rule, 2); |
|
| 149 | + if (isset($rule[1]) && $rule[1]['type'] === Tokenizer::COLON) { |
|
| 150 | + $return[$rule[0]['value']] = array_slice($rule, 2); |
|
| 151 | + } |
|
| 131 | 152 | } |
| 132 | 153 | |
| 133 | 154 | return $return; |