@@ -51,39 +51,39 @@ discard block |
||
51 | 51 | $this->body = null; |
52 | 52 | $hasWhitespace = false; |
53 | 53 | |
54 | - while ($n = $src->next()) { |
|
55 | - if (!$n instanceof Byte) { |
|
54 | + while ($n = $src->next()){ |
|
55 | + if (!$n instanceof Byte){ |
|
56 | 56 | // no other grammars are allowed |
57 | 57 | break; |
58 | 58 | } |
59 | 59 | |
60 | - switch ($n->char) { |
|
60 | + switch ($n->char){ |
|
61 | 61 | case '(': |
62 | 62 | $this->flushName(); |
63 | 63 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); |
64 | 64 | |
65 | 65 | return $this->parseBody($src); |
66 | 66 | default: |
67 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
67 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
68 | 68 | $hasWhitespace = true; |
69 | - if ($this->name !== []) { |
|
69 | + if ($this->name !== []){ |
|
70 | 70 | $this->flushName(); |
71 | 71 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); |
72 | 72 | break; |
73 | 73 | } |
74 | 74 | |
75 | - if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { |
|
75 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE){ |
|
76 | 76 | $this->getLastToken()->content .= $n->char; |
77 | 77 | break; |
78 | 78 | } |
79 | 79 | |
80 | 80 | // invalid directive |
81 | 81 | return false; |
82 | - } elseif ($hasWhitespace) { |
|
82 | + } elseif ($hasWhitespace){ |
|
83 | 83 | return $this->finalize(); |
84 | 84 | } |
85 | 85 | |
86 | - if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
86 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)){ |
|
87 | 87 | $this->flushName(); |
88 | 88 | |
89 | 89 | return $this->finalize(); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function getIterator() |
107 | 107 | { |
108 | - if ($this->tokens === []) { |
|
108 | + if ($this->tokens === []){ |
|
109 | 109 | throw new \LogicException('Directive not parsed'); |
110 | 110 | } |
111 | 111 | |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getKeyword(): string |
131 | 131 | { |
132 | - foreach ($this->tokens as $token) { |
|
133 | - if ($token->type === DynamicGrammar::TYPE_KEYWORD) { |
|
132 | + foreach ($this->tokens as $token){ |
|
133 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD){ |
|
134 | 134 | return $token->content; |
135 | 135 | } |
136 | 136 | } |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function getBody(): ?string |
147 | 147 | { |
148 | - foreach ($this->tokens as $token) { |
|
149 | - if ($token->type === DynamicGrammar::TYPE_BODY) { |
|
148 | + foreach ($this->tokens as $token){ |
|
149 | + if ($token->type === DynamicGrammar::TYPE_BODY){ |
|
150 | 150 | return $token->content; |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | private function flushName(): void |
161 | 161 | { |
162 | - if ($this->name === []) { |
|
162 | + if ($this->name === []){ |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
@@ -176,17 +176,17 @@ discard block |
||
176 | 176 | $this->body = []; |
177 | 177 | $level = 1; |
178 | 178 | |
179 | - while ($nn = $src->next()) { |
|
180 | - if (!$nn instanceof Byte) { |
|
179 | + while ($nn = $src->next()){ |
|
180 | + if (!$nn instanceof Byte){ |
|
181 | 181 | $this->flushBody(); |
182 | 182 | return $this->finalize(); |
183 | 183 | } |
184 | 184 | |
185 | - if (in_array($nn->char, ['"', '"'])) { |
|
185 | + if (in_array($nn->char, ['"', '"'])){ |
|
186 | 186 | $this->body[] = $nn; |
187 | - while ($nnn = $src->next()) { |
|
187 | + while ($nnn = $src->next()){ |
|
188 | 188 | $this->body[] = $nnn; |
189 | - if ($nnn instanceof Byte && $nnn->char === $nn->char) { |
|
189 | + if ($nnn instanceof Byte && $nnn->char === $nn->char){ |
|
190 | 190 | break; |
191 | 191 | } |
192 | 192 | } |
@@ -195,15 +195,15 @@ discard block |
||
195 | 195 | |
196 | 196 | $this->body[] = $nn; |
197 | 197 | |
198 | - if ($nn->char === '(') { |
|
198 | + if ($nn->char === '('){ |
|
199 | 199 | $level++; |
200 | 200 | continue; |
201 | 201 | } |
202 | 202 | |
203 | - if ($nn->char === ')') { |
|
203 | + if ($nn->char === ')'){ |
|
204 | 204 | $level--; |
205 | 205 | |
206 | - if ($level === 0) { |
|
206 | + if ($level === 0){ |
|
207 | 207 | $n = array_pop($this->body); |
208 | 208 | |
209 | 209 | $this->flushBody(); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | private function flushBody(): void |
226 | 226 | { |
227 | - if ($this->body === []) { |
|
227 | + if ($this->body === []){ |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | private function getLastToken(): Token |
239 | 239 | { |
240 | - if ($this->tokens === []) { |
|
240 | + if ($this->tokens === []){ |
|
241 | 241 | throw new \LogicException('Directive not parsed'); |
242 | 242 | } |
243 | 243 | |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | { |
254 | 254 | $tokens = $this->tokens; |
255 | 255 | |
256 | - foreach (array_reverse($tokens, true) as $i => $t) { |
|
257 | - if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { |
|
256 | + foreach (array_reverse($tokens, true) as $i => $t){ |
|
257 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE){ |
|
258 | 258 | break; |
259 | 259 | } |
260 | 260 | |
@@ -262,19 +262,19 @@ discard block |
||
262 | 262 | } |
263 | 263 | |
264 | 264 | $body = null; |
265 | - foreach ($tokens as $t) { |
|
266 | - if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { |
|
265 | + foreach ($tokens as $t){ |
|
266 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN){ |
|
267 | 267 | $body = false; |
268 | 268 | continue; |
269 | 269 | } |
270 | 270 | |
271 | - if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { |
|
271 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE){ |
|
272 | 272 | $body = null; |
273 | 273 | continue; |
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
277 | - if ($body !== null) { |
|
277 | + if ($body !== null){ |
|
278 | 278 | return false; |
279 | 279 | } |
280 | 280 |
@@ -51,39 +51,48 @@ discard block |
||
51 | 51 | $this->body = null; |
52 | 52 | $hasWhitespace = false; |
53 | 53 | |
54 | - while ($n = $src->next()) { |
|
55 | - if (!$n instanceof Byte) { |
|
54 | + while ($n = $src->next()) |
|
55 | + { |
|
56 | + if (!$n instanceof Byte) |
|
57 | + { |
|
56 | 58 | // no other grammars are allowed |
57 | 59 | break; |
58 | 60 | } |
59 | 61 | |
60 | - switch ($n->char) { |
|
62 | + switch ($n->char) |
|
63 | + { |
|
61 | 64 | case '(': |
62 | 65 | $this->flushName(); |
63 | 66 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); |
64 | 67 | |
65 | 68 | return $this->parseBody($src); |
66 | 69 | default: |
67 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
70 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
71 | + { |
|
68 | 72 | $hasWhitespace = true; |
69 | - if ($this->name !== []) { |
|
73 | + if ($this->name !== []) |
|
74 | + { |
|
70 | 75 | $this->flushName(); |
71 | 76 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); |
72 | 77 | break; |
73 | 78 | } |
74 | 79 | |
75 | - if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { |
|
80 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) |
|
81 | + { |
|
76 | 82 | $this->getLastToken()->content .= $n->char; |
77 | 83 | break; |
78 | 84 | } |
79 | 85 | |
80 | 86 | // invalid directive |
81 | 87 | return false; |
82 | - } elseif ($hasWhitespace) { |
|
88 | + } |
|
89 | + elseif ($hasWhitespace) |
|
90 | + { |
|
83 | 91 | return $this->finalize(); |
84 | 92 | } |
85 | 93 | |
86 | - if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
94 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)) |
|
95 | + { |
|
87 | 96 | $this->flushName(); |
88 | 97 | |
89 | 98 | return $this->finalize(); |
@@ -105,7 +114,8 @@ discard block |
||
105 | 114 | */ |
106 | 115 | public function getIterator() |
107 | 116 | { |
108 | - if ($this->tokens === []) { |
|
117 | + if ($this->tokens === []) |
|
118 | + { |
|
109 | 119 | throw new \LogicException('Directive not parsed'); |
110 | 120 | } |
111 | 121 | |
@@ -129,8 +139,10 @@ discard block |
||
129 | 139 | */ |
130 | 140 | public function getKeyword(): string |
131 | 141 | { |
132 | - foreach ($this->tokens as $token) { |
|
133 | - if ($token->type === DynamicGrammar::TYPE_KEYWORD) { |
|
142 | + foreach ($this->tokens as $token) |
|
143 | + { |
|
144 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD) |
|
145 | + { |
|
134 | 146 | return $token->content; |
135 | 147 | } |
136 | 148 | } |
@@ -145,8 +157,10 @@ discard block |
||
145 | 157 | */ |
146 | 158 | public function getBody(): ?string |
147 | 159 | { |
148 | - foreach ($this->tokens as $token) { |
|
149 | - if ($token->type === DynamicGrammar::TYPE_BODY) { |
|
160 | + foreach ($this->tokens as $token) |
|
161 | + { |
|
162 | + if ($token->type === DynamicGrammar::TYPE_BODY) |
|
163 | + { |
|
150 | 164 | return $token->content; |
151 | 165 | } |
152 | 166 | } |
@@ -159,7 +173,8 @@ discard block |
||
159 | 173 | */ |
160 | 174 | private function flushName(): void |
161 | 175 | { |
162 | - if ($this->name === []) { |
|
176 | + if ($this->name === []) |
|
177 | + { |
|
163 | 178 | return; |
164 | 179 | } |
165 | 180 | |
@@ -176,17 +191,22 @@ discard block |
||
176 | 191 | $this->body = []; |
177 | 192 | $level = 1; |
178 | 193 | |
179 | - while ($nn = $src->next()) { |
|
180 | - if (!$nn instanceof Byte) { |
|
194 | + while ($nn = $src->next()) |
|
195 | + { |
|
196 | + if (!$nn instanceof Byte) |
|
197 | + { |
|
181 | 198 | $this->flushBody(); |
182 | 199 | return $this->finalize(); |
183 | 200 | } |
184 | 201 | |
185 | - if (in_array($nn->char, ['"', '"'])) { |
|
202 | + if (in_array($nn->char, ['"', '"'])) |
|
203 | + { |
|
186 | 204 | $this->body[] = $nn; |
187 | - while ($nnn = $src->next()) { |
|
205 | + while ($nnn = $src->next()) |
|
206 | + { |
|
188 | 207 | $this->body[] = $nnn; |
189 | - if ($nnn instanceof Byte && $nnn->char === $nn->char) { |
|
208 | + if ($nnn instanceof Byte && $nnn->char === $nn->char) |
|
209 | + { |
|
190 | 210 | break; |
191 | 211 | } |
192 | 212 | } |
@@ -195,15 +215,18 @@ discard block |
||
195 | 215 | |
196 | 216 | $this->body[] = $nn; |
197 | 217 | |
198 | - if ($nn->char === '(') { |
|
218 | + if ($nn->char === '(') |
|
219 | + { |
|
199 | 220 | $level++; |
200 | 221 | continue; |
201 | 222 | } |
202 | 223 | |
203 | - if ($nn->char === ')') { |
|
224 | + if ($nn->char === ')') |
|
225 | + { |
|
204 | 226 | $level--; |
205 | 227 | |
206 | - if ($level === 0) { |
|
228 | + if ($level === 0) |
|
229 | + { |
|
207 | 230 | $n = array_pop($this->body); |
208 | 231 | |
209 | 232 | $this->flushBody(); |
@@ -224,7 +247,8 @@ discard block |
||
224 | 247 | */ |
225 | 248 | private function flushBody(): void |
226 | 249 | { |
227 | - if ($this->body === []) { |
|
250 | + if ($this->body === []) |
|
251 | + { |
|
228 | 252 | return; |
229 | 253 | } |
230 | 254 | |
@@ -237,7 +261,8 @@ discard block |
||
237 | 261 | */ |
238 | 262 | private function getLastToken(): Token |
239 | 263 | { |
240 | - if ($this->tokens === []) { |
|
264 | + if ($this->tokens === []) |
|
265 | + { |
|
241 | 266 | throw new \LogicException('Directive not parsed'); |
242 | 267 | } |
243 | 268 | |
@@ -253,8 +278,10 @@ discard block |
||
253 | 278 | { |
254 | 279 | $tokens = $this->tokens; |
255 | 280 | |
256 | - foreach (array_reverse($tokens, true) as $i => $t) { |
|
257 | - if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { |
|
281 | + foreach (array_reverse($tokens, true) as $i => $t) |
|
282 | + { |
|
283 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) |
|
284 | + { |
|
258 | 285 | break; |
259 | 286 | } |
260 | 287 | |
@@ -262,19 +289,23 @@ discard block |
||
262 | 289 | } |
263 | 290 | |
264 | 291 | $body = null; |
265 | - foreach ($tokens as $t) { |
|
266 | - if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { |
|
292 | + foreach ($tokens as $t) |
|
293 | + { |
|
294 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) |
|
295 | + { |
|
267 | 296 | $body = false; |
268 | 297 | continue; |
269 | 298 | } |
270 | 299 | |
271 | - if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { |
|
300 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) |
|
301 | + { |
|
272 | 302 | $body = null; |
273 | 303 | continue; |
274 | 304 | } |
275 | 305 | } |
276 | 306 | |
277 | - if ($body !== null) { |
|
307 | + if ($body !== null) |
|
308 | + { |
|
278 | 309 | return false; |
279 | 310 | } |
280 | 311 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public function getStackPath(): string |
52 | 52 | { |
53 | 53 | $path = [$this->nodeName($this->node)]; |
54 | - foreach ($this->stack as $tuple) { |
|
54 | + foreach ($this->stack as $tuple){ |
|
55 | 55 | $path[] = $this->nodeName($tuple[0]); |
56 | 56 | } |
57 | 57 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | private function nodeName(NodeInterface $node): string |
95 | 95 | { |
96 | 96 | $r = new \ReflectionClass($node); |
97 | - if (property_exists($node, 'name')) { |
|
98 | - return lcfirst($r->getShortName()) . "[{$node->name}]"; |
|
97 | + if (property_exists($node, 'name')){ |
|
98 | + return lcfirst($r->getShortName())."[{$node->name}]"; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return lcfirst($r->getShortName()); |
@@ -51,7 +51,8 @@ discard block |
||
51 | 51 | public function getStackPath(): string |
52 | 52 | { |
53 | 53 | $path = [$this->nodeName($this->node)]; |
54 | - foreach ($this->stack as $tuple) { |
|
54 | + foreach ($this->stack as $tuple) |
|
55 | + { |
|
55 | 56 | $path[] = $this->nodeName($tuple[0]); |
56 | 57 | } |
57 | 58 | |
@@ -94,7 +95,8 @@ discard block |
||
94 | 95 | private function nodeName(NodeInterface $node): string |
95 | 96 | { |
96 | 97 | $r = new \ReflectionClass($node); |
97 | - if (property_exists($node, 'name')) { |
|
98 | + if (property_exists($node, 'name')) |
|
99 | + { |
|
98 | 100 | return lcfirst($r->getShortName()) . "[{$node->name}]"; |
99 | 101 | } |
100 | 102 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
71 | 71 | { |
72 | - switch ($token->type) { |
|
72 | + switch ($token->type){ |
|
73 | 73 | case HTMLGrammar::TYPE_OPEN: |
74 | 74 | case HTMLGrammar::TYPE_OPEN_SHORT: |
75 | 75 | $this->node = new Tag(new Parser\Context($token, $parser->getPath())); |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | break; |
79 | 79 | |
80 | 80 | case HTMLGrammar::TYPE_KEYWORD: |
81 | - if ($this->node->name === null) { |
|
81 | + if ($this->node->name === null){ |
|
82 | 82 | $this->node->name = $this->parseToken($parser, $token); |
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | - if ($this->attr !== null && !$this->attr->value instanceof Nil) { |
|
86 | + if ($this->attr !== null && !$this->attr->value instanceof Nil){ |
|
87 | 87 | $this->attr->value = $this->parseToken($parser, $token); |
88 | 88 | $this->attr = null; |
89 | 89 | break; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | break; |
100 | 100 | |
101 | 101 | case HTMLGrammar::TYPE_EQUAL: |
102 | - if ($this->attr === null) { |
|
102 | + if ($this->attr === null){ |
|
103 | 103 | throw new SyntaxException('unexpected attribute token', $token); |
104 | 104 | } |
105 | 105 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | break; |
109 | 109 | |
110 | 110 | case HTMLGrammar::TYPE_ATTRIBUTE: |
111 | - if ($this->attr === null) { |
|
111 | + if ($this->attr === null){ |
|
112 | 112 | throw new SyntaxException('unexpected attribute token', $token); |
113 | 113 | } |
114 | 114 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | strpos($this->attr->name, 'on') === 0 |
119 | 119 | || in_array($this->attr->name, self::VERBATIM_ATTRIBUTES, true) |
120 | 120 | ) |
121 | - ) { |
|
121 | + ){ |
|
122 | 122 | $this->attr->value = $this->parseVerbatim($parser, $token); |
123 | - } else { |
|
123 | + }else{ |
|
124 | 124 | $this->attr->value = $this->parseToken($parser, $token); |
125 | 125 | } |
126 | 126 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | break; |
135 | 135 | |
136 | 136 | case HTMLGrammar::TYPE_CLOSE: |
137 | - if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) { |
|
138 | - if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) { |
|
137 | + if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT){ |
|
138 | + if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name){ |
|
139 | 139 | throw new SyntaxException( |
140 | 140 | "Invalid closing tag `{$this->node->name}`, expected `{$asm->getNode()->name}`", |
141 | 141 | $this->token |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | $asm->close(); |
146 | - } else { |
|
147 | - if (in_array($this->node->name, self::VOID_TAGS)) { |
|
146 | + }else{ |
|
147 | + if (in_array($this->node->name, self::VOID_TAGS)){ |
|
148 | 148 | $this->node->void = true; |
149 | 149 | $asm->push($this->node); |
150 | - } else { |
|
150 | + }else{ |
|
151 | 151 | $asm->open($this->node, 'nodes'); |
152 | 152 | } |
153 | 153 | } |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | break; |
161 | 161 | |
162 | 162 | default: |
163 | - if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) { |
|
163 | + if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim){ |
|
164 | 164 | $node = $this->parseToken($parser, $token); |
165 | - if (is_string($node)) { |
|
165 | + if (is_string($node)){ |
|
166 | 166 | $node = new Raw($node, new Parser\Context($token, $parser->getPath())); |
167 | 167 | } |
168 | 168 | |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | { |
191 | 191 | $verbatim = new Verbatim(new Parser\Context($token, $parser->getPath())); |
192 | 192 | |
193 | - if ($token->tokens === []) { |
|
194 | - if ($token->content) { |
|
193 | + if ($token->tokens === []){ |
|
194 | + if ($token->content){ |
|
195 | 195 | $verbatim->nodes[] = $token->content; |
196 | 196 | } |
197 | - } else { |
|
197 | + }else{ |
|
198 | 198 | $parser->parseTokens( |
199 | 199 | new Assembler($verbatim, 'nodes'), |
200 | 200 | $token->tokens |
@@ -69,7 +69,8 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
71 | 71 | { |
72 | - switch ($token->type) { |
|
72 | + switch ($token->type) |
|
73 | + { |
|
73 | 74 | case HTMLGrammar::TYPE_OPEN: |
74 | 75 | case HTMLGrammar::TYPE_OPEN_SHORT: |
75 | 76 | $this->node = new Tag(new Parser\Context($token, $parser->getPath())); |
@@ -78,12 +79,14 @@ discard block |
||
78 | 79 | break; |
79 | 80 | |
80 | 81 | case HTMLGrammar::TYPE_KEYWORD: |
81 | - if ($this->node->name === null) { |
|
82 | + if ($this->node->name === null) |
|
83 | + { |
|
82 | 84 | $this->node->name = $this->parseToken($parser, $token); |
83 | 85 | return; |
84 | 86 | } |
85 | 87 | |
86 | - if ($this->attr !== null && !$this->attr->value instanceof Nil) { |
|
88 | + if ($this->attr !== null && !$this->attr->value instanceof Nil) |
|
89 | + { |
|
87 | 90 | $this->attr->value = $this->parseToken($parser, $token); |
88 | 91 | $this->attr = null; |
89 | 92 | break; |
@@ -99,7 +102,8 @@ discard block |
||
99 | 102 | break; |
100 | 103 | |
101 | 104 | case HTMLGrammar::TYPE_EQUAL: |
102 | - if ($this->attr === null) { |
|
105 | + if ($this->attr === null) |
|
106 | + { |
|
103 | 107 | throw new SyntaxException('unexpected attribute token', $token); |
104 | 108 | } |
105 | 109 | |
@@ -108,7 +112,8 @@ discard block |
||
108 | 112 | break; |
109 | 113 | |
110 | 114 | case HTMLGrammar::TYPE_ATTRIBUTE: |
111 | - if ($this->attr === null) { |
|
115 | + if ($this->attr === null) |
|
116 | + { |
|
112 | 117 | throw new SyntaxException('unexpected attribute token', $token); |
113 | 118 | } |
114 | 119 | |
@@ -120,7 +125,9 @@ discard block |
||
120 | 125 | ) |
121 | 126 | ) { |
122 | 127 | $this->attr->value = $this->parseVerbatim($parser, $token); |
123 | - } else { |
|
128 | + } |
|
129 | + else |
|
130 | + { |
|
124 | 131 | $this->attr->value = $this->parseToken($parser, $token); |
125 | 132 | } |
126 | 133 | |
@@ -134,8 +141,10 @@ discard block |
||
134 | 141 | break; |
135 | 142 | |
136 | 143 | case HTMLGrammar::TYPE_CLOSE: |
137 | - if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) { |
|
138 | - if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) { |
|
144 | + if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) |
|
145 | + { |
|
146 | + if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) |
|
147 | + { |
|
139 | 148 | throw new SyntaxException( |
140 | 149 | "Invalid closing tag `{$this->node->name}`, expected `{$asm->getNode()->name}`", |
141 | 150 | $this->token |
@@ -143,11 +152,16 @@ discard block |
||
143 | 152 | } |
144 | 153 | |
145 | 154 | $asm->close(); |
146 | - } else { |
|
147 | - if (in_array($this->node->name, self::VOID_TAGS)) { |
|
155 | + } |
|
156 | + else |
|
157 | + { |
|
158 | + if (in_array($this->node->name, self::VOID_TAGS)) |
|
159 | + { |
|
148 | 160 | $this->node->void = true; |
149 | 161 | $asm->push($this->node); |
150 | - } else { |
|
162 | + } |
|
163 | + else |
|
164 | + { |
|
151 | 165 | $asm->open($this->node, 'nodes'); |
152 | 166 | } |
153 | 167 | } |
@@ -160,9 +174,11 @@ discard block |
||
160 | 174 | break; |
161 | 175 | |
162 | 176 | default: |
163 | - if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) { |
|
177 | + if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) |
|
178 | + { |
|
164 | 179 | $node = $this->parseToken($parser, $token); |
165 | - if (is_string($node)) { |
|
180 | + if (is_string($node)) |
|
181 | + { |
|
166 | 182 | $node = new Raw($node, new Parser\Context($token, $parser->getPath())); |
167 | 183 | } |
168 | 184 | |
@@ -190,11 +206,15 @@ discard block |
||
190 | 206 | { |
191 | 207 | $verbatim = new Verbatim(new Parser\Context($token, $parser->getPath())); |
192 | 208 | |
193 | - if ($token->tokens === []) { |
|
194 | - if ($token->content) { |
|
209 | + if ($token->tokens === []) |
|
210 | + { |
|
211 | + if ($token->content) |
|
212 | + { |
|
195 | 213 | $verbatim->nodes[] = $token->content; |
196 | 214 | } |
197 | - } else { |
|
215 | + } |
|
216 | + else |
|
217 | + { |
|
198 | 218 | $parser->parseTokens( |
199 | 219 | new Assembler($verbatim, 'nodes'), |
200 | 220 | $token->tokens |
@@ -30,7 +30,7 @@ |
||
30 | 30 | */ |
31 | 31 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
32 | 32 | { |
33 | - switch ($token->type) { |
|
33 | + switch ($token->type){ |
|
34 | 34 | case InlineGrammar::TYPE_OPEN_TAG: |
35 | 35 | $this->inline = new Inline(new Parser\Context($token, $parser->getPath())); |
36 | 36 | $asm->push($this->inline); |
@@ -30,7 +30,8 @@ |
||
30 | 30 | */ |
31 | 31 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
32 | 32 | { |
33 | - switch ($token->type) { |
|
33 | + switch ($token->type) |
|
34 | + { |
|
34 | 35 | case InlineGrammar::TYPE_OPEN_TAG: |
35 | 36 | $this->inline = new Inline(new Parser\Context($token, $parser->getPath())); |
36 | 37 | $asm->push($this->inline); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
38 | 38 | { |
39 | - switch ($token->type) { |
|
39 | + switch ($token->type){ |
|
40 | 40 | case DynamicGrammar::TYPE_DIRECTIVE: |
41 | 41 | $this->directive = new Directive(new Parser\Context($token, $parser->getPath())); |
42 | 42 | $asm->push($this->directive); |
@@ -61,20 +61,20 @@ discard block |
||
61 | 61 | break; |
62 | 62 | |
63 | 63 | case DynamicGrammar::TYPE_KEYWORD: |
64 | - if ($this->directive !== null) { |
|
64 | + if ($this->directive !== null){ |
|
65 | 65 | $this->directive->name = $token->content; |
66 | 66 | } |
67 | 67 | break; |
68 | 68 | |
69 | 69 | case DynamicGrammar::TYPE_BODY: |
70 | - if ($this->directive !== null) { |
|
70 | + if ($this->directive !== null){ |
|
71 | 71 | $this->directive->body = $token->content; |
72 | 72 | $this->directive->values = $this->fetchValues($this->directive->body); |
73 | 73 | |
74 | 74 | $this->directive = null; |
75 | 75 | } |
76 | 76 | |
77 | - if ($this->output !== null) { |
|
77 | + if ($this->output !== null){ |
|
78 | 78 | $this->output->body = $token->content; |
79 | 79 | } |
80 | 80 | |
@@ -95,31 +95,31 @@ discard block |
||
95 | 95 | |
96 | 96 | $src = new StringStream($body); |
97 | 97 | |
98 | - while ($n = $src->peak()) { |
|
99 | - if (in_array($n, ['"', '"'])) { |
|
98 | + while ($n = $src->peak()){ |
|
99 | + if (in_array($n, ['"', '"'])){ |
|
100 | 100 | $values[count($values) - 1] .= $n; |
101 | - while ($nn = $src->peak()) { |
|
101 | + while ($nn = $src->peak()){ |
|
102 | 102 | $values[count($values) - 1] .= $nn; |
103 | - if ($nn === $n) { |
|
103 | + if ($nn === $n){ |
|
104 | 104 | break; |
105 | 105 | } |
106 | 106 | } |
107 | 107 | continue; |
108 | 108 | } |
109 | 109 | |
110 | - if ($n === ',' && $level === 0) { |
|
110 | + if ($n === ',' && $level === 0){ |
|
111 | 111 | $values[] = ''; |
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
115 | 115 | $values[count($values) - 1] .= $n; |
116 | 116 | |
117 | - if ($n === '(' || $n === '[' || $n === '{') { |
|
117 | + if ($n === '(' || $n === '[' || $n === '{'){ |
|
118 | 118 | $level++; |
119 | 119 | continue; |
120 | 120 | } |
121 | 121 | |
122 | - if ($n === ')' || $n === ']' || $n === '}') { |
|
122 | + if ($n === ')' || $n === ']' || $n === '}'){ |
|
123 | 123 | $level--; |
124 | 124 | } |
125 | 125 | } |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
38 | 38 | { |
39 | - switch ($token->type) { |
|
39 | + switch ($token->type) |
|
40 | + { |
|
40 | 41 | case DynamicGrammar::TYPE_DIRECTIVE: |
41 | 42 | $this->directive = new Directive(new Parser\Context($token, $parser->getPath())); |
42 | 43 | $asm->push($this->directive); |
@@ -61,20 +62,23 @@ discard block |
||
61 | 62 | break; |
62 | 63 | |
63 | 64 | case DynamicGrammar::TYPE_KEYWORD: |
64 | - if ($this->directive !== null) { |
|
65 | + if ($this->directive !== null) |
|
66 | + { |
|
65 | 67 | $this->directive->name = $token->content; |
66 | 68 | } |
67 | 69 | break; |
68 | 70 | |
69 | 71 | case DynamicGrammar::TYPE_BODY: |
70 | - if ($this->directive !== null) { |
|
72 | + if ($this->directive !== null) |
|
73 | + { |
|
71 | 74 | $this->directive->body = $token->content; |
72 | 75 | $this->directive->values = $this->fetchValues($this->directive->body); |
73 | 76 | |
74 | 77 | $this->directive = null; |
75 | 78 | } |
76 | 79 | |
77 | - if ($this->output !== null) { |
|
80 | + if ($this->output !== null) |
|
81 | + { |
|
78 | 82 | $this->output->body = $token->content; |
79 | 83 | } |
80 | 84 | |
@@ -95,31 +99,38 @@ discard block |
||
95 | 99 | |
96 | 100 | $src = new StringStream($body); |
97 | 101 | |
98 | - while ($n = $src->peak()) { |
|
99 | - if (in_array($n, ['"', '"'])) { |
|
102 | + while ($n = $src->peak()) |
|
103 | + { |
|
104 | + if (in_array($n, ['"', '"'])) |
|
105 | + { |
|
100 | 106 | $values[count($values) - 1] .= $n; |
101 | - while ($nn = $src->peak()) { |
|
107 | + while ($nn = $src->peak()) |
|
108 | + { |
|
102 | 109 | $values[count($values) - 1] .= $nn; |
103 | - if ($nn === $n) { |
|
110 | + if ($nn === $n) |
|
111 | + { |
|
104 | 112 | break; |
105 | 113 | } |
106 | 114 | } |
107 | 115 | continue; |
108 | 116 | } |
109 | 117 | |
110 | - if ($n === ',' && $level === 0) { |
|
118 | + if ($n === ',' && $level === 0) |
|
119 | + { |
|
111 | 120 | $values[] = ''; |
112 | 121 | continue; |
113 | 122 | } |
114 | 123 | |
115 | 124 | $values[count($values) - 1] .= $n; |
116 | 125 | |
117 | - if ($n === '(' || $n === '[' || $n === '{') { |
|
126 | + if ($n === '(' || $n === '[' || $n === '{') |
|
127 | + { |
|
118 | 128 | $level++; |
119 | 129 | continue; |
120 | 130 | } |
121 | 131 | |
122 | - if ($n === ')' || $n === ']' || $n === '}') { |
|
132 | + if ($n === ')' || $n === ']' || $n === '}') |
|
133 | + { |
|
123 | 134 | $level--; |
124 | 135 | } |
125 | 136 | } |
@@ -26,8 +26,8 @@ |
||
26 | 26 | */ |
27 | 27 | private function parseToken(Parser $parser, Token $token) |
28 | 28 | { |
29 | - if ($token->tokens === []) { |
|
30 | - if ($token->type === Token::TYPE_RAW) { |
|
29 | + if ($token->tokens === []){ |
|
30 | + if ($token->type === Token::TYPE_RAW){ |
|
31 | 31 | return new Raw($token->content); |
32 | 32 | } |
33 | 33 |
@@ -26,8 +26,10 @@ |
||
26 | 26 | */ |
27 | 27 | private function parseToken(Parser $parser, Token $token) |
28 | 28 | { |
29 | - if ($token->tokens === []) { |
|
30 | - if ($token->type === Token::TYPE_RAW) { |
|
29 | + if ($token->tokens === []) |
|
30 | + { |
|
31 | + if ($token->type === Token::TYPE_RAW) |
|
32 | + { |
|
31 | 33 | return new Raw($token->content); |
32 | 34 | } |
33 | 35 |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $parser->path = $path; |
59 | 59 | $parser->lexer = clone $this->lexer; |
60 | 60 | |
61 | - foreach ($parser->syntax as $grammar => $stx) { |
|
61 | + foreach ($parser->syntax as $grammar => $stx){ |
|
62 | 62 | $parser->syntax[$grammar] = clone $stx; |
63 | 63 | } |
64 | 64 | |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | { |
96 | 96 | $template = new Template(); |
97 | 97 | |
98 | - try { |
|
98 | + try{ |
|
99 | 99 | $this->parseTokens( |
100 | 100 | new Assembler($template, 'nodes'), |
101 | 101 | $this->lexer->parse($stream) |
102 | 102 | ); |
103 | - } catch (SyntaxException $e) { |
|
103 | + }catch (SyntaxException $e){ |
|
104 | 104 | throw new ParserException( |
105 | 105 | $e->getMessage(), |
106 | 106 | new Context($e->getToken(), $this->getPath()), |
@@ -122,21 +122,21 @@ discard block |
||
122 | 122 | $node = $asm->getNode(); |
123 | 123 | |
124 | 124 | $syntax = []; |
125 | - foreach ($this->syntax as $grammar => $stx) { |
|
125 | + foreach ($this->syntax as $grammar => $stx){ |
|
126 | 126 | $syntax[$grammar] = clone $stx; |
127 | 127 | } |
128 | 128 | |
129 | - foreach ($tokens as $token) { |
|
130 | - if (!isset($syntax[$token->grammar])) { |
|
129 | + foreach ($tokens as $token){ |
|
130 | + if (!isset($syntax[$token->grammar])){ |
|
131 | 131 | throw new SyntaxException('Undefined token', $token); |
132 | 132 | } |
133 | 133 | |
134 | 134 | $syntax[$token->grammar]->handle($this, $asm, $token); |
135 | 135 | } |
136 | 136 | |
137 | - if ($asm->getNode() !== $node) { |
|
137 | + if ($asm->getNode() !== $node){ |
|
138 | 138 | throw new SyntaxException( |
139 | - 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
|
139 | + 'Invalid node hierarchy, unclosed '.$asm->getStackPath(), |
|
140 | 140 | $asm->getNode()->getContext()->getToken() |
141 | 141 | ); |
142 | 142 | } |
@@ -58,7 +58,8 @@ discard block |
||
58 | 58 | $parser->path = $path; |
59 | 59 | $parser->lexer = clone $this->lexer; |
60 | 60 | |
61 | - foreach ($parser->syntax as $grammar => $stx) { |
|
61 | + foreach ($parser->syntax as $grammar => $stx) |
|
62 | + { |
|
62 | 63 | $parser->syntax[$grammar] = clone $stx; |
63 | 64 | } |
64 | 65 | |
@@ -95,12 +96,15 @@ discard block |
||
95 | 96 | { |
96 | 97 | $template = new Template(); |
97 | 98 | |
98 | - try { |
|
99 | + try |
|
100 | + { |
|
99 | 101 | $this->parseTokens( |
100 | 102 | new Assembler($template, 'nodes'), |
101 | 103 | $this->lexer->parse($stream) |
102 | 104 | ); |
103 | - } catch (SyntaxException $e) { |
|
105 | + } |
|
106 | + catch (SyntaxException $e) |
|
107 | + { |
|
104 | 108 | throw new ParserException( |
105 | 109 | $e->getMessage(), |
106 | 110 | new Context($e->getToken(), $this->getPath()), |
@@ -122,19 +126,23 @@ discard block |
||
122 | 126 | $node = $asm->getNode(); |
123 | 127 | |
124 | 128 | $syntax = []; |
125 | - foreach ($this->syntax as $grammar => $stx) { |
|
129 | + foreach ($this->syntax as $grammar => $stx) |
|
130 | + { |
|
126 | 131 | $syntax[$grammar] = clone $stx; |
127 | 132 | } |
128 | 133 | |
129 | - foreach ($tokens as $token) { |
|
130 | - if (!isset($syntax[$token->grammar])) { |
|
134 | + foreach ($tokens as $token) |
|
135 | + { |
|
136 | + if (!isset($syntax[$token->grammar])) |
|
137 | + { |
|
131 | 138 | throw new SyntaxException('Undefined token', $token); |
132 | 139 | } |
133 | 140 | |
134 | 141 | $syntax[$token->grammar]->handle($this, $asm, $token); |
135 | 142 | } |
136 | 143 | |
137 | - if ($asm->getNode() !== $node) { |
|
144 | + if ($asm->getNode() !== $node) |
|
145 | + { |
|
138 | 146 | throw new SyntaxException( |
139 | 147 | 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
140 | 148 | $asm->getNode()->getContext()->getToken() |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct(array $visitors = []) |
33 | 33 | { |
34 | - foreach ($visitors as $visitor) { |
|
34 | + foreach ($visitors as $visitor){ |
|
35 | 35 | $this->addVisitor($visitor); |
36 | 36 | } |
37 | 37 | } |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function removeVisitor(VisitorInterface $visitor): void |
53 | 53 | { |
54 | - foreach ($this->visitors as $index => $added) { |
|
55 | - if ($added === $visitor) { |
|
54 | + foreach ($this->visitors as $index => $added){ |
|
55 | + if ($added === $visitor){ |
|
56 | 56 | unset($this->visitors[$index]); |
57 | 57 | break; |
58 | 58 | } |
@@ -73,22 +73,22 @@ discard block |
||
73 | 73 | $context = $context ?? new VisitorContext(); |
74 | 74 | |
75 | 75 | $ctx = clone $context; |
76 | - foreach ($nodes as $index => $node) { |
|
77 | - if ($this->stopTraversal) { |
|
76 | + foreach ($nodes as $index => $node){ |
|
77 | + if ($this->stopTraversal){ |
|
78 | 78 | break; |
79 | 79 | } |
80 | 80 | |
81 | 81 | $traverseChildren = true; |
82 | 82 | $breakVisitorID = null; |
83 | 83 | |
84 | - if ($node instanceof NodeInterface) { |
|
84 | + if ($node instanceof NodeInterface){ |
|
85 | 85 | $ctx = $context->withNode($node); |
86 | 86 | } |
87 | 87 | |
88 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
88 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
89 | 89 | $result = $visitor->enterNode($node, $ctx); |
90 | 90 | |
91 | - switch (true) { |
|
91 | + switch (true){ |
|
92 | 92 | case $result === null: |
93 | 93 | break; |
94 | 94 | |
@@ -112,23 +112,23 @@ discard block |
||
112 | 112 | |
113 | 113 | default: |
114 | 114 | throw new \LogicException( |
115 | - 'enterNode() returned invalid value of type ' . gettype($result) |
|
115 | + 'enterNode() returned invalid value of type '.gettype($result) |
|
116 | 116 | ); |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | 120 | // sub nodes |
121 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
121 | + if ($traverseChildren && $node instanceof NodeInterface){ |
|
122 | 122 | $nodes[$index] = $this->traverseNode($node, $ctx); |
123 | - if ($this->stopTraversal) { |
|
123 | + if ($this->stopTraversal){ |
|
124 | 124 | break; |
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
128 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
129 | 129 | $result = $visitor->leaveNode($node, $ctx); |
130 | 130 | |
131 | - switch (true) { |
|
131 | + switch (true){ |
|
132 | 132 | case $result === null: |
133 | 133 | break; |
134 | 134 | |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | |
147 | 147 | default: |
148 | 148 | throw new \LogicException( |
149 | - 'leaveNode() returned invalid value of type ' . gettype($result) |
|
149 | + 'leaveNode() returned invalid value of type '.gettype($result) |
|
150 | 150 | ); |
151 | 151 | } |
152 | 152 | |
153 | - if ($breakVisitorID === $visitorID) { |
|
153 | + if ($breakVisitorID === $visitorID){ |
|
154 | 154 | break; |
155 | 155 | } |
156 | 156 | } |
@@ -169,18 +169,18 @@ discard block |
||
169 | 169 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
170 | 170 | { |
171 | 171 | $ctx = clone $context; |
172 | - foreach ($node as $name => $_) { |
|
172 | + foreach ($node as $name => $_){ |
|
173 | 173 | $child = &$node->$name; |
174 | - if (is_array($child)) { |
|
174 | + if (is_array($child)){ |
|
175 | 175 | $child = $this->traverse($child, $ctx); |
176 | - if ($this->stopTraversal) { |
|
176 | + if ($this->stopTraversal){ |
|
177 | 177 | break; |
178 | 178 | } |
179 | 179 | |
180 | 180 | continue; |
181 | 181 | } |
182 | 182 | |
183 | - if (!$child instanceof NodeInterface) { |
|
183 | + if (!$child instanceof NodeInterface){ |
|
184 | 184 | continue; |
185 | 185 | } |
186 | 186 | |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | $traverseChildren = true; |
190 | 190 | $breakVisitorID = null; |
191 | 191 | |
192 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
192 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
193 | 193 | $result = $visitor->enterNode($child, $ctx); |
194 | - switch (true) { |
|
194 | + switch (true){ |
|
195 | 195 | case $result === null: |
196 | 196 | break; |
197 | 197 | |
@@ -214,22 +214,22 @@ discard block |
||
214 | 214 | |
215 | 215 | default: |
216 | 216 | throw new \LogicException( |
217 | - 'enterNode() returned invalid value of type ' . gettype($result) |
|
217 | + 'enterNode() returned invalid value of type '.gettype($result) |
|
218 | 218 | ); |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - if ($traverseChildren) { |
|
222 | + if ($traverseChildren){ |
|
223 | 223 | $child = $this->traverseNode($child, $ctx); |
224 | - if ($this->stopTraversal) { |
|
224 | + if ($this->stopTraversal){ |
|
225 | 225 | break; |
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
229 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
229 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
230 | 230 | $result = $visitor->leaveNode($child, $ctx); |
231 | 231 | |
232 | - switch (true) { |
|
232 | + switch (true){ |
|
233 | 233 | case $result === null: |
234 | 234 | break; |
235 | 235 | |
@@ -243,11 +243,11 @@ discard block |
||
243 | 243 | |
244 | 244 | default: |
245 | 245 | throw new \LogicException( |
246 | - 'leaveNode() returned invalid value of type ' . gettype($result) |
|
246 | + 'leaveNode() returned invalid value of type '.gettype($result) |
|
247 | 247 | ); |
248 | 248 | } |
249 | 249 | |
250 | - if ($breakVisitorID === $visitorID) { |
|
250 | + if ($breakVisitorID === $visitorID){ |
|
251 | 251 | break; |
252 | 252 | } |
253 | 253 | } |
@@ -31,7 +31,8 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct(array $visitors = []) |
33 | 33 | { |
34 | - foreach ($visitors as $visitor) { |
|
34 | + foreach ($visitors as $visitor) |
|
35 | + { |
|
35 | 36 | $this->addVisitor($visitor); |
36 | 37 | } |
37 | 38 | } |
@@ -51,8 +52,10 @@ discard block |
||
51 | 52 | */ |
52 | 53 | public function removeVisitor(VisitorInterface $visitor): void |
53 | 54 | { |
54 | - foreach ($this->visitors as $index => $added) { |
|
55 | - if ($added === $visitor) { |
|
55 | + foreach ($this->visitors as $index => $added) |
|
56 | + { |
|
57 | + if ($added === $visitor) |
|
58 | + { |
|
56 | 59 | unset($this->visitors[$index]); |
57 | 60 | break; |
58 | 61 | } |
@@ -73,22 +76,27 @@ discard block |
||
73 | 76 | $context = $context ?? new VisitorContext(); |
74 | 77 | |
75 | 78 | $ctx = clone $context; |
76 | - foreach ($nodes as $index => $node) { |
|
77 | - if ($this->stopTraversal) { |
|
79 | + foreach ($nodes as $index => $node) |
|
80 | + { |
|
81 | + if ($this->stopTraversal) |
|
82 | + { |
|
78 | 83 | break; |
79 | 84 | } |
80 | 85 | |
81 | 86 | $traverseChildren = true; |
82 | 87 | $breakVisitorID = null; |
83 | 88 | |
84 | - if ($node instanceof NodeInterface) { |
|
89 | + if ($node instanceof NodeInterface) |
|
90 | + { |
|
85 | 91 | $ctx = $context->withNode($node); |
86 | 92 | } |
87 | 93 | |
88 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
94 | + foreach ($this->visitors as $visitorID => $visitor) |
|
95 | + { |
|
89 | 96 | $result = $visitor->enterNode($node, $ctx); |
90 | 97 | |
91 | - switch (true) { |
|
98 | + switch (true) |
|
99 | + { |
|
92 | 100 | case $result === null: |
93 | 101 | break; |
94 | 102 | |
@@ -118,17 +126,21 @@ discard block |
||
118 | 126 | } |
119 | 127 | |
120 | 128 | // sub nodes |
121 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
129 | + if ($traverseChildren && $node instanceof NodeInterface) |
|
130 | + { |
|
122 | 131 | $nodes[$index] = $this->traverseNode($node, $ctx); |
123 | - if ($this->stopTraversal) { |
|
132 | + if ($this->stopTraversal) |
|
133 | + { |
|
124 | 134 | break; |
125 | 135 | } |
126 | 136 | } |
127 | 137 | |
128 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
138 | + foreach ($this->visitors as $visitorID => $visitor) |
|
139 | + { |
|
129 | 140 | $result = $visitor->leaveNode($node, $ctx); |
130 | 141 | |
131 | - switch (true) { |
|
142 | + switch (true) |
|
143 | + { |
|
132 | 144 | case $result === null: |
133 | 145 | break; |
134 | 146 | |
@@ -150,7 +162,8 @@ discard block |
||
150 | 162 | ); |
151 | 163 | } |
152 | 164 | |
153 | - if ($breakVisitorID === $visitorID) { |
|
165 | + if ($breakVisitorID === $visitorID) |
|
166 | + { |
|
154 | 167 | break; |
155 | 168 | } |
156 | 169 | } |
@@ -169,18 +182,22 @@ discard block |
||
169 | 182 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
170 | 183 | { |
171 | 184 | $ctx = clone $context; |
172 | - foreach ($node as $name => $_) { |
|
185 | + foreach ($node as $name => $_) |
|
186 | + { |
|
173 | 187 | $child = &$node->$name; |
174 | - if (is_array($child)) { |
|
188 | + if (is_array($child)) |
|
189 | + { |
|
175 | 190 | $child = $this->traverse($child, $ctx); |
176 | - if ($this->stopTraversal) { |
|
191 | + if ($this->stopTraversal) |
|
192 | + { |
|
177 | 193 | break; |
178 | 194 | } |
179 | 195 | |
180 | 196 | continue; |
181 | 197 | } |
182 | 198 | |
183 | - if (!$child instanceof NodeInterface) { |
|
199 | + if (!$child instanceof NodeInterface) |
|
200 | + { |
|
184 | 201 | continue; |
185 | 202 | } |
186 | 203 | |
@@ -189,9 +206,11 @@ discard block |
||
189 | 206 | $traverseChildren = true; |
190 | 207 | $breakVisitorID = null; |
191 | 208 | |
192 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
209 | + foreach ($this->visitors as $visitorID => $visitor) |
|
210 | + { |
|
193 | 211 | $result = $visitor->enterNode($child, $ctx); |
194 | - switch (true) { |
|
212 | + switch (true) |
|
213 | + { |
|
195 | 214 | case $result === null: |
196 | 215 | break; |
197 | 216 | |
@@ -219,17 +238,21 @@ discard block |
||
219 | 238 | } |
220 | 239 | } |
221 | 240 | |
222 | - if ($traverseChildren) { |
|
241 | + if ($traverseChildren) |
|
242 | + { |
|
223 | 243 | $child = $this->traverseNode($child, $ctx); |
224 | - if ($this->stopTraversal) { |
|
244 | + if ($this->stopTraversal) |
|
245 | + { |
|
225 | 246 | break; |
226 | 247 | } |
227 | 248 | } |
228 | 249 | |
229 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
250 | + foreach ($this->visitors as $visitorID => $visitor) |
|
251 | + { |
|
230 | 252 | $result = $visitor->leaveNode($child, $ctx); |
231 | 253 | |
232 | - switch (true) { |
|
254 | + switch (true) |
|
255 | + { |
|
233 | 256 | case $result === null: |
234 | 257 | break; |
235 | 258 | |
@@ -247,7 +270,8 @@ discard block |
||
247 | 270 | ); |
248 | 271 | } |
249 | 272 | |
250 | - if ($breakVisitorID === $visitorID) { |
|
273 | + if ($breakVisitorID === $visitorID) |
|
274 | + { |
|
251 | 275 | break; |
252 | 276 | } |
253 | 277 | } |
@@ -118,14 +118,14 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function compileTemplate(Template $tpl): Result |
120 | 120 | { |
121 | - try { |
|
122 | - if (isset($this->visitors[self::STAGE_COMPILE])) { |
|
121 | + try{ |
|
122 | + if (isset($this->visitors[self::STAGE_COMPILE])){ |
|
123 | 123 | $traverser = new Traverser($this->visitors[self::STAGE_COMPILE]); |
124 | 124 | $tpl = $traverser->traverse([$tpl])[0]; |
125 | 125 | } |
126 | 126 | |
127 | 127 | return $this->compiler->compile($tpl); |
128 | - } catch (CompilerException $e) { |
|
128 | + }catch (CompilerException $e){ |
|
129 | 129 | throw $this->mapException($e); |
130 | 130 | } |
131 | 131 | } |
@@ -141,21 +141,21 @@ discard block |
||
141 | 141 | $source = $this->loader->load($path); |
142 | 142 | $stream = new StringStream($source->getContent()); |
143 | 143 | |
144 | - try { |
|
144 | + try{ |
|
145 | 145 | $tpl = $this->parser->withPath($path)->parse($stream); |
146 | 146 | $tpl->setContext(new Context( |
147 | 147 | new Token(Token::TYPE_RAW, 0, ''), |
148 | 148 | $path |
149 | 149 | )); |
150 | - } catch (ParserException $e) { |
|
150 | + }catch (ParserException $e){ |
|
151 | 151 | throw $this->mapException($e); |
152 | 152 | } |
153 | 153 | |
154 | - try { |
|
154 | + try{ |
|
155 | 155 | return $this->process($tpl); |
156 | - } catch (ContextExceptionInterface $e) { |
|
156 | + }catch (ContextExceptionInterface $e){ |
|
157 | 157 | throw $this->mapException($e); |
158 | - } catch (\Throwable $e) { |
|
158 | + }catch (\Throwable $e){ |
|
159 | 159 | throw $e; |
160 | 160 | } |
161 | 161 | } |
@@ -168,17 +168,17 @@ discard block |
||
168 | 168 | */ |
169 | 169 | private function process(Template $template): Template |
170 | 170 | { |
171 | - if (isset($this->visitors[self::STAGE_PREPARE])) { |
|
171 | + if (isset($this->visitors[self::STAGE_PREPARE])){ |
|
172 | 172 | $traverser = new Traverser($this->visitors[self::STAGE_PREPARE]); |
173 | 173 | $template = $traverser->traverse([$template])[0]; |
174 | 174 | } |
175 | 175 | |
176 | - if (isset($this->visitors[self::STAGE_TRANSFORM])) { |
|
176 | + if (isset($this->visitors[self::STAGE_TRANSFORM])){ |
|
177 | 177 | $traverser = new Traverser($this->visitors[self::STAGE_TRANSFORM]); |
178 | 178 | $template = $traverser->traverse([$template])[0]; |
179 | 179 | } |
180 | 180 | |
181 | - if (isset($this->visitors[self::STAGE_FINALIZE])) { |
|
181 | + if (isset($this->visitors[self::STAGE_FINALIZE])){ |
|
182 | 182 | $traverser = new Traverser($this->visitors[self::STAGE_FINALIZE]); |
183 | 183 | $template = $traverser->traverse([$template])[0]; |
184 | 184 | } |
@@ -194,17 +194,17 @@ discard block |
||
194 | 194 | */ |
195 | 195 | private function mapException(ContextExceptionInterface $e): ContextExceptionInterface |
196 | 196 | { |
197 | - if ($e->getContext()->getPath() === null) { |
|
197 | + if ($e->getContext()->getPath() === null){ |
|
198 | 198 | return $e; |
199 | 199 | } |
200 | 200 | |
201 | - try { |
|
201 | + try{ |
|
202 | 202 | $source = $this->loader->load($e->getContext()->getPath()); |
203 | - } catch (LoaderException $te) { |
|
203 | + }catch (LoaderException $te){ |
|
204 | 204 | return $e; |
205 | 205 | } |
206 | 206 | |
207 | - if ($source->getFilename() === null) { |
|
207 | + if ($source->getFilename() === null){ |
|
208 | 208 | return $e; |
209 | 209 | } |
210 | 210 |
@@ -118,14 +118,18 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function compileTemplate(Template $tpl): Result |
120 | 120 | { |
121 | - try { |
|
122 | - if (isset($this->visitors[self::STAGE_COMPILE])) { |
|
121 | + try |
|
122 | + { |
|
123 | + if (isset($this->visitors[self::STAGE_COMPILE])) |
|
124 | + { |
|
123 | 125 | $traverser = new Traverser($this->visitors[self::STAGE_COMPILE]); |
124 | 126 | $tpl = $traverser->traverse([$tpl])[0]; |
125 | 127 | } |
126 | 128 | |
127 | 129 | return $this->compiler->compile($tpl); |
128 | - } catch (CompilerException $e) { |
|
130 | + } |
|
131 | + catch (CompilerException $e) |
|
132 | + { |
|
129 | 133 | throw $this->mapException($e); |
130 | 134 | } |
131 | 135 | } |
@@ -141,21 +145,29 @@ discard block |
||
141 | 145 | $source = $this->loader->load($path); |
142 | 146 | $stream = new StringStream($source->getContent()); |
143 | 147 | |
144 | - try { |
|
148 | + try |
|
149 | + { |
|
145 | 150 | $tpl = $this->parser->withPath($path)->parse($stream); |
146 | 151 | $tpl->setContext(new Context( |
147 | 152 | new Token(Token::TYPE_RAW, 0, ''), |
148 | 153 | $path |
149 | 154 | )); |
150 | - } catch (ParserException $e) { |
|
155 | + } |
|
156 | + catch (ParserException $e) |
|
157 | + { |
|
151 | 158 | throw $this->mapException($e); |
152 | 159 | } |
153 | 160 | |
154 | - try { |
|
161 | + try |
|
162 | + { |
|
155 | 163 | return $this->process($tpl); |
156 | - } catch (ContextExceptionInterface $e) { |
|
164 | + } |
|
165 | + catch (ContextExceptionInterface $e) |
|
166 | + { |
|
157 | 167 | throw $this->mapException($e); |
158 | - } catch (\Throwable $e) { |
|
168 | + } |
|
169 | + catch (\Throwable $e) |
|
170 | + { |
|
159 | 171 | throw $e; |
160 | 172 | } |
161 | 173 | } |
@@ -168,17 +180,20 @@ discard block |
||
168 | 180 | */ |
169 | 181 | private function process(Template $template): Template |
170 | 182 | { |
171 | - if (isset($this->visitors[self::STAGE_PREPARE])) { |
|
183 | + if (isset($this->visitors[self::STAGE_PREPARE])) |
|
184 | + { |
|
172 | 185 | $traverser = new Traverser($this->visitors[self::STAGE_PREPARE]); |
173 | 186 | $template = $traverser->traverse([$template])[0]; |
174 | 187 | } |
175 | 188 | |
176 | - if (isset($this->visitors[self::STAGE_TRANSFORM])) { |
|
189 | + if (isset($this->visitors[self::STAGE_TRANSFORM])) |
|
190 | + { |
|
177 | 191 | $traverser = new Traverser($this->visitors[self::STAGE_TRANSFORM]); |
178 | 192 | $template = $traverser->traverse([$template])[0]; |
179 | 193 | } |
180 | 194 | |
181 | - if (isset($this->visitors[self::STAGE_FINALIZE])) { |
|
195 | + if (isset($this->visitors[self::STAGE_FINALIZE])) |
|
196 | + { |
|
182 | 197 | $traverser = new Traverser($this->visitors[self::STAGE_FINALIZE]); |
183 | 198 | $template = $traverser->traverse([$template])[0]; |
184 | 199 | } |
@@ -194,17 +209,22 @@ discard block |
||
194 | 209 | */ |
195 | 210 | private function mapException(ContextExceptionInterface $e): ContextExceptionInterface |
196 | 211 | { |
197 | - if ($e->getContext()->getPath() === null) { |
|
212 | + if ($e->getContext()->getPath() === null) |
|
213 | + { |
|
198 | 214 | return $e; |
199 | 215 | } |
200 | 216 | |
201 | - try { |
|
217 | + try |
|
218 | + { |
|
202 | 219 | $source = $this->loader->load($e->getContext()->getPath()); |
203 | - } catch (LoaderException $te) { |
|
220 | + } |
|
221 | + catch (LoaderException $te) |
|
222 | + { |
|
204 | 223 | return $e; |
205 | 224 | } |
206 | 225 | |
207 | - if ($source->getFilename() === null) { |
|
226 | + if ($source->getFilename() === null) |
|
227 | + { |
|
208 | 228 | return $e; |
209 | 229 | } |
210 | 230 |