@@ -81,10 +81,15 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | private function processLiterals(&$tokens, $name) { |
| 84 | - if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
| 85 | - else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
| 86 | - else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
| 87 | - else $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
| 84 | + if (is_numeric($name)) { |
|
| 85 | + $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
| 86 | + } else if ($name == 'true') { |
|
| 87 | + $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
| 88 | + } else if ($name == 'false') { |
|
| 89 | + $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
| 90 | + } else { |
|
| 91 | + $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
| 92 | + } |
|
| 88 | 93 | } |
| 89 | 94 | |
| 90 | 95 | private function doBrackets(&$tokens, $char, $i) { |
@@ -118,7 +123,9 @@ discard block |
||
| 118 | 123 | private function extractString($pos) { |
| 119 | 124 | $char = $this->str[$pos]; |
| 120 | 125 | $end = strpos($this->str, $char, $pos+1); |
| 121 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
| 126 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
| 127 | + $end = strpos($this->str, $char, $end+1); |
|
| 128 | + } |
|
| 122 | 129 | |
| 123 | 130 | return substr($this->str, $pos+1, $end-$pos-1); |
| 124 | 131 | } |
@@ -127,18 +134,26 @@ discard block |
||
| 127 | 134 | $close = strpos($this->str, $closeBracket, $open); |
| 128 | 135 | |
| 129 | 136 | $cPos = $open+1; |
| 130 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
| 137 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
| 138 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
| 139 | + } |
|
| 131 | 140 | return substr($this->str, $open+1, $close-$open-1); |
| 132 | 141 | } |
| 133 | 142 | |
| 134 | 143 | private function identifyChar($chr) { |
| 135 | - if (isset($this->chars[$chr])) return $this->chars[$chr]; |
|
| 136 | - else return self::NAME; |
|
| 144 | + if (isset($this->chars[$chr])) { |
|
| 145 | + return $this->chars[$chr]; |
|
| 146 | + } else { |
|
| 147 | + return self::NAME; |
|
| 148 | + } |
|
| 137 | 149 | } |
| 138 | 150 | |
| 139 | 151 | private function getChar($num) { |
| 140 | 152 | $chars = array_reverse($this->chars); |
| 141 | - if (isset($chars[$num])) return $chars[$num]; |
|
| 142 | - else return false; |
|
| 153 | + if (isset($chars[$num])) { |
|
| 154 | + return $chars[$num]; |
|
| 155 | + } else { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 143 | 158 | } |
| 144 | 159 | } |
@@ -18,15 +18,20 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 21 | - if (!$this->shouldRun($element)) return false; |
|
| 21 | + if (!$this->shouldRun($element)) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 22 | 24 | $values = $this->fixValues($this->formatter->format($values, $rules)); |
| 23 | 25 | |
| 24 | 26 | if (!$this->processPseudo($values, $element, $pseudoMatcher)) { |
| 25 | 27 | //Remove the current contents |
| 26 | 28 | $this->removeAllChildren($element); |
| 27 | 29 | //Now make a text node |
| 28 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
| 29 | - else $this->appendContent($element, $values); |
|
| 30 | + if ($this->getContentMode($rules) === 'replace') { |
|
| 31 | + $this->replaceContent($element, $values); |
|
| 32 | + } else { |
|
| 33 | + $this->appendContent($element, $values); |
|
| 34 | + } |
|
| 30 | 35 | } |
| 31 | 36 | } |
| 32 | 37 | |
@@ -38,7 +43,9 @@ discard block |
||
| 38 | 43 | |
| 39 | 44 | private function shouldRun($element) { |
| 40 | 45 | do { |
| 41 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
| 46 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
| 47 | + return false; |
|
| 48 | + } |
|
| 42 | 49 | } |
| 43 | 50 | while (($element = $element->parentNode) instanceof \DomElement); |
| 44 | 51 | return true; |
@@ -65,9 +72,10 @@ discard block |
||
| 65 | 72 | $new = $document->importNode($n, true); |
| 66 | 73 | //Removing this might cause problems with caching... |
| 67 | 74 | //$new->setAttribute('transphporm', 'added'); |
| 68 | - } |
|
| 69 | - else { |
|
| 70 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
| 75 | + } else { |
|
| 76 | + if ($n instanceof \DomText) { |
|
| 77 | + $n = $n->nodeValue; |
|
| 78 | + } |
|
| 71 | 79 | $new = $document->createElement('text'); |
| 72 | 80 | |
| 73 | 81 | $new->appendChild($document->createTextNode($n)); |
@@ -114,6 +122,8 @@ discard block |
||
| 114 | 122 | } |
| 115 | 123 | |
| 116 | 124 | private function removeAllChildren($element) { |
| 117 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
| 125 | + while ($element->hasChildNodes()) { |
|
| 126 | + $element->removeChild($element->firstChild); |
|
| 127 | + } |
|
| 118 | 128 | } |
| 119 | 129 | } |
| 120 | 130 | \ No newline at end of file |