@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
56 | 56 | { |
57 | - switch ($token->type) { |
|
57 | + switch ($token->type){ |
|
58 | 58 | case HTMLGrammar::TYPE_OPEN: |
59 | 59 | case HTMLGrammar::TYPE_OPEN_SHORT: |
60 | 60 | $this->node = new Tag(new Parser\Context($token, $parser->getPath())); |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | break; |
64 | 64 | |
65 | 65 | case HTMLGrammar::TYPE_KEYWORD: |
66 | - if ($this->node->name === null) { |
|
66 | + if ($this->node->name === null){ |
|
67 | 67 | $this->node->name = $this->parseToken($parser, $token); |
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - if ($this->attr !== null && !$this->attr->value instanceof Nil) { |
|
71 | + if ($this->attr !== null && !$this->attr->value instanceof Nil){ |
|
72 | 72 | $this->attr->value = $this->parseToken($parser, $token); |
73 | 73 | $this->attr = null; |
74 | 74 | break; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | break; |
85 | 85 | |
86 | 86 | case HTMLGrammar::TYPE_EQUAL: |
87 | - if ($this->attr === null) { |
|
87 | + if ($this->attr === null){ |
|
88 | 88 | throw new SyntaxException('unexpected attribute token', $token); |
89 | 89 | } |
90 | 90 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | break; |
94 | 94 | |
95 | 95 | case HTMLGrammar::TYPE_ATTRIBUTE: |
96 | - if ($this->attr === null) { |
|
96 | + if ($this->attr === null){ |
|
97 | 97 | throw new SyntaxException('unexpected attribute token', $token); |
98 | 98 | } |
99 | 99 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | \str_starts_with($this->attr->name, 'on') |
104 | 104 | || \in_array($this->attr->name, self::VERBATIM_ATTRIBUTES, true) |
105 | 105 | ) |
106 | - ) { |
|
106 | + ){ |
|
107 | 107 | $this->attr->value = $this->parseVerbatim($parser, $token); |
108 | - } else { |
|
108 | + }else{ |
|
109 | 109 | $this->attr->value = $this->parseToken($parser, $token); |
110 | 110 | } |
111 | 111 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | break; |
120 | 120 | |
121 | 121 | case HTMLGrammar::TYPE_CLOSE: |
122 | - if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) { |
|
123 | - if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) { |
|
122 | + if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT){ |
|
123 | + if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name){ |
|
124 | 124 | /** |
125 | 125 | * TODO issue #767 |
126 | 126 | * @link https://github.com/spiral/framework/issues/767 |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | $asm->close(); |
136 | - } elseif (\in_array($this->node->name, self::VOID_TAGS)) { |
|
136 | + } elseif (\in_array($this->node->name, self::VOID_TAGS)){ |
|
137 | 137 | $this->node->void = true; |
138 | 138 | $asm->push($this->node); |
139 | - } else { |
|
139 | + }else{ |
|
140 | 140 | $asm->open($this->node, 'nodes'); |
141 | 141 | } |
142 | 142 | $this->flush(); |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | break; |
149 | 149 | |
150 | 150 | default: |
151 | - if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) { |
|
151 | + if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim){ |
|
152 | 152 | $node = $this->parseToken($parser, $token); |
153 | - if (\is_string($node)) { |
|
153 | + if (\is_string($node)){ |
|
154 | 154 | $node = new Raw($node, new Parser\Context($token, $parser->getPath())); |
155 | 155 | } |
156 | 156 | |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | { |
174 | 174 | $verbatim = new Verbatim(new Parser\Context($token, $parser->getPath())); |
175 | 175 | |
176 | - if ($token->tokens === []) { |
|
177 | - if ($token->content) { |
|
176 | + if ($token->tokens === []){ |
|
177 | + if ($token->content){ |
|
178 | 178 | $verbatim->nodes[] = $token->content; |
179 | 179 | } |
180 | - } else { |
|
180 | + }else{ |
|
181 | 181 | /** |
182 | 182 | * TODO issue #767 |
183 | 183 | * @link https://github.com/spiral/framework/issues/767 |
@@ -54,7 +54,8 @@ discard block |
||
54 | 54 | |
55 | 55 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
56 | 56 | { |
57 | - switch ($token->type) { |
|
57 | + switch ($token->type) |
|
58 | + { |
|
58 | 59 | case HTMLGrammar::TYPE_OPEN: |
59 | 60 | case HTMLGrammar::TYPE_OPEN_SHORT: |
60 | 61 | $this->node = new Tag(new Parser\Context($token, $parser->getPath())); |
@@ -63,12 +64,14 @@ discard block |
||
63 | 64 | break; |
64 | 65 | |
65 | 66 | case HTMLGrammar::TYPE_KEYWORD: |
66 | - if ($this->node->name === null) { |
|
67 | + if ($this->node->name === null) |
|
68 | + { |
|
67 | 69 | $this->node->name = $this->parseToken($parser, $token); |
68 | 70 | return; |
69 | 71 | } |
70 | 72 | |
71 | - if ($this->attr !== null && !$this->attr->value instanceof Nil) { |
|
73 | + if ($this->attr !== null && !$this->attr->value instanceof Nil) |
|
74 | + { |
|
72 | 75 | $this->attr->value = $this->parseToken($parser, $token); |
73 | 76 | $this->attr = null; |
74 | 77 | break; |
@@ -84,7 +87,8 @@ discard block |
||
84 | 87 | break; |
85 | 88 | |
86 | 89 | case HTMLGrammar::TYPE_EQUAL: |
87 | - if ($this->attr === null) { |
|
90 | + if ($this->attr === null) |
|
91 | + { |
|
88 | 92 | throw new SyntaxException('unexpected attribute token', $token); |
89 | 93 | } |
90 | 94 | |
@@ -93,7 +97,8 @@ discard block |
||
93 | 97 | break; |
94 | 98 | |
95 | 99 | case HTMLGrammar::TYPE_ATTRIBUTE: |
96 | - if ($this->attr === null) { |
|
100 | + if ($this->attr === null) |
|
101 | + { |
|
97 | 102 | throw new SyntaxException('unexpected attribute token', $token); |
98 | 103 | } |
99 | 104 | |
@@ -105,7 +110,9 @@ discard block |
||
105 | 110 | ) |
106 | 111 | ) { |
107 | 112 | $this->attr->value = $this->parseVerbatim($parser, $token); |
108 | - } else { |
|
113 | + } |
|
114 | + else |
|
115 | + { |
|
109 | 116 | $this->attr->value = $this->parseToken($parser, $token); |
110 | 117 | } |
111 | 118 | |
@@ -119,8 +126,10 @@ discard block |
||
119 | 126 | break; |
120 | 127 | |
121 | 128 | case HTMLGrammar::TYPE_CLOSE: |
122 | - if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) { |
|
123 | - if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) { |
|
129 | + if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) |
|
130 | + { |
|
131 | + if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) |
|
132 | + { |
|
124 | 133 | /** |
125 | 134 | * TODO issue #767 |
126 | 135 | * @link https://github.com/spiral/framework/issues/767 |
@@ -133,10 +142,14 @@ discard block |
||
133 | 142 | } |
134 | 143 | |
135 | 144 | $asm->close(); |
136 | - } elseif (\in_array($this->node->name, self::VOID_TAGS)) { |
|
145 | + } |
|
146 | + elseif (\in_array($this->node->name, self::VOID_TAGS)) |
|
147 | + { |
|
137 | 148 | $this->node->void = true; |
138 | 149 | $asm->push($this->node); |
139 | - } else { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
140 | 153 | $asm->open($this->node, 'nodes'); |
141 | 154 | } |
142 | 155 | $this->flush(); |
@@ -148,9 +161,11 @@ discard block |
||
148 | 161 | break; |
149 | 162 | |
150 | 163 | default: |
151 | - if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) { |
|
164 | + if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) |
|
165 | + { |
|
152 | 166 | $node = $this->parseToken($parser, $token); |
153 | - if (\is_string($node)) { |
|
167 | + if (\is_string($node)) |
|
168 | + { |
|
154 | 169 | $node = new Raw($node, new Parser\Context($token, $parser->getPath())); |
155 | 170 | } |
156 | 171 | |
@@ -173,11 +188,15 @@ discard block |
||
173 | 188 | { |
174 | 189 | $verbatim = new Verbatim(new Parser\Context($token, $parser->getPath())); |
175 | 190 | |
176 | - if ($token->tokens === []) { |
|
177 | - if ($token->content) { |
|
191 | + if ($token->tokens === []) |
|
192 | + { |
|
193 | + if ($token->content) |
|
194 | + { |
|
178 | 195 | $verbatim->nodes[] = $token->content; |
179 | 196 | } |
180 | - } else { |
|
197 | + } |
|
198 | + else |
|
199 | + { |
|
181 | 200 | /** |
182 | 201 | * TODO issue #767 |
183 | 202 | * @link https://github.com/spiral/framework/issues/767 |
@@ -17,7 +17,7 @@ |
||
17 | 17 | public function __construct( |
18 | 18 | private Token $token, |
19 | 19 | private ?string $path = null |
20 | - ) { |
|
20 | + ){ |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function getToken(): Token |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public function __construct( |
23 | 23 | private NodeInterface $node, |
24 | 24 | private string $path |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | public function getNode(): NodeInterface |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function getStackPath(): string |
34 | 34 | { |
35 | 35 | $path = [$this->nodeName($this->node)]; |
36 | - foreach ($this->stack as $tuple) { |
|
36 | + foreach ($this->stack as $tuple){ |
|
37 | 37 | $path[] = $this->nodeName($tuple[0]); |
38 | 38 | } |
39 | 39 | |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | private function nodeName(NodeInterface $node): string |
75 | 75 | { |
76 | 76 | $r = new \ReflectionClass($node); |
77 | - if (\property_exists($node, 'name')) { |
|
77 | + if (\property_exists($node, 'name')){ |
|
78 | 78 | /** |
79 | 79 | * TODO issue #767 |
80 | 80 | * @link https://github.com/spiral/framework/issues/767 |
81 | 81 | * @psalm-suppress NoInterfaceProperties |
82 | 82 | */ |
83 | - return \lcfirst($r->getShortName()) . \sprintf('[%s]', $node->name); |
|
83 | + return \lcfirst($r->getShortName()).\sprintf('[%s]', $node->name); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return \lcfirst($r->getShortName()); |
@@ -33,7 +33,8 @@ discard block |
||
33 | 33 | public function getStackPath(): string |
34 | 34 | { |
35 | 35 | $path = [$this->nodeName($this->node)]; |
36 | - foreach ($this->stack as $tuple) { |
|
36 | + foreach ($this->stack as $tuple) |
|
37 | + { |
|
37 | 38 | $path[] = $this->nodeName($tuple[0]); |
38 | 39 | } |
39 | 40 | |
@@ -74,7 +75,8 @@ discard block |
||
74 | 75 | private function nodeName(NodeInterface $node): string |
75 | 76 | { |
76 | 77 | $r = new \ReflectionClass($node); |
77 | - if (\property_exists($node, 'name')) { |
|
78 | + if (\property_exists($node, 'name')) |
|
79 | + { |
|
78 | 80 | /** |
79 | 81 | * TODO issue #767 |
80 | 82 | * @link https://github.com/spiral/framework/issues/767 |
@@ -22,20 +22,20 @@ |
||
22 | 22 | $this->renders[] = $renderer; |
23 | 23 | } |
24 | 24 | |
25 | - public function compile(array|NodeInterface $node, Result $result = null): Result |
|
25 | + public function compile(array | NodeInterface $node, Result $result = null): Result |
|
26 | 26 | { |
27 | 27 | $result ??= new Result(); |
28 | 28 | |
29 | - if (\is_array($node)) { |
|
30 | - foreach ($node as $child) { |
|
29 | + if (\is_array($node)){ |
|
30 | + foreach ($node as $child){ |
|
31 | 31 | $this->compile($child, $result); |
32 | 32 | } |
33 | 33 | |
34 | 34 | return $result; |
35 | 35 | } |
36 | 36 | |
37 | - foreach ($this->renders as $renderer) { |
|
38 | - if ($renderer->render($this, $result, $node)) { |
|
37 | + foreach ($this->renders as $renderer){ |
|
38 | + if ($renderer->render($this, $result, $node)){ |
|
39 | 39 | return $result; |
40 | 40 | } |
41 | 41 | } |
@@ -26,16 +26,20 @@ |
||
26 | 26 | { |
27 | 27 | $result ??= new Result(); |
28 | 28 | |
29 | - if (\is_array($node)) { |
|
30 | - foreach ($node as $child) { |
|
29 | + if (\is_array($node)) |
|
30 | + { |
|
31 | + foreach ($node as $child) |
|
32 | + { |
|
31 | 33 | $this->compile($child, $result); |
32 | 34 | } |
33 | 35 | |
34 | 36 | return $result; |
35 | 37 | } |
36 | 38 | |
37 | - foreach ($this->renders as $renderer) { |
|
38 | - if ($renderer->render($this, $result, $node)) { |
|
39 | + foreach ($this->renders as $renderer) |
|
40 | + { |
|
41 | + if ($renderer->render($this, $result, $node)) |
|
42 | + { |
|
39 | 43 | return $result; |
40 | 44 | } |
41 | 45 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | protected function traverse(array $nodes, VisitorInterface ...$visitors): array |
70 | 70 | { |
71 | 71 | $traverser = new Traverser(); |
72 | - foreach ($visitors as $visitor) { |
|
72 | + foreach ($visitors as $visitor){ |
|
73 | 73 | $traverser->addVisitor($visitor); |
74 | 74 | } |
75 | 75 |
@@ -69,7 +69,8 @@ |
||
69 | 69 | protected function traverse(array $nodes, VisitorInterface ...$visitors): array |
70 | 70 | { |
71 | 71 | $traverser = new Traverser(); |
72 | - foreach ($visitors as $visitor) { |
|
72 | + foreach ($visitors as $visitor) |
|
73 | + { |
|
73 | 74 | $traverser->addVisitor($visitor); |
74 | 75 | } |
75 | 76 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | { |
14 | 14 | private function __construct( |
15 | 15 | private readonly VisitorContext $ctx |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function register(Aggregate $aggregate, int $level = 0): void |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | |
29 | 29 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
30 | 30 | { |
31 | - foreach ($this->getStacks() as $stack) { |
|
32 | - if ($stack->accepts($name) !== $name) { |
|
31 | + foreach ($this->getStacks() as $stack){ |
|
32 | + if ($stack->accepts($name) !== $name){ |
|
33 | 33 | continue; |
34 | 34 | } |
35 | 35 | |
36 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
36 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
37 | 37 | return true; |
38 | 38 | } |
39 | 39 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @link https://github.com/spiral/framework/issues/767 |
44 | 44 | * @psalm-suppress NoInterfaceProperties |
45 | 45 | */ |
46 | - foreach ($child->nodes as $child) { |
|
46 | + foreach ($child->nodes as $child){ |
|
47 | 47 | $stack->nodes[] = $child; |
48 | 48 | } |
49 | 49 | |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | |
56 | 56 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
57 | 57 | { |
58 | - foreach ($this->getStacks() as $stack) { |
|
59 | - if ($stack->accepts($name) !== $name) { |
|
58 | + foreach ($this->getStacks() as $stack){ |
|
59 | + if ($stack->accepts($name) !== $name){ |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
63 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
63 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
64 | 64 | return true; |
65 | 65 | } |
66 | 66 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @link https://github.com/spiral/framework/issues/767 |
70 | 70 | * @psalm-suppress NoInterfaceProperties |
71 | 71 | */ |
72 | - foreach ($child->nodes as $child) { |
|
72 | + foreach ($child->nodes as $child){ |
|
73 | 73 | \array_unshift($stack->nodes, $child); |
74 | 74 | } |
75 | 75 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | public function getStacks(): array |
88 | 88 | { |
89 | 89 | $stacks = []; |
90 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
91 | - if ($node instanceof AttributedInterface) { |
|
92 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
90 | + foreach (\array_reverse($this->ctx->getScope()) as $node){ |
|
91 | + if ($node instanceof AttributedInterface){ |
|
92 | + foreach ($node->getAttribute(self::class, []) as $stack){ |
|
93 | 93 | $stacks[] = $stack; |
94 | 94 | } |
95 | 95 | } |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | |
106 | 106 | private function getStackRootNode(int $level): AttributedInterface |
107 | 107 | { |
108 | - if ($level === 0) { |
|
108 | + if ($level === 0){ |
|
109 | 109 | $node = $this->ctx->getParentNode(); |
110 | - } else { |
|
110 | + }else{ |
|
111 | 111 | $scope = $this->ctx->getScope(); |
112 | 112 | |
113 | 113 | // looking for the parent node via given nesting level |
114 | 114 | $node = $scope[\count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
115 | 115 | } |
116 | 116 | |
117 | - if (!$node instanceof AttributedInterface) { |
|
117 | + if (!$node instanceof AttributedInterface){ |
|
118 | 118 | throw new \LogicException( |
119 | 119 | \sprintf( |
120 | 120 | 'Unable to create import on node without attribute storage (%s)', |
@@ -28,12 +28,15 @@ discard block |
||
28 | 28 | |
29 | 29 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
30 | 30 | { |
31 | - foreach ($this->getStacks() as $stack) { |
|
32 | - if ($stack->accepts($name) !== $name) { |
|
31 | + foreach ($this->getStacks() as $stack) |
|
32 | + { |
|
33 | + if ($stack->accepts($name) !== $name) |
|
34 | + { |
|
33 | 35 | continue; |
34 | 36 | } |
35 | 37 | |
36 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
38 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
39 | + { |
|
37 | 40 | return true; |
38 | 41 | } |
39 | 42 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -43,7 +46,8 @@ discard block |
||
43 | 46 | * @link https://github.com/spiral/framework/issues/767 |
44 | 47 | * @psalm-suppress NoInterfaceProperties |
45 | 48 | */ |
46 | - foreach ($child->nodes as $child) { |
|
49 | + foreach ($child->nodes as $child) |
|
50 | + { |
|
47 | 51 | $stack->nodes[] = $child; |
48 | 52 | } |
49 | 53 | |
@@ -55,12 +59,15 @@ discard block |
||
55 | 59 | |
56 | 60 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
57 | 61 | { |
58 | - foreach ($this->getStacks() as $stack) { |
|
59 | - if ($stack->accepts($name) !== $name) { |
|
62 | + foreach ($this->getStacks() as $stack) |
|
63 | + { |
|
64 | + if ($stack->accepts($name) !== $name) |
|
65 | + { |
|
60 | 66 | continue; |
61 | 67 | } |
62 | 68 | |
63 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
69 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
70 | + { |
|
64 | 71 | return true; |
65 | 72 | } |
66 | 73 | $stack->uniqueIDs[$uniqueID] = true; |
@@ -69,7 +76,8 @@ discard block |
||
69 | 76 | * @link https://github.com/spiral/framework/issues/767 |
70 | 77 | * @psalm-suppress NoInterfaceProperties |
71 | 78 | */ |
72 | - foreach ($child->nodes as $child) { |
|
79 | + foreach ($child->nodes as $child) |
|
80 | + { |
|
73 | 81 | \array_unshift($stack->nodes, $child); |
74 | 82 | } |
75 | 83 | |
@@ -87,9 +95,12 @@ discard block |
||
87 | 95 | public function getStacks(): array |
88 | 96 | { |
89 | 97 | $stacks = []; |
90 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
91 | - if ($node instanceof AttributedInterface) { |
|
92 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
98 | + foreach (\array_reverse($this->ctx->getScope()) as $node) |
|
99 | + { |
|
100 | + if ($node instanceof AttributedInterface) |
|
101 | + { |
|
102 | + foreach ($node->getAttribute(self::class, []) as $stack) |
|
103 | + { |
|
93 | 104 | $stacks[] = $stack; |
94 | 105 | } |
95 | 106 | } |
@@ -105,16 +116,20 @@ discard block |
||
105 | 116 | |
106 | 117 | private function getStackRootNode(int $level): AttributedInterface |
107 | 118 | { |
108 | - if ($level === 0) { |
|
119 | + if ($level === 0) |
|
120 | + { |
|
109 | 121 | $node = $this->ctx->getParentNode(); |
110 | - } else { |
|
122 | + } |
|
123 | + else |
|
124 | + { |
|
111 | 125 | $scope = $this->ctx->getScope(); |
112 | 126 | |
113 | 127 | // looking for the parent node via given nesting level |
114 | 128 | $node = $scope[\count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
115 | 129 | } |
116 | 130 | |
117 | - if (!$node instanceof AttributedInterface) { |
|
131 | + if (!$node instanceof AttributedInterface) |
|
132 | + { |
|
118 | 133 | throw new \LogicException( |
119 | 134 | \sprintf( |
120 | 135 | 'Unable to create import on node without attribute storage (%s)', |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | { |
19 | 19 | private function __construct( |
20 | 20 | private readonly VisitorContext $ctx |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function add(ImportInterface $import): void |
25 | 25 | { |
26 | 26 | $node = $this->ctx->getParentNode(); |
27 | - if (!$node instanceof AttributedInterface) { |
|
27 | + if (!$node instanceof AttributedInterface){ |
|
28 | 28 | throw new LogicException(\sprintf( |
29 | 29 | 'Unable to create import on node without attribute storage (%s)', |
30 | 30 | \get_debug_type($node) |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function resolve(Builder $builder, string $name): ?Template |
43 | 43 | { |
44 | - foreach ($this->getImports() as $import) { |
|
44 | + foreach ($this->getImports() as $import){ |
|
45 | 45 | $tpl = $import->resolve($builder, $name); |
46 | - if ($tpl !== null) { |
|
46 | + if ($tpl !== null){ |
|
47 | 47 | return $tpl; |
48 | 48 | } |
49 | 49 | } |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | public function getImports(): array |
60 | 60 | { |
61 | 61 | $imports = []; |
62 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
63 | - if ($node instanceof AttributedInterface) { |
|
64 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
62 | + foreach (\array_reverse($this->ctx->getScope()) as $node){ |
|
63 | + if ($node instanceof AttributedInterface){ |
|
64 | + foreach ($node->getAttribute(self::class, []) as $import){ |
|
65 | 65 | $imports[] = $import; |
66 | 66 | } |
67 | 67 | } |
@@ -24,7 +24,8 @@ discard block |
||
24 | 24 | public function add(ImportInterface $import): void |
25 | 25 | { |
26 | 26 | $node = $this->ctx->getParentNode(); |
27 | - if (!$node instanceof AttributedInterface) { |
|
27 | + if (!$node instanceof AttributedInterface) |
|
28 | + { |
|
28 | 29 | throw new LogicException(\sprintf( |
29 | 30 | 'Unable to create import on node without attribute storage (%s)', |
30 | 31 | \get_debug_type($node) |
@@ -41,9 +42,11 @@ discard block |
||
41 | 42 | */ |
42 | 43 | public function resolve(Builder $builder, string $name): ?Template |
43 | 44 | { |
44 | - foreach ($this->getImports() as $import) { |
|
45 | + foreach ($this->getImports() as $import) |
|
46 | + { |
|
45 | 47 | $tpl = $import->resolve($builder, $name); |
46 | - if ($tpl !== null) { |
|
48 | + if ($tpl !== null) |
|
49 | + { |
|
47 | 50 | return $tpl; |
48 | 51 | } |
49 | 52 | } |
@@ -59,9 +62,12 @@ discard block |
||
59 | 62 | public function getImports(): array |
60 | 63 | { |
61 | 64 | $imports = []; |
62 | - foreach (\array_reverse($this->ctx->getScope()) as $node) { |
|
63 | - if ($node instanceof AttributedInterface) { |
|
64 | - foreach ($node->getAttribute(self::class, []) as $import) { |
|
65 | + foreach (\array_reverse($this->ctx->getScope()) as $node) |
|
66 | + { |
|
67 | + if ($node instanceof AttributedInterface) |
|
68 | + { |
|
69 | + foreach ($node->getAttribute(self::class, []) as $import) |
|
70 | + { |
|
65 | 71 | $imports[] = $import; |
66 | 72 | } |
67 | 73 | } |
@@ -15,12 +15,12 @@ |
||
15 | 15 | { |
16 | 16 | public function __construct( |
17 | 17 | private readonly string $path |
18 | - ) { |
|
18 | + ){ |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
23 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path){ |
|
24 | 24 | $node->name = null; |
25 | 25 | } |
26 | 26 |
@@ -20,7 +20,8 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if ($node instanceof Block && $node->getContext()->getPath() === $this->path) { |
|
23 | + if ($node instanceof Block && $node->getContext()->getPath() === $this->path) |
|
24 | + { |
|
24 | 25 | $node->name = null; |
25 | 26 | } |
26 | 27 |
@@ -19,21 +19,21 @@ |
||
19 | 19 | |
20 | 20 | public function __construct( |
21 | 21 | private readonly string $path |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
26 | 26 | { |
27 | - if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)) { |
|
27 | + if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)){ |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 | |
31 | - if ($node->getContext()->getPath() !== $this->path) { |
|
31 | + if ($node->getContext()->getPath() !== $this->path){ |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | |
35 | 35 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
36 | - foreach (\array_keys($exists->getBlocks()) as $name) { |
|
36 | + foreach (\array_keys($exists->getBlocks()) as $name){ |
|
37 | 37 | // do not leak to parent template |
38 | 38 | $exists->set($name, 'false'); |
39 | 39 | } |
@@ -24,16 +24,19 @@ |
||
24 | 24 | |
25 | 25 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
26 | 26 | { |
27 | - if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)) { |
|
27 | + if (!$node instanceof PHP || !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION)) |
|
28 | + { |
|
28 | 29 | return null; |
29 | 30 | } |
30 | 31 | |
31 | - if ($node->getContext()->getPath() !== $this->path) { |
|
32 | + if ($node->getContext()->getPath() !== $this->path) |
|
33 | + { |
|
32 | 34 | return null; |
33 | 35 | } |
34 | 36 | |
35 | 37 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
36 | - foreach (\array_keys($exists->getBlocks()) as $name) { |
|
38 | + foreach (\array_keys($exists->getBlocks()) as $name) |
|
39 | + { |
|
37 | 40 | // do not leak to parent template |
38 | 41 | $exists->set($name, 'false'); |
39 | 42 | } |