@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function enterNode($node, VisitorContext $ctx): void |
| 34 | 34 | { |
| 35 | - if (!$node instanceof Tag) { |
|
| 35 | + if (!$node instanceof Tag){ |
|
| 36 | 36 | return; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $flatten = []; |
| 40 | - foreach ($node->nodes as $child) { |
|
| 41 | - if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) { |
|
| 42 | - foreach ($child->nodes as $childNode) { |
|
| 40 | + foreach ($node->nodes as $child){ |
|
| 41 | + if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate){ |
|
| 42 | + foreach ($child->nodes as $childNode){ |
|
| 43 | 43 | $flatten[] = $childNode; |
| 44 | 44 | } |
| 45 | 45 | continue; |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | private function mergeRaw(array $nodes): array |
| 66 | 66 | { |
| 67 | 67 | $result = []; |
| 68 | - foreach ($nodes as $node) { |
|
| 68 | + foreach ($nodes as $node){ |
|
| 69 | 69 | if ( |
| 70 | 70 | $node instanceof Raw |
| 71 | 71 | && isset($result[count($result) - 1]) |
| 72 | 72 | && $result[count($result) - 1] instanceof Raw |
| 73 | - ) { |
|
| 73 | + ){ |
|
| 74 | 74 | $result[count($result) - 1]->content .= $node->content; |
| 75 | 75 | continue; |
| 76 | 76 | } |
@@ -32,14 +32,18 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function enterNode($node, VisitorContext $ctx): void |
| 34 | 34 | { |
| 35 | - if (!$node instanceof Tag) { |
|
| 35 | + if (!$node instanceof Tag) |
|
| 36 | + { |
|
| 36 | 37 | return; |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | $flatten = []; |
| 40 | - foreach ($node->nodes as $child) { |
|
| 41 | - if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) { |
|
| 42 | - foreach ($child->nodes as $childNode) { |
|
| 41 | + foreach ($node->nodes as $child) |
|
| 42 | + { |
|
| 43 | + if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) |
|
| 44 | + { |
|
| 45 | + foreach ($child->nodes as $childNode) |
|
| 46 | + { |
|
| 43 | 47 | $flatten[] = $childNode; |
| 44 | 48 | } |
| 45 | 49 | continue; |
@@ -65,7 +69,8 @@ discard block |
||
| 65 | 69 | private function mergeRaw(array $nodes): array |
| 66 | 70 | { |
| 67 | 71 | $result = []; |
| 68 | - foreach ($nodes as $node) { |
|
| 72 | + foreach ($nodes as $node) |
|
| 73 | + { |
|
| 69 | 74 | if ( |
| 70 | 75 | $node instanceof Raw |
| 71 | 76 | && isset($result[count($result) - 1]) |
@@ -40,30 +40,30 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function enterNode($node, VisitorContext $ctx) |
| 42 | 42 | { |
| 43 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
| 43 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag){ |
|
| 44 | 44 | return null; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) { |
|
| 47 | + if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)){ |
|
| 48 | 48 | // raw nodes |
| 49 | 49 | return null; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $level = $this->getLevel($ctx); |
| 53 | - if ($level === null) { |
|
| 53 | + if ($level === null){ |
|
| 54 | 54 | // not available in some contexts |
| 55 | 55 | return null; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - foreach ($node->nodes as $i => $child) { |
|
| 59 | - if (!$child instanceof Raw) { |
|
| 58 | + foreach ($node->nodes as $i => $child){ |
|
| 59 | + if (!$child instanceof Raw){ |
|
| 60 | 60 | continue; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $position = self::BETWEEN_TAGS; |
| 64 | - if (!isset($node->nodes[$i + 1])) { |
|
| 64 | + if (!isset($node->nodes[$i + 1])){ |
|
| 65 | 65 | $position = self::BEFORE_CLOSE; |
| 66 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
| 66 | + } elseif ($node->nodes[$i + 1] instanceof PHP){ |
|
| 67 | 67 | $position = self::BEFORE_PHP; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS) |
| 92 | 92 | { |
| 93 | - if (strpos($content, "\n") === false) { |
|
| 93 | + if (strpos($content, "\n") === false){ |
|
| 94 | 94 | // no need to do anything |
| 95 | 95 | return $content; |
| 96 | 96 | } |
@@ -98,44 +98,44 @@ discard block |
||
| 98 | 98 | // we have to apply special rules to the first and the last lines |
| 99 | 99 | $lines = explode("\n", $content); |
| 100 | 100 | |
| 101 | - foreach ($lines as $i => $line) { |
|
| 102 | - if (trim($line) === '' && $i !== 0) { |
|
| 101 | + foreach ($lines as $i => $line){ |
|
| 102 | + if (trim($line) === '' && $i !== 0){ |
|
| 103 | 103 | unset($lines[$i]); |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $lines = array_values($lines); |
| 108 | - if (count($lines) === 0) { |
|
| 108 | + if (count($lines) === 0){ |
|
| 109 | 109 | $lines[] = ''; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $result = ''; |
| 113 | - foreach ($lines as $i => $line) { |
|
| 114 | - if (trim($line) !== '') { |
|
| 115 | - if ($i === 0) { |
|
| 113 | + foreach ($lines as $i => $line){ |
|
| 114 | + if (trim($line) !== ''){ |
|
| 115 | + if ($i === 0){ |
|
| 116 | 116 | $line = rtrim($line); |
| 117 | - } else { |
|
| 117 | + }else{ |
|
| 118 | 118 | $line = trim($line); |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if ($i !== (count($lines) - 1)) { |
|
| 123 | - $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
|
| 122 | + if ($i !== (count($lines) - 1)){ |
|
| 123 | + $result .= $line."\n".str_repeat(self::INDENT, $level); |
|
| 124 | 124 | continue; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // working with last line |
| 128 | - if ($position === self::BEFORE_PHP) { |
|
| 129 | - $result .= $line . "\n"; |
|
| 128 | + if ($position === self::BEFORE_PHP){ |
|
| 129 | + $result .= $line."\n"; |
|
| 130 | 130 | break; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if ($position === self::BEFORE_CLOSE) { |
|
| 134 | - $result .= $line . "\n" . str_repeat(self::INDENT, max($level - 1, 0)); |
|
| 133 | + if ($position === self::BEFORE_CLOSE){ |
|
| 134 | + $result .= $line."\n".str_repeat(self::INDENT, max($level - 1, 0)); |
|
| 135 | 135 | break; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
|
| 138 | + $result .= $line."\n".str_repeat(self::INDENT, $level); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | return $result; |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | private function getLevel(VisitorContext $ctx): ?int |
| 149 | 149 | { |
| 150 | 150 | $level = 0; |
| 151 | - foreach ($ctx->getScope() as $node) { |
|
| 152 | - if ($node instanceof Attr) { |
|
| 151 | + foreach ($ctx->getScope() as $node){ |
|
| 152 | + if ($node instanceof Attr){ |
|
| 153 | 153 | return null; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ($node instanceof Block || $node instanceof Template) { |
|
| 156 | + if ($node instanceof Block || $node instanceof Template){ |
|
| 157 | 157 | continue; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
| 175 | 175 | { |
| 176 | - if (!$joinMultiple) { |
|
| 176 | + if (!$joinMultiple){ |
|
| 177 | 177 | return str_replace("\r\n", "\n", $string); |
| 178 | 178 | } |
| 179 | 179 | |
@@ -40,30 +40,38 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function enterNode($node, VisitorContext $ctx) |
| 42 | 42 | { |
| 43 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
| 43 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) |
|
| 44 | + { |
|
| 44 | 45 | return null; |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | - if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) { |
|
| 48 | + if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) |
|
| 49 | + { |
|
| 48 | 50 | // raw nodes |
| 49 | 51 | return null; |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | $level = $this->getLevel($ctx); |
| 53 | - if ($level === null) { |
|
| 55 | + if ($level === null) |
|
| 56 | + { |
|
| 54 | 57 | // not available in some contexts |
| 55 | 58 | return null; |
| 56 | 59 | } |
| 57 | 60 | |
| 58 | - foreach ($node->nodes as $i => $child) { |
|
| 59 | - if (!$child instanceof Raw) { |
|
| 61 | + foreach ($node->nodes as $i => $child) |
|
| 62 | + { |
|
| 63 | + if (!$child instanceof Raw) |
|
| 64 | + { |
|
| 60 | 65 | continue; |
| 61 | 66 | } |
| 62 | 67 | |
| 63 | 68 | $position = self::BETWEEN_TAGS; |
| 64 | - if (!isset($node->nodes[$i + 1])) { |
|
| 69 | + if (!isset($node->nodes[$i + 1])) |
|
| 70 | + { |
|
| 65 | 71 | $position = self::BEFORE_CLOSE; |
| 66 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
| 72 | + } |
|
| 73 | + elseif ($node->nodes[$i + 1] instanceof PHP) |
|
| 74 | + { |
|
| 67 | 75 | $position = self::BEFORE_PHP; |
| 68 | 76 | } |
| 69 | 77 | |
@@ -90,7 +98,8 @@ discard block |
||
| 90 | 98 | */ |
| 91 | 99 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS) |
| 92 | 100 | { |
| 93 | - if (strpos($content, "\n") === false) { |
|
| 101 | + if (strpos($content, "\n") === false) |
|
| 102 | + { |
|
| 94 | 103 | // no need to do anything |
| 95 | 104 | return $content; |
| 96 | 105 | } |
@@ -98,39 +107,50 @@ discard block |
||
| 98 | 107 | // we have to apply special rules to the first and the last lines |
| 99 | 108 | $lines = explode("\n", $content); |
| 100 | 109 | |
| 101 | - foreach ($lines as $i => $line) { |
|
| 102 | - if (trim($line) === '' && $i !== 0) { |
|
| 110 | + foreach ($lines as $i => $line) |
|
| 111 | + { |
|
| 112 | + if (trim($line) === '' && $i !== 0) |
|
| 113 | + { |
|
| 103 | 114 | unset($lines[$i]); |
| 104 | 115 | } |
| 105 | 116 | } |
| 106 | 117 | |
| 107 | 118 | $lines = array_values($lines); |
| 108 | - if (count($lines) === 0) { |
|
| 119 | + if (count($lines) === 0) |
|
| 120 | + { |
|
| 109 | 121 | $lines[] = ''; |
| 110 | 122 | } |
| 111 | 123 | |
| 112 | 124 | $result = ''; |
| 113 | - foreach ($lines as $i => $line) { |
|
| 114 | - if (trim($line) !== '') { |
|
| 115 | - if ($i === 0) { |
|
| 125 | + foreach ($lines as $i => $line) |
|
| 126 | + { |
|
| 127 | + if (trim($line) !== '') |
|
| 128 | + { |
|
| 129 | + if ($i === 0) |
|
| 130 | + { |
|
| 116 | 131 | $line = rtrim($line); |
| 117 | - } else { |
|
| 132 | + } |
|
| 133 | + else |
|
| 134 | + { |
|
| 118 | 135 | $line = trim($line); |
| 119 | 136 | } |
| 120 | 137 | } |
| 121 | 138 | |
| 122 | - if ($i !== (count($lines) - 1)) { |
|
| 139 | + if ($i !== (count($lines) - 1)) |
|
| 140 | + { |
|
| 123 | 141 | $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
| 124 | 142 | continue; |
| 125 | 143 | } |
| 126 | 144 | |
| 127 | 145 | // working with last line |
| 128 | - if ($position === self::BEFORE_PHP) { |
|
| 146 | + if ($position === self::BEFORE_PHP) |
|
| 147 | + { |
|
| 129 | 148 | $result .= $line . "\n"; |
| 130 | 149 | break; |
| 131 | 150 | } |
| 132 | 151 | |
| 133 | - if ($position === self::BEFORE_CLOSE) { |
|
| 152 | + if ($position === self::BEFORE_CLOSE) |
|
| 153 | + { |
|
| 134 | 154 | $result .= $line . "\n" . str_repeat(self::INDENT, max($level - 1, 0)); |
| 135 | 155 | break; |
| 136 | 156 | } |
@@ -148,12 +168,15 @@ discard block |
||
| 148 | 168 | private function getLevel(VisitorContext $ctx): ?int |
| 149 | 169 | { |
| 150 | 170 | $level = 0; |
| 151 | - foreach ($ctx->getScope() as $node) { |
|
| 152 | - if ($node instanceof Attr) { |
|
| 171 | + foreach ($ctx->getScope() as $node) |
|
| 172 | + { |
|
| 173 | + if ($node instanceof Attr) |
|
| 174 | + { |
|
| 153 | 175 | return null; |
| 154 | 176 | } |
| 155 | 177 | |
| 156 | - if ($node instanceof Block || $node instanceof Template) { |
|
| 178 | + if ($node instanceof Block || $node instanceof Template) |
|
| 179 | + { |
|
| 157 | 180 | continue; |
| 158 | 181 | } |
| 159 | 182 | |
@@ -173,7 +196,8 @@ discard block |
||
| 173 | 196 | */ |
| 174 | 197 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
| 175 | 198 | { |
| 176 | - if (!$joinMultiple) { |
|
| 199 | + if (!$joinMultiple) |
|
| 200 | + { |
|
| 177 | 201 | return str_replace("\r\n", "\n", $string); |
| 178 | 202 | } |
| 179 | 203 | |