@@ -25,13 +25,18 @@ discard block |
||
| 25 | 25 | $selector = $this->readArray($args, 1); |
| 26 | 26 | $tss = $this->readArray($args, 2); |
| 27 | 27 | |
| 28 | - if (trim($args[0])[0] === '<') $xml = $args[0]; |
|
| 29 | - else $xml = $this->filePath->getFilePath($args[0]); |
|
| 28 | + if (trim($args[0])[0] === '<') { |
|
| 29 | + $xml = $args[0]; |
|
| 30 | + } else { |
|
| 31 | + $xml = $this->filePath->getFilePath($args[0]); |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->filePath->getFilePath($tss) : null); |
| 32 | 35 | |
| 33 | 36 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
| 34 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
| 37 | + if ($selector != '') { |
|
| 38 | + return $this->templateSubsection($doc, $selector); |
|
| 39 | + } |
|
| 35 | 40 | |
| 36 | 41 | return $this->getTemplateContent($doc, $tss); |
| 37 | 42 | |
@@ -62,7 +67,9 @@ discard block |
||
| 62 | 67 | |
| 63 | 68 | private function getClonedElement($node, $tss) { |
| 64 | 69 | $clone = $node->cloneNode(true); |
| 65 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 70 | + if ($tss != null && $clone instanceof \DomElement) { |
|
| 71 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 72 | + } |
|
| 66 | 73 | return $clone; |
| 67 | 74 | } |
| 68 | 75 | } |
@@ -25,8 +25,11 @@ discard block |
||
| 25 | 25 | $this->file = $tss; |
| 26 | 26 | $this->rules = $this->cache->load($tss); |
| 27 | 27 | $baseDir = dirname(realpath($tss)) . DIRECTORY_SEPARATOR; |
| 28 | - if (empty($this->rules)) $tss = file_get_contents($tss); |
|
| 29 | - else return; |
|
| 28 | + if (empty($this->rules)) { |
|
| 29 | + $tss = file_get_contents($tss); |
|
| 30 | + } else { |
|
| 31 | + return; |
|
| 32 | + } |
|
| 30 | 33 | } |
| 31 | 34 | $this->tss = $this->stripComments($tss, '//', "\n"); |
| 32 | 35 | $this->tss = $this->stripComments($this->tss, '/*', '*/'); |
@@ -38,7 +41,9 @@ discard block |
||
| 38 | 41 | } |
| 39 | 42 | |
| 40 | 43 | public function parse($indexStart = 0) { |
| 41 | - if (!empty($this->rules)) return $this->rules['rules']; |
|
| 44 | + if (!empty($this->rules)) { |
|
| 45 | + return $this->rules['rules']; |
|
| 46 | + } |
|
| 42 | 47 | $rules = $this->parseTokens($indexStart); |
| 43 | 48 | usort($rules, [$this, 'sortRules']); |
| 44 | 49 | $this->checkError($rules); |
@@ -52,12 +57,12 @@ discard block |
||
| 52 | 57 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
| 53 | 58 | $this->rules = array_merge($this->rules, $processing); |
| 54 | 59 | continue; |
| 55 | - } |
|
| 56 | - else if ($token['type'] === Tokenizer::NEW_LINE) { |
|
| 60 | + } else if ($token['type'] === Tokenizer::NEW_LINE) { |
|
| 57 | 61 | $line++; |
| 58 | 62 | continue; |
| 63 | + } else { |
|
| 64 | + $this->addRules($token, $indexStart, $line); |
|
| 59 | 65 | } |
| 60 | - else $this->addRules($token, $indexStart, $line); |
|
| 61 | 66 | } |
| 62 | 67 | return $this->rules; |
| 63 | 68 | } |
@@ -65,14 +70,18 @@ discard block |
||
| 65 | 70 | private function addRules($token, $indexStart, $line) { |
| 66 | 71 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
| 67 | 72 | $this->tss->skip(count($selector)); |
| 68 | - if (count($selector) === 0) return; |
|
| 73 | + if (count($selector) === 0) { |
|
| 74 | + return; |
|
| 75 | + } |
|
| 69 | 76 | |
| 70 | 77 | $newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $line); |
| 71 | 78 | $this->rules = $this->writeRule($this->rules, $newRules); |
| 72 | 79 | } |
| 73 | 80 | |
| 74 | 81 | private function checkError($rules) { |
| 75 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
| 82 | + if (empty($rules) && count($this->tss) > 0) { |
|
| 83 | + throw new \Exception('No TSS rules parsed'); |
|
| 84 | + } |
|
| 76 | 85 | } |
| 77 | 86 | |
| 78 | 87 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -99,7 +108,9 @@ discard block |
||
| 99 | 108 | } |
| 100 | 109 | |
| 101 | 110 | private function processingInstructions($token, $indexStart) { |
| 102 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
| 111 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 103 | 114 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
| 104 | 115 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
| 105 | 116 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -111,8 +122,11 @@ discard block |
||
| 111 | 122 | } |
| 112 | 123 | |
| 113 | 124 | private function import($args, $indexStart) { |
| 114 | - if ($this->file !== null) $fileName = $fileName = $this->filePath->getFilePath($args[0]); |
|
| 115 | - else $fileName = $args[0]; |
|
| 125 | + if ($this->file !== null) { |
|
| 126 | + $fileName = $fileName = $this->filePath->getFilePath($args[0]); |
|
| 127 | + } else { |
|
| 128 | + $fileName = $args[0]; |
|
| 129 | + } |
|
| 116 | 130 | $this->import[] = $fileName; |
| 117 | 131 | $sheet = new Sheet($fileName, $this->baseDir, $this->xPath, $this->valueParser, $this->cache, $this->filePath); |
| 118 | 132 | return $sheet->parse($indexStart); |
@@ -120,7 +134,9 @@ discard block |
||
| 120 | 134 | |
| 121 | 135 | private function sortRules($a, $b) { |
| 122 | 136 | //If they have the same depth, compare on index |
| 123 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
| 137 | + if ($a->depth === $b->depth) { |
|
| 138 | + return $a->index < $b->index ? -1 : 1; |
|
| 139 | + } |
|
| 124 | 140 | |
| 125 | 141 | return ($a->depth < $b->depth) ? -1 : 1; |
| 126 | 142 | } |
@@ -129,7 +145,9 @@ discard block |
||
| 129 | 145 | $pos = 0; |
| 130 | 146 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 131 | 147 | $end = strpos($str, $close, $pos); |
| 132 | - if ($end === false) break; |
|
| 148 | + if ($end === false) { |
|
| 149 | + break; |
|
| 150 | + } |
|
| 133 | 151 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
| 134 | 152 | } |
| 135 | 153 | |
@@ -7,12 +7,18 @@ |
||
| 7 | 7 | |
| 8 | 8 | public function __construct(&$baseDir, $customBase = null) { |
| 9 | 9 | $this->baseDir = &$baseDir; |
| 10 | - if ($customBase === null) $this->customBase = getcwd(); |
|
| 11 | - else $this->customBase = rtrim($customBase, '/'); |
|
| 10 | + if ($customBase === null) { |
|
| 11 | + $this->customBase = getcwd(); |
|
| 12 | + } else { |
|
| 13 | + $this->customBase = rtrim($customBase, '/'); |
|
| 14 | + } |
|
| 12 | 15 | } |
| 13 | 16 | |
| 14 | 17 | public function getFilePath($filePath = "") { |
| 15 | - if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath; |
|
| 16 | - else return $this->baseDir . $filePath; |
|
| 18 | + if (isset($filePath[0]) && $filePath[0] == "/") { |
|
| 19 | + return $this->customBase . $filePath; |
|
| 20 | + } else { |
|
| 21 | + return $this->baseDir . $filePath; |
|
| 22 | + } |
|
| 17 | 23 | } |
| 18 | 24 | } |