@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | $this->cache = new Cache(new \ArrayObject()); |
| 27 | 27 | |
| 28 | 28 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
| 29 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
| 29 | + foreach ($modules as $module) { |
|
| 30 | + $this->loadModule(new $module); |
|
| 31 | + } |
|
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -51,7 +53,9 @@ discard block |
||
| 51 | 53 | $valueParser = new Parser\Value($data); |
| 52 | 54 | $config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($data, $template->getPrefix()), $headers, $this->baseDir); |
| 53 | 55 | |
| 54 | - foreach ($this->modules as $module) $module->load($config); |
|
| 56 | + foreach ($this->modules as $module) { |
|
| 57 | + $module->load($config); |
|
| 58 | + } |
|
| 55 | 59 | |
| 56 | 60 | $this->processRules($template, $config); |
| 57 | 61 | |
@@ -66,7 +70,9 @@ discard block |
||
| 66 | 70 | $rules = $this->getRules($template, $config); |
| 67 | 71 | |
| 68 | 72 | foreach ($rules as $rule) { |
| 69 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
| 73 | + if ($rule->shouldRun($this->time)) { |
|
| 74 | + $this->executeTssRule($rule, $template, $config); |
|
| 75 | + } |
|
| 70 | 76 | } |
| 71 | 77 | } |
| 72 | 78 | |
@@ -91,8 +97,9 @@ discard block |
||
| 91 | 97 | if (trim($this->template)[0] !== '<') { |
| 92 | 98 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 93 | 99 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 100 | + } else { |
|
| 101 | + return ['body' => $this->template, 'headers' => []]; |
|
| 94 | 102 | } |
| 95 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 96 | 103 | } |
| 97 | 104 | |
| 98 | 105 | //Load the TSS rules either from a file or as a string |
@@ -23,8 +23,11 @@ discard block |
||
| 23 | 23 | $this->file = $tss; |
| 24 | 24 | $this->rules = $this->getRulesFromCache($tss, $templatePrefix); |
| 25 | 25 | $baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR; |
| 26 | - if (empty($this->rules)) $tss = file_get_contents($tss); |
|
| 27 | - else return; |
|
| 26 | + if (empty($this->rules)) { |
|
| 27 | + $tss = file_get_contents($tss); |
|
| 28 | + } else { |
|
| 29 | + return; |
|
| 30 | + } |
|
| 28 | 31 | } |
| 29 | 32 | $this->tss = $this->stripComments($tss, '//', "\n"); |
| 30 | 33 | $this->tss = $this->stripComments($this->tss, '/*', '*/'); |
@@ -49,7 +52,9 @@ discard block |
||
| 49 | 52 | } |
| 50 | 53 | |
| 51 | 54 | public function parse($indexStart = 0) { |
| 52 | - if (!empty($this->rules)) return $this->rules; |
|
| 55 | + if (!empty($this->rules)) { |
|
| 56 | + return $this->rules; |
|
| 57 | + } |
|
| 53 | 58 | $rules = []; |
| 54 | 59 | $line = 1; |
| 55 | 60 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
@@ -57,26 +62,31 @@ discard block |
||
| 57 | 62 | $this->tss->skip($processing['skip']+1); |
| 58 | 63 | $rules = array_merge($rules, $processing['rules']); |
| 59 | 64 | continue; |
| 60 | - } |
|
| 61 | - else if ($token['type'] === Tokenizer::NEW_LINE) { |
|
| 65 | + } else if ($token['type'] === Tokenizer::NEW_LINE) { |
|
| 62 | 66 | $line++; |
| 63 | 67 | continue; |
| 64 | 68 | } |
| 65 | 69 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
| 66 | 70 | $this->tss->skip(count($selector)); |
| 67 | - if (count($selector) === 0) break; |
|
| 71 | + if (count($selector) === 0) { |
|
| 72 | + break; |
|
| 73 | + } |
|
| 68 | 74 | |
| 69 | 75 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $line); |
| 70 | 76 | $rules = $this->writeRule($rules, $newRules); |
| 71 | 77 | } |
| 72 | 78 | usort($rules, [$this, 'sortRules']); |
| 73 | 79 | $this->checkError($rules); |
| 74 | - if (!empty($this->file)) $this->cache->write($this->getCacheKey(), $rules); |
|
| 80 | + if (!empty($this->file)) { |
|
| 81 | + $this->cache->write($this->getCacheKey(), $rules); |
|
| 82 | + } |
|
| 75 | 83 | return $rules; |
| 76 | 84 | } |
| 77 | 85 | |
| 78 | 86 | private function checkError($rules) { |
| 79 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
| 87 | + if (empty($rules) && count($this->tss) > 0) { |
|
| 88 | + throw new \Exception('No TSS rules parsed'); |
|
| 89 | + } |
|
| 80 | 90 | } |
| 81 | 91 | |
| 82 | 92 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -103,7 +113,9 @@ discard block |
||
| 103 | 113 | } |
| 104 | 114 | |
| 105 | 115 | private function processingInstructions($token, $indexStart) { |
| 106 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
| 116 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 107 | 119 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
| 108 | 120 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
| 109 | 121 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -113,15 +125,20 @@ discard block |
||
| 113 | 125 | } |
| 114 | 126 | |
| 115 | 127 | private function import($args, $indexStart) { |
| 116 | - if ($this->file !== null) $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0]; |
|
| 117 | - else $fileName = $args[0]; |
|
| 128 | + if ($this->file !== null) { |
|
| 129 | + $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0]; |
|
| 130 | + } else { |
|
| 131 | + $fileName = $args[0]; |
|
| 132 | + } |
|
| 118 | 133 | $sheet = new Sheet($fileName, $this->prefix, $this->baseDir, $this->xPath, $this->valueParser, $this->cache); |
| 119 | 134 | return $sheet->parse($indexStart); |
| 120 | 135 | } |
| 121 | 136 | |
| 122 | 137 | private function sortRules($a, $b) { |
| 123 | 138 | //If they have the same depth, compare on index |
| 124 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
| 139 | + if ($a->depth === $b->depth) { |
|
| 140 | + return $a->index < $b->index ? -1 : 1; |
|
| 141 | + } |
|
| 125 | 142 | |
| 126 | 143 | return ($a->depth < $b->depth) ? -1 : 1; |
| 127 | 144 | } |
@@ -130,7 +147,9 @@ discard block |
||
| 130 | 147 | $pos = 0; |
| 131 | 148 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 132 | 149 | $end = strpos($str, $close, $pos); |
| 133 | - if ($end === false) break; |
|
| 150 | + if ($end === false) { |
|
| 151 | + break; |
|
| 152 | + } |
|
| 134 | 153 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
| 135 | 154 | } |
| 136 | 155 | |