@@ -37,9 +37,13 @@ |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | private function processLiterals($tokens, $name, $str) { |
| 40 | - if (is_numeric($name)) $tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]); |
|
| 41 | - else if (method_exists($this, $name)) $this->$name($tokens); |
|
| 42 | - else $tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]); |
|
| 40 | + if (is_numeric($name)) { |
|
| 41 | + $tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]); |
|
| 42 | + } else if (method_exists($this, $name)) { |
|
| 43 | + $this->$name($tokens); |
|
| 44 | + } else { |
|
| 45 | + $tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]); |
|
| 46 | + } |
|
| 43 | 47 | } |
| 44 | 48 | |
| 45 | 49 | private function true($tokens) { |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | |
| 109 | 109 | //Postprocessing - replace values with null where allowed, or override a value at position |
| 110 | 110 | public function postProcess(ValueData $data, $val, $overrideVal, $allowNull) { |
| 111 | - if ($this->getMode() !== Tokenizer::ARG) return; |
|
| 111 | + if ($this->getMode() !== Tokenizer::ARG) return; |
|
| 112 | 112 | foreach ($this->getResult() as $i => $value) { |
| 113 | 113 | if (is_scalar($value)) { |
| 114 | 114 | $val = ($overrideVal == $val) ? $data->read($value) : $overrideVal; |
@@ -33,14 +33,17 @@ discard block |
||
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | if ($funcs[$this->mode] === 'concat' && is_numeric($newValue) |
| 36 | - && is_numeric($this->result[count($this->result)-1])) |
|
| 37 | - $this->add($newValue); |
|
| 38 | - else |
|
| 39 | - $this->{$funcs[$this->mode]}($newValue); |
|
| 36 | + && is_numeric($this->result[count($this->result)-1])) { |
|
| 37 | + $this->add($newValue); |
|
| 38 | + } else { |
|
| 39 | + $this->{$funcs[$this->mode]}($newValue); |
|
| 40 | + } |
|
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | public function in($value) { |
| 43 | - if (!is_array($value)) throw new \Exception(' `in` can only be used with arrays'); |
|
| 44 | + if (!is_array($value)) { |
|
| 45 | + throw new \Exception(' `in` can only be used with arrays'); |
|
| 46 | + } |
|
| 44 | 47 | $this->result[count($this->result)-1] = in_array($this->result[count($this->result)-1], $value); |
| 45 | 48 | } |
| 46 | 49 | |
@@ -108,7 +111,9 @@ discard block |
||
| 108 | 111 | |
| 109 | 112 | //Postprocessing - replace values with null where allowed, or override a value at position |
| 110 | 113 | public function postProcess(ValueData $data, $val, $overrideVal, $allowNull) { |
| 111 | - if ($this->getMode() !== Tokenizer::ARG) return; |
|
| 114 | + if ($this->getMode() !== Tokenizer::ARG) { |
|
| 115 | + return; |
|
| 116 | + } |
|
| 112 | 117 | foreach ($this->getResult() as $i => $value) { |
| 113 | 118 | if (is_scalar($value)) { |
| 114 | 119 | $val = ($overrideVal == $val) ? $data->read($value) : $overrideVal; |
@@ -26,11 +26,12 @@ |
||
| 26 | 26 | private function getArgs0($name, $args) { |
| 27 | 27 | if (isset($this->functions[$name]) && !($this->functions[$name] instanceof TSSFunction\Data)) { |
| 28 | 28 | $tokens = $args[0]; |
| 29 | - if ($tokens->count() == 0) return []; |
|
| 29 | + if ($tokens->count() == 0) { |
|
| 30 | + return []; |
|
| 31 | + } |
|
| 30 | 32 | $parser = new \Transphporm\Parser\Value($this); |
| 31 | 33 | return $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
| 32 | - } |
|
| 33 | - else { |
|
| 34 | + } else { |
|
| 34 | 35 | return iterator_to_array($args[0]); |
| 35 | 36 | } |
| 36 | 37 | |
@@ -14,7 +14,9 @@ discard block |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 17 | - if (!$this->shouldRun($element)) return false; |
|
| 17 | + if (!$this->shouldRun($element)) { |
|
| 18 | + return false; |
|
| 19 | + } |
|
| 18 | 20 | |
| 19 | 21 | $values = $this->formatter->format($values, $rules); |
| 20 | 22 | |
@@ -22,14 +24,19 @@ discard block |
||
| 22 | 24 | //Remove the current contents |
| 23 | 25 | $this->removeAllChildren($element); |
| 24 | 26 | //Now make a text node |
| 25 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
| 26 | - else $this->appendContent($element, $values); |
|
| 27 | + if ($this->getContentMode($rules) === 'replace') { |
|
| 28 | + $this->replaceContent($element, $values); |
|
| 29 | + } else { |
|
| 30 | + $this->appendContent($element, $values); |
|
| 31 | + } |
|
| 27 | 32 | } |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | 35 | private function shouldRun($element) { |
| 31 | 36 | do { |
| 32 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
| 37 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 33 | 40 | } |
| 34 | 41 | while (($element = $element->parentNode) instanceof \DomElement); |
| 35 | 42 | return true; |
@@ -56,9 +63,10 @@ discard block |
||
| 56 | 63 | public function getNode($node, $document) { |
| 57 | 64 | foreach ($node as $n) { |
| 58 | 65 | if (is_array($n)) { |
| 59 | - foreach ($this->getNode($n, $document) as $new) yield $new; |
|
| 60 | - } |
|
| 61 | - else { |
|
| 66 | + foreach ($this->getNode($n, $document) as $new) { |
|
| 67 | + yield $new; |
|
| 68 | + } |
|
| 69 | + } else { |
|
| 62 | 70 | yield $this->convertNode($n, $document); |
| 63 | 71 | } |
| 64 | 72 | } |
@@ -69,9 +77,10 @@ discard block |
||
| 69 | 77 | $new = $document->importNode($node, true); |
| 70 | 78 | //Removing this might cause problems with caching... |
| 71 | 79 | //$new->setAttribute('transphporm', 'added'); |
| 72 | - } |
|
| 73 | - else { |
|
| 74 | - if ($node instanceof \DomText) $node = $node->nodeValue; |
|
| 80 | + } else { |
|
| 81 | + if ($node instanceof \DomText) { |
|
| 82 | + $node = $node->nodeValue; |
|
| 83 | + } |
|
| 75 | 84 | $new = $document->createElement('text'); |
| 76 | 85 | |
| 77 | 86 | $new->appendChild($document->createTextNode($node)); |
@@ -88,7 +97,9 @@ discard block |
||
| 88 | 97 | } |
| 89 | 98 | |
| 90 | 99 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
| 91 | - if (!$node->getAttribute('transphporm')) $node->setAttribute('transphporm', 'added'); |
|
| 100 | + if (!$node->getAttribute('transphporm')) { |
|
| 101 | + $node->setAttribute('transphporm', 'added'); |
|
| 102 | + } |
|
| 92 | 103 | $element->parentNode->insertBefore($node, $element); |
| 93 | 104 | } |
| 94 | 105 | |
@@ -122,6 +133,8 @@ discard block |
||
| 122 | 133 | } |
| 123 | 134 | |
| 124 | 135 | private function removeAllChildren($element) { |
| 125 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
| 136 | + while ($element->hasChildNodes()) { |
|
| 137 | + $element->removeChild($element->firstChild); |
|
| 138 | + } |
|
| 126 | 139 | } |
| 127 | 140 | } |