@@ -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,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 |