@@ -54,7 +54,9 @@ discard block |
||
| 54 | 54 | $this->last = null; |
| 55 | 55 | $this->traversing = false; |
| 56 | 56 | |
| 57 | - if (count($tokens) <= 0) return [$data]; |
|
| 57 | + if (count($tokens) <= 0) { |
|
| 58 | + return [$data]; |
|
| 59 | + } |
|
| 58 | 60 | |
| 59 | 61 | foreach (new TokenFilterIterator($tokens, [Tokenizer::WHITESPACE, Tokenizer::NEW_LINE]) as $token) { |
| 60 | 62 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -76,16 +78,16 @@ discard block |
||
| 76 | 78 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
| 77 | 79 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
| 78 | 80 | private function processDot($token) { |
| 79 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
| 80 | - else { |
|
| 81 | + if ($this->last !== null) { |
|
| 82 | + $this->data->traverse($this->last); |
|
| 83 | + } else { |
|
| 81 | 84 | //When . is not preceeded by anything, treat it as part of the string instead of an operator |
| 82 | 85 | // foo.bar is treated as looking up `bar` in `foo` whereas .foo is treated as the string ".foo" |
| 83 | 86 | $lastResult = $this->result->pop(); |
| 84 | 87 | if ($lastResult) { |
| 85 | 88 | $this->data = new ValueData($lastResult); |
| 86 | 89 | $this->traversing = true; |
| 87 | - } |
|
| 88 | - else { |
|
| 90 | + } else { |
|
| 89 | 91 | $this->processString(['value' => '.']); |
| 90 | 92 | $this->result->setMode(Tokenizer::CONCAT); |
| 91 | 93 | } |
@@ -102,15 +104,19 @@ discard block |
||
| 102 | 104 | $parser = new Value($this->baseData, $this->autoLookup); |
| 103 | 105 | if ($this->hasFunction($this->last)) { |
| 104 | 106 | $this->callTransphpormFunctions($token); |
| 105 | - } |
|
| 106 | - else { |
|
| 107 | - if ($this->last !== null) $this->data->traverse($this->last); |
|
| 108 | - else { |
|
| 107 | + } else { |
|
| 108 | + if ($this->last !== null) { |
|
| 109 | + $this->data->traverse($this->last); |
|
| 110 | + } else { |
|
| 109 | 111 | $lastResult = $this->result->pop(); |
| 110 | - if ($lastResult) $this->data = new ValueData($lastResult); |
|
| 112 | + if ($lastResult) { |
|
| 113 | + $this->data = new ValueData($lastResult); |
|
| 114 | + } |
|
| 111 | 115 | } |
| 112 | 116 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
| 113 | - if (!is_bool($this->last)) $this->traversing = true; |
|
| 117 | + if (!is_bool($this->last)) { |
|
| 118 | + $this->traversing = true; |
|
| 119 | + } |
|
| 114 | 120 | } |
| 115 | 121 | } |
| 116 | 122 | |
@@ -130,8 +136,7 @@ discard block |
||
| 130 | 136 | if ($this->hasFunction($this->last) |
| 131 | 137 | && !$this->data->methodExists($this->last)) { |
| 132 | 138 | $this->callTransphpormFunctions($token); |
| 133 | - } |
|
| 134 | - else { |
|
| 139 | + } else { |
|
| 135 | 140 | $this->processNested($token); |
| 136 | 141 | } |
| 137 | 142 | } |
@@ -148,7 +153,9 @@ discard block |
||
| 148 | 153 | foreach ($this->result->getResult() as $i => $value) { |
| 149 | 154 | if (is_scalar($value)) { |
| 150 | 155 | $val = $this->data->read($value); |
| 151 | - if ($val) $this->result[$i] = $val; |
|
| 156 | + if ($val) { |
|
| 157 | + $this->result[$i] = $val; |
|
| 158 | + } |
|
| 152 | 159 | } |
| 153 | 160 | } |
| 154 | 161 | $this->last = null; |
@@ -160,8 +167,7 @@ discard block |
||
| 160 | 167 | try { |
| 161 | 168 | $value = $this->data->extract($this->last, $this->autoLookup, $this->traversing); |
| 162 | 169 | $this->result->processValue($value); |
| 163 | - } |
|
| 164 | - catch (\UnexpectedValueException $e) { |
|
| 170 | + } catch (\UnexpectedValueException $e) { |
|
| 165 | 171 | $this->processLastUnexpected(); |
| 166 | 172 | } |
| 167 | 173 | } |
@@ -170,8 +176,7 @@ discard block |
||
| 170 | 176 | private function processLastUnexpected() { |
| 171 | 177 | if (!($this->autoLookup || $this->traversing)) { |
| 172 | 178 | $this->result->processValue($this->last); |
| 173 | - } |
|
| 174 | - else { |
|
| 179 | + } else { |
|
| 175 | 180 | $this->result->clear(); |
| 176 | 181 | $this->result[0] = false; |
| 177 | 182 | } |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | private function getTemplateContent($newNode, $tss) { |
| 41 | 41 | $result = []; |
| 42 | 42 | foreach ($newNode->childNodes as $node) { |
| 43 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
| 43 | + if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
| 44 | 44 | else $result[] = $this->getClonedElement($node, $tss); |
| 45 | 45 | } |
| 46 | 46 | return $result; |
@@ -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->documentElement, $tss); |
| 37 | 42 | |
@@ -40,8 +45,11 @@ discard block |
||
| 40 | 45 | private function getTemplateContent($newNode, $tss) { |
| 41 | 46 | $result = []; |
| 42 | 47 | foreach ($newNode->childNodes as $node) { |
| 43 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
| 44 | - else $result[] = $this->getClonedElement($node, $tss); |
|
| 48 | + if (isset($node->tagName) && $node->tagName === 'template') { |
|
| 49 | + $result[] = $this->getTemplateContent($node, $tss); |
|
| 50 | + } else { |
|
| 51 | + $result[] = $this->getClonedElement($node, $tss); |
|
| 52 | + } |
|
| 45 | 53 | } |
| 46 | 54 | return $result; |
| 47 | 55 | } |
@@ -60,7 +68,9 @@ discard block |
||
| 60 | 68 | |
| 61 | 69 | private function getClonedElement($node, $tss) { |
| 62 | 70 | $clone = $node->cloneNode(true); |
| 63 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 71 | + if ($tss != null && $clone instanceof \DomElement) { |
|
| 72 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 73 | + } |
|
| 64 | 74 | return $clone; |
| 65 | 75 | } |
| 66 | 76 | } |