@@ -79,6 +79,10 @@ discard block |
||
79 | 79 | if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
80 | 80 | } |
81 | 81 | |
82 | + /** |
|
83 | + * @param integer $index |
|
84 | + * @param integer $line |
|
85 | + */ |
|
82 | 86 | private function CssToRules($selector, $index, $properties, $line) { |
83 | 87 | $parts = $selector->trim()->splitOnToken(Tokenizer::ARG); |
84 | 88 | $rules = []; |
@@ -102,6 +106,9 @@ discard block |
||
102 | 106 | return $rules; |
103 | 107 | } |
104 | 108 | |
109 | + /** |
|
110 | + * @param integer $indexStart |
|
111 | + */ |
|
105 | 112 | private function processingInstructions($token, $indexStart) { |
106 | 113 | if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
107 | 114 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
@@ -126,6 +133,10 @@ discard block |
||
126 | 133 | return ($a->depth < $b->depth) ? -1 : 1; |
127 | 134 | } |
128 | 135 | |
136 | + /** |
|
137 | + * @param string $open |
|
138 | + * @param string $close |
|
139 | + */ |
|
129 | 140 | private function stripComments($str, $open, $close) { |
130 | 141 | $pos = 0; |
131 | 142 | while (($pos = strpos($str, $open, $pos)) !== false) { |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | if (is_file($tss)) { |
23 | 23 | $this->file = $tss; |
24 | 24 | $this->rules = $this->getRulesFromCache($tss, $templatePrefix); |
25 | - $baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR; |
|
25 | + $baseDir = dirname(realpath($tss)).DIRECTORY_SEPARATOR; |
|
26 | 26 | if (empty($this->rules)) $tss = file_get_contents($tss); |
27 | 27 | else return; |
28 | 28 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | private function getCacheKey() { |
48 | - return $this->file . $this->prefix . dirname(realpath($this->file)) . DIRECTORY_SEPARATOR; |
|
48 | + return $this->file.$this->prefix.dirname(realpath($this->file)).DIRECTORY_SEPARATOR; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function parse($indexStart = 0) { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | private function import($args, $indexStart) { |
116 | - if ($this->file !== null) $fileName = dirname(realpath($this->file)) . DIRECTORY_SEPARATOR . $args[0]; |
|
116 | + if ($this->file !== null) $fileName = dirname(realpath($this->file)).DIRECTORY_SEPARATOR.$args[0]; |
|
117 | 117 | else $fileName = $args[0]; |
118 | 118 | $sheet = new Sheet($fileName, $this->prefix, $this->baseDir, $this->xPath, $this->valueParser, $this->cache); |
119 | 119 | return $sheet->parse($indexStart); |
@@ -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 |
@@ -47,7 +47,7 @@ |
||
47 | 47 | |
48 | 48 | $cachedOutput = $this->loadTemplate(); |
49 | 49 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
50 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
50 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
51 | 51 | $valueParser = new Parser\Value($data); |
52 | 52 | $config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($data, $template->getPrefix()), $headers, $this->baseDir); |
53 | 53 |
@@ -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 |