@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | public function __construct( |
15 | 15 | private readonly array $tokens, |
16 | 16 | string $func |
17 | - ) { |
|
17 | + ){ |
|
18 | 18 | $this->parse($func); |
19 | 19 | } |
20 | 20 | |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | { |
23 | 23 | $replace = []; |
24 | 24 | |
25 | - foreach ($this->blocks as $block) { |
|
26 | - for ($i = $block['start']; $i <= $block['end']; $i++) { |
|
25 | + foreach ($this->blocks as $block){ |
|
26 | + for ($i = $block['start']; $i <= $block['end']; $i++){ |
|
27 | 27 | $replace[$i] = ''; |
28 | 28 | } |
29 | 29 | |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | $result = ''; |
34 | - foreach ($this->tokens as $position => $token) { |
|
35 | - if (\array_key_exists($position, $replace)) { |
|
34 | + foreach ($this->tokens as $position => $token){ |
|
35 | + if (\array_key_exists($position, $replace)){ |
|
36 | 36 | $result .= $replace[$position]; |
37 | 37 | continue; |
38 | 38 | } |
39 | 39 | |
40 | - if (\is_string($token)) { |
|
40 | + if (\is_string($token)){ |
|
41 | 41 | $result .= $token; |
42 | 42 | continue; |
43 | 43 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | { |
56 | 56 | $replace = []; |
57 | 57 | |
58 | - foreach ($this->blocks as $block) { |
|
59 | - for ($i = $block['start']; $i <= $block['end']; ++$i) { |
|
58 | + foreach ($this->blocks as $block){ |
|
59 | + for ($i = $block['start']; $i <= $block['end']; ++$i){ |
|
60 | 60 | $replace[$i] = ''; |
61 | 61 | } |
62 | 62 | |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | $result = ''; |
67 | - foreach ($this->tokens as $position => $token) { |
|
68 | - if (\array_key_exists($position, $replace)) { |
|
67 | + foreach ($this->tokens as $position => $token){ |
|
68 | + if (\array_key_exists($position, $replace)){ |
|
69 | 69 | $result .= $replace[$position]; |
70 | 70 | continue; |
71 | 71 | } |
72 | 72 | |
73 | - if (\is_string($token)) { |
|
73 | + if (\is_string($token)){ |
|
74 | 74 | $result .= $token; |
75 | 75 | continue; |
76 | 76 | } |
77 | 77 | |
78 | - if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) { |
|
78 | + if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])){ |
|
79 | 79 | continue; |
80 | 80 | } |
81 | 81 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | public function getBlocks(): array |
92 | 92 | { |
93 | 93 | $result = []; |
94 | - foreach ($this->blocks as $name => $macro) { |
|
94 | + foreach ($this->blocks as $name => $macro){ |
|
95 | 95 | $result[$name] = $macro['value']; |
96 | 96 | } |
97 | 97 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | public function set(string $block, string $value): void |
107 | 107 | { |
108 | - if (!isset($this->blocks[$block])) { |
|
108 | + if (!isset($this->blocks[$block])){ |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
@@ -116,26 +116,26 @@ discard block |
||
116 | 116 | { |
117 | 117 | $level = 0; |
118 | 118 | $start = $name = $value = null; |
119 | - foreach ($this->tokens as $position => $token) { |
|
120 | - if (!\is_array($token)) { |
|
119 | + foreach ($this->tokens as $position => $token){ |
|
120 | + if (!\is_array($token)){ |
|
121 | 121 | $token = [$token, $token, 0]; |
122 | 122 | } |
123 | 123 | |
124 | - switch ($token[0]) { |
|
124 | + switch ($token[0]){ |
|
125 | 125 | case '(': |
126 | - if ($start !== null) { |
|
126 | + if ($start !== null){ |
|
127 | 127 | $level++; |
128 | 128 | $value .= $token[1]; |
129 | 129 | } |
130 | 130 | break; |
131 | 131 | case ')': |
132 | - if ($start === null) { |
|
132 | + if ($start === null){ |
|
133 | 133 | break; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $level--; |
137 | 137 | $value .= $token[1]; |
138 | - if ($level === 0) { |
|
138 | + if ($level === 0){ |
|
139 | 139 | $this->blocks[$name] = [ |
140 | 140 | 'start' => $start, |
141 | 141 | 'value' => trim($value), |
@@ -147,22 +147,22 @@ discard block |
||
147 | 147 | } |
148 | 148 | break; |
149 | 149 | case T_STRING: |
150 | - if ($token[1] === $func) { |
|
150 | + if ($token[1] === $func){ |
|
151 | 151 | $start = $position; |
152 | 152 | $value = $token[1]; |
153 | 153 | break; |
154 | 154 | } |
155 | 155 | |
156 | - if ($start !== null) { |
|
156 | + if ($start !== null){ |
|
157 | 157 | $value .= $token[1]; |
158 | 158 | } |
159 | 159 | break; |
160 | 160 | case T_CONSTANT_ENCAPSED_STRING: |
161 | - if ($start === null) { |
|
161 | + if ($start === null){ |
|
162 | 162 | break; |
163 | 163 | } |
164 | 164 | |
165 | - if ($name === null) { |
|
165 | + if ($name === null){ |
|
166 | 166 | $name = \stripcslashes(\substr($token[1], 1, -1)); |
167 | 167 | } |
168 | 168 | $value .= $token[1]; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $value .= $token[1]; |
172 | 172 | break; |
173 | 173 | default: |
174 | - if ($start !== null) { |
|
174 | + if ($start !== null){ |
|
175 | 175 | $value .= $token[1]; |
176 | 176 | } |
177 | 177 | } |
@@ -22,8 +22,10 @@ discard block |
||
22 | 22 | { |
23 | 23 | $replace = []; |
24 | 24 | |
25 | - foreach ($this->blocks as $block) { |
|
26 | - for ($i = $block['start']; $i <= $block['end']; $i++) { |
|
25 | + foreach ($this->blocks as $block) |
|
26 | + { |
|
27 | + for ($i = $block['start']; $i <= $block['end']; $i++) |
|
28 | + { |
|
27 | 29 | $replace[$i] = ''; |
28 | 30 | } |
29 | 31 | |
@@ -31,13 +33,16 @@ discard block |
||
31 | 33 | } |
32 | 34 | |
33 | 35 | $result = ''; |
34 | - foreach ($this->tokens as $position => $token) { |
|
35 | - if (\array_key_exists($position, $replace)) { |
|
36 | + foreach ($this->tokens as $position => $token) |
|
37 | + { |
|
38 | + if (\array_key_exists($position, $replace)) |
|
39 | + { |
|
36 | 40 | $result .= $replace[$position]; |
37 | 41 | continue; |
38 | 42 | } |
39 | 43 | |
40 | - if (\is_string($token)) { |
|
44 | + if (\is_string($token)) |
|
45 | + { |
|
41 | 46 | $result .= $token; |
42 | 47 | continue; |
43 | 48 | } |
@@ -55,8 +60,10 @@ discard block |
||
55 | 60 | { |
56 | 61 | $replace = []; |
57 | 62 | |
58 | - foreach ($this->blocks as $block) { |
|
59 | - for ($i = $block['start']; $i <= $block['end']; ++$i) { |
|
63 | + foreach ($this->blocks as $block) |
|
64 | + { |
|
65 | + for ($i = $block['start']; $i <= $block['end']; ++$i) |
|
66 | + { |
|
60 | 67 | $replace[$i] = ''; |
61 | 68 | } |
62 | 69 | |
@@ -64,18 +71,22 @@ discard block |
||
64 | 71 | } |
65 | 72 | |
66 | 73 | $result = ''; |
67 | - foreach ($this->tokens as $position => $token) { |
|
68 | - if (\array_key_exists($position, $replace)) { |
|
74 | + foreach ($this->tokens as $position => $token) |
|
75 | + { |
|
76 | + if (\array_key_exists($position, $replace)) |
|
77 | + { |
|
69 | 78 | $result .= $replace[$position]; |
70 | 79 | continue; |
71 | 80 | } |
72 | 81 | |
73 | - if (\is_string($token)) { |
|
82 | + if (\is_string($token)) |
|
83 | + { |
|
74 | 84 | $result .= $token; |
75 | 85 | continue; |
76 | 86 | } |
77 | 87 | |
78 | - if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) { |
|
88 | + if (\in_array($token[0], [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_ECHO])) |
|
89 | + { |
|
79 | 90 | continue; |
80 | 91 | } |
81 | 92 | |
@@ -91,7 +102,8 @@ discard block |
||
91 | 102 | public function getBlocks(): array |
92 | 103 | { |
93 | 104 | $result = []; |
94 | - foreach ($this->blocks as $name => $macro) { |
|
105 | + foreach ($this->blocks as $name => $macro) |
|
106 | + { |
|
95 | 107 | $result[$name] = $macro['value']; |
96 | 108 | } |
97 | 109 | |
@@ -105,7 +117,8 @@ discard block |
||
105 | 117 | |
106 | 118 | public function set(string $block, string $value): void |
107 | 119 | { |
108 | - if (!isset($this->blocks[$block])) { |
|
120 | + if (!isset($this->blocks[$block])) |
|
121 | + { |
|
109 | 122 | return; |
110 | 123 | } |
111 | 124 | |
@@ -116,26 +129,32 @@ discard block |
||
116 | 129 | { |
117 | 130 | $level = 0; |
118 | 131 | $start = $name = $value = null; |
119 | - foreach ($this->tokens as $position => $token) { |
|
120 | - if (!\is_array($token)) { |
|
132 | + foreach ($this->tokens as $position => $token) |
|
133 | + { |
|
134 | + if (!\is_array($token)) |
|
135 | + { |
|
121 | 136 | $token = [$token, $token, 0]; |
122 | 137 | } |
123 | 138 | |
124 | - switch ($token[0]) { |
|
139 | + switch ($token[0]) |
|
140 | + { |
|
125 | 141 | case '(': |
126 | - if ($start !== null) { |
|
142 | + if ($start !== null) |
|
143 | + { |
|
127 | 144 | $level++; |
128 | 145 | $value .= $token[1]; |
129 | 146 | } |
130 | 147 | break; |
131 | 148 | case ')': |
132 | - if ($start === null) { |
|
149 | + if ($start === null) |
|
150 | + { |
|
133 | 151 | break; |
134 | 152 | } |
135 | 153 | |
136 | 154 | $level--; |
137 | 155 | $value .= $token[1]; |
138 | - if ($level === 0) { |
|
156 | + if ($level === 0) |
|
157 | + { |
|
139 | 158 | $this->blocks[$name] = [ |
140 | 159 | 'start' => $start, |
141 | 160 | 'value' => trim($value), |
@@ -147,22 +166,26 @@ discard block |
||
147 | 166 | } |
148 | 167 | break; |
149 | 168 | case T_STRING: |
150 | - if ($token[1] === $func) { |
|
169 | + if ($token[1] === $func) |
|
170 | + { |
|
151 | 171 | $start = $position; |
152 | 172 | $value = $token[1]; |
153 | 173 | break; |
154 | 174 | } |
155 | 175 | |
156 | - if ($start !== null) { |
|
176 | + if ($start !== null) |
|
177 | + { |
|
157 | 178 | $value .= $token[1]; |
158 | 179 | } |
159 | 180 | break; |
160 | 181 | case T_CONSTANT_ENCAPSED_STRING: |
161 | - if ($start === null) { |
|
182 | + if ($start === null) |
|
183 | + { |
|
162 | 184 | break; |
163 | 185 | } |
164 | 186 | |
165 | - if ($name === null) { |
|
187 | + if ($name === null) |
|
188 | + { |
|
166 | 189 | $name = \stripcslashes(\substr($token[1], 1, -1)); |
167 | 190 | } |
168 | 191 | $value .= $token[1]; |
@@ -171,7 +194,8 @@ discard block |
||
171 | 194 | $value .= $token[1]; |
172 | 195 | break; |
173 | 196 | default: |
174 | - if ($start !== null) { |
|
197 | + if ($start !== null) |
|
198 | + { |
|
175 | 199 | $value .= $token[1]; |
176 | 200 | } |
177 | 201 | } |
@@ -22,24 +22,24 @@ discard block |
||
22 | 22 | { |
23 | 23 | public function __construct( |
24 | 24 | private readonly BlockClaims $blocks |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
29 | 29 | { |
30 | - if (!$node instanceof Aggregate) { |
|
30 | + if (!$node instanceof Aggregate){ |
|
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | |
34 | - foreach ($this->blocks->getUnclaimed() as $name) { |
|
34 | + foreach ($this->blocks->getUnclaimed() as $name){ |
|
35 | 35 | $alias = $node->accepts($name); |
36 | - if ($alias === null) { |
|
36 | + if ($alias === null){ |
|
37 | 37 | continue; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $value = $this->blocks->claim($name); |
41 | 41 | |
42 | - if ($value instanceof QuotedValue) { |
|
42 | + if ($value instanceof QuotedValue){ |
|
43 | 43 | /** |
44 | 44 | * TODO issue #767 |
45 | 45 | * @link https://github.com/spiral/framework/issues/767 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | // simple copy attribute copy |
53 | - if ($value instanceof Attr) { |
|
53 | + if ($value instanceof Attr){ |
|
54 | 54 | /** |
55 | 55 | * TODO issue #767 |
56 | 56 | * @link https://github.com/spiral/framework/issues/767 |
@@ -27,19 +27,23 @@ discard block |
||
27 | 27 | |
28 | 28 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
29 | 29 | { |
30 | - if (!$node instanceof Aggregate) { |
|
30 | + if (!$node instanceof Aggregate) |
|
31 | + { |
|
31 | 32 | return null; |
32 | 33 | } |
33 | 34 | |
34 | - foreach ($this->blocks->getUnclaimed() as $name) { |
|
35 | + foreach ($this->blocks->getUnclaimed() as $name) |
|
36 | + { |
|
35 | 37 | $alias = $node->accepts($name); |
36 | - if ($alias === null) { |
|
38 | + if ($alias === null) |
|
39 | + { |
|
37 | 40 | continue; |
38 | 41 | } |
39 | 42 | |
40 | 43 | $value = $this->blocks->claim($name); |
41 | 44 | |
42 | - if ($value instanceof QuotedValue) { |
|
45 | + if ($value instanceof QuotedValue) |
|
46 | + { |
|
43 | 47 | /** |
44 | 48 | * TODO issue #767 |
45 | 49 | * @link https://github.com/spiral/framework/issues/767 |
@@ -50,7 +54,8 @@ discard block |
||
50 | 54 | } |
51 | 55 | |
52 | 56 | // simple copy attribute copy |
53 | - if ($value instanceof Attr) { |
|
57 | + if ($value instanceof Attr) |
|
58 | + { |
|
54 | 59 | /** |
55 | 60 | * TODO issue #767 |
56 | 61 | * @link https://github.com/spiral/framework/issues/767 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | { |
19 | 19 | public function __construct( |
20 | 20 | private readonly BlockClaims $blocks |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
@@ -28,19 +28,19 @@ discard block |
||
28 | 28 | |
29 | 29 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
30 | 30 | { |
31 | - if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)) { |
|
31 | + if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)){ |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | |
35 | 35 | $inject = $this->blocks->claim($node->name); |
36 | 36 | |
37 | - if ($inject instanceof QuotedValue) { |
|
37 | + if ($inject instanceof QuotedValue){ |
|
38 | 38 | // exclude quotes |
39 | 39 | $inject = $inject->trimValue(); |
40 | 40 | } |
41 | 41 | |
42 | 42 | // mount block:parent content |
43 | - if ($node->name !== 'parent') { |
|
43 | + if ($node->name !== 'parent'){ |
|
44 | 44 | $traverser = new Traverser(); |
45 | 45 | $traverser->addVisitor(new InjectBlocks(new BlockClaims([ |
46 | 46 | 'parent' => $node->nodes, |
@@ -28,19 +28,22 @@ |
||
28 | 28 | |
29 | 29 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
30 | 30 | { |
31 | - if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)) { |
|
31 | + if (!$node instanceof Block || $node->name === null || !$this->blocks->has($node->name)) |
|
32 | + { |
|
32 | 33 | return null; |
33 | 34 | } |
34 | 35 | |
35 | 36 | $inject = $this->blocks->claim($node->name); |
36 | 37 | |
37 | - if ($inject instanceof QuotedValue) { |
|
38 | + if ($inject instanceof QuotedValue) |
|
39 | + { |
|
38 | 40 | // exclude quotes |
39 | 41 | $inject = $inject->trimValue(); |
40 | 42 | } |
41 | 43 | |
42 | 44 | // mount block:parent content |
43 | - if ($node->name !== 'parent') { |
|
45 | + if ($node->name !== 'parent') |
|
46 | + { |
|
44 | 47 | $traverser = new Traverser(); |
45 | 48 | $traverser->addVisitor(new InjectBlocks(new BlockClaims([ |
46 | 49 | 'parent' => $node->nodes, |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | public function __construct( |
28 | 28 | private readonly BlockClaims $blocks |
29 | - ) { |
|
29 | + ){ |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
@@ -37,20 +37,20 @@ discard block |
||
37 | 37 | !\str_contains($node->content, self::PHP_MACRO_FUNCTION) |
38 | 38 | && !\str_contains($node->content, self::PHP_MARCO_EXISTS_FUNCTION) |
39 | 39 | ) |
40 | - ) { |
|
40 | + ){ |
|
41 | 41 | return null; |
42 | 42 | } |
43 | 43 | |
44 | 44 | $php = new PHPMixin($node->tokens, self::PHP_MACRO_FUNCTION); |
45 | - foreach ($this->blocks->getNames() as $name) { |
|
45 | + foreach ($this->blocks->getNames() as $name){ |
|
46 | 46 | $block = $this->blocks->get($name); |
47 | 47 | |
48 | - if ($this->isReference($block)) { |
|
48 | + if ($this->isReference($block)){ |
|
49 | 49 | // resolved on later stage |
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
53 | - if ($php->has($name)) { |
|
53 | + if ($php->has($name)){ |
|
54 | 54 | $php->set($name, $this->trimPHP($this->blocks->claim($name))); |
55 | 55 | } |
56 | 56 | } |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | $node->tokens = \token_get_all($node->content); |
60 | 60 | |
61 | 61 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
62 | - foreach ($this->blocks->getNames() as $name) { |
|
62 | + foreach ($this->blocks->getNames() as $name){ |
|
63 | 63 | $block = $this->blocks->get($name); |
64 | 64 | |
65 | - if ($this->isReference($block)) { |
|
65 | + if ($this->isReference($block)){ |
|
66 | 66 | // resolved on later stage |
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | |
70 | - if ($exists->has($name)) { |
|
70 | + if ($exists->has($name)){ |
|
71 | 71 | $exists->set($name, 'true'); |
72 | 72 | } |
73 | 73 | } |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | |
86 | 86 | private function isReference(mixed $node): bool |
87 | 87 | { |
88 | - switch (true) { |
|
88 | + switch (true){ |
|
89 | 89 | case \is_array($node): |
90 | - foreach ($node as $child) { |
|
91 | - if ($this->isReference($child)) { |
|
90 | + foreach ($node as $child){ |
|
91 | + if ($this->isReference($child)){ |
|
92 | 92 | return true; |
93 | 93 | } |
94 | 94 | } |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | return $this->isReference($node->getValue()); |
100 | 100 | |
101 | 101 | case $node instanceof Mixin: |
102 | - foreach ($node->nodes as $child) { |
|
103 | - if ($this->isReference($child)) { |
|
102 | + foreach ($node->nodes as $child){ |
|
103 | + if ($this->isReference($child)){ |
|
104 | 104 | return true; |
105 | 105 | } |
106 | 106 | } |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | |
117 | 117 | private function trimPHP(mixed $node): string |
118 | 118 | { |
119 | - switch (true) { |
|
119 | + switch (true){ |
|
120 | 120 | case \is_array($node): |
121 | 121 | $result = []; |
122 | - foreach ($node as $child) { |
|
122 | + foreach ($node as $child){ |
|
123 | 123 | $result[] = $this->trimPHP($child); |
124 | 124 | } |
125 | 125 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | |
128 | 128 | case $node instanceof Mixin: |
129 | 129 | $result = []; |
130 | - foreach ($node->nodes as $child) { |
|
130 | + foreach ($node->nodes as $child){ |
|
131 | 131 | $result[] = $this->trimPHP($child); |
132 | 132 | } |
133 | 133 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | return match (true) { |
157 | 157 | \strtolower($value) === 'true' => 'true', |
158 | 158 | \strtolower($value) === 'false' => 'false', |
159 | - \is_float($value) || \is_numeric($value) => (string) $value, |
|
159 | + \is_float($value) || \is_numeric($value) => (string)$value, |
|
160 | 160 | default => \var_export($node->content, true), |
161 | 161 | }; |
162 | 162 | } |
@@ -42,15 +42,18 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | $php = new PHPMixin($node->tokens, self::PHP_MACRO_FUNCTION); |
45 | - foreach ($this->blocks->getNames() as $name) { |
|
45 | + foreach ($this->blocks->getNames() as $name) |
|
46 | + { |
|
46 | 47 | $block = $this->blocks->get($name); |
47 | 48 | |
48 | - if ($this->isReference($block)) { |
|
49 | + if ($this->isReference($block)) |
|
50 | + { |
|
49 | 51 | // resolved on later stage |
50 | 52 | continue; |
51 | 53 | } |
52 | 54 | |
53 | - if ($php->has($name)) { |
|
55 | + if ($php->has($name)) |
|
56 | + { |
|
54 | 57 | $php->set($name, $this->trimPHP($this->blocks->claim($name))); |
55 | 58 | } |
56 | 59 | } |
@@ -59,15 +62,18 @@ discard block |
||
59 | 62 | $node->tokens = \token_get_all($node->content); |
60 | 63 | |
61 | 64 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
62 | - foreach ($this->blocks->getNames() as $name) { |
|
65 | + foreach ($this->blocks->getNames() as $name) |
|
66 | + { |
|
63 | 67 | $block = $this->blocks->get($name); |
64 | 68 | |
65 | - if ($this->isReference($block)) { |
|
69 | + if ($this->isReference($block)) |
|
70 | + { |
|
66 | 71 | // resolved on later stage |
67 | 72 | continue; |
68 | 73 | } |
69 | 74 | |
70 | - if ($exists->has($name)) { |
|
75 | + if ($exists->has($name)) |
|
76 | + { |
|
71 | 77 | $exists->set($name, 'true'); |
72 | 78 | } |
73 | 79 | } |
@@ -85,10 +91,13 @@ discard block |
||
85 | 91 | |
86 | 92 | private function isReference(mixed $node): bool |
87 | 93 | { |
88 | - switch (true) { |
|
94 | + switch (true) |
|
95 | + { |
|
89 | 96 | case \is_array($node): |
90 | - foreach ($node as $child) { |
|
91 | - if ($this->isReference($child)) { |
|
97 | + foreach ($node as $child) |
|
98 | + { |
|
99 | + if ($this->isReference($child)) |
|
100 | + { |
|
92 | 101 | return true; |
93 | 102 | } |
94 | 103 | } |
@@ -99,8 +108,10 @@ discard block |
||
99 | 108 | return $this->isReference($node->getValue()); |
100 | 109 | |
101 | 110 | case $node instanceof Mixin: |
102 | - foreach ($node->nodes as $child) { |
|
103 | - if ($this->isReference($child)) { |
|
111 | + foreach ($node->nodes as $child) |
|
112 | + { |
|
113 | + if ($this->isReference($child)) |
|
114 | + { |
|
104 | 115 | return true; |
105 | 116 | } |
106 | 117 | } |
@@ -116,10 +127,12 @@ discard block |
||
116 | 127 | |
117 | 128 | private function trimPHP(mixed $node): string |
118 | 129 | { |
119 | - switch (true) { |
|
130 | + switch (true) |
|
131 | + { |
|
120 | 132 | case \is_array($node): |
121 | 133 | $result = []; |
122 | - foreach ($node as $child) { |
|
134 | + foreach ($node as $child) |
|
135 | + { |
|
123 | 136 | $result[] = $this->trimPHP($child); |
124 | 137 | } |
125 | 138 | |
@@ -127,7 +140,8 @@ discard block |
||
127 | 140 | |
128 | 141 | case $node instanceof Mixin: |
129 | 142 | $result = []; |
130 | - foreach ($node->nodes as $child) { |
|
143 | + foreach ($node->nodes as $child) |
|
144 | + { |
|
131 | 145 | $result[] = $this->trimPHP($child); |
132 | 146 | } |
133 | 147 |
@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | public function __construct( |
28 | 28 | private readonly Builder $builder, |
29 | 29 | private readonly Merger $merger = new Merger() |
30 | - ) { |
|
30 | + ){ |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
34 | 34 | { |
35 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)) { |
|
35 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)){ |
|
36 | 36 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
37 | 37 | } |
38 | 38 | |
@@ -41,23 +41,23 @@ discard block |
||
41 | 41 | |
42 | 42 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
43 | 43 | { |
44 | - if (!$node instanceof Tag) { |
|
44 | + if (!$node instanceof Tag){ |
|
45 | 45 | return null; |
46 | 46 | } |
47 | 47 | |
48 | 48 | $importCtx = ImportContext::on($ctx); |
49 | 49 | |
50 | 50 | // import definition |
51 | - if (\str_starts_with($node->name, $this->useKeyword)) { |
|
51 | + if (\str_starts_with($node->name, $this->useKeyword)){ |
|
52 | 52 | $importCtx->add($this->makeImport($node)); |
53 | 53 | |
54 | 54 | return self::REMOVE_NODE; |
55 | 55 | } |
56 | 56 | |
57 | 57 | // imported tag |
58 | - try { |
|
58 | + try{ |
|
59 | 59 | $import = $importCtx->resolve($this->builder, $node->name); |
60 | - } catch (\Throwable $e) { |
|
60 | + }catch (\Throwable $e){ |
|
61 | 61 | throw new ImportException( |
62 | 62 | \sprintf('Unable to resolve import `%s`', $node->name), |
63 | 63 | $node->getContext(), |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - if ($import !== null) { |
|
68 | + if ($import !== null){ |
|
69 | 69 | $node = $this->merger->merge($import, $node); |
70 | 70 | |
71 | 71 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | private function makeImport(Tag $tag): ImportInterface |
82 | 82 | { |
83 | 83 | $options = []; |
84 | - foreach ($tag->attrs as $attr) { |
|
85 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
84 | + foreach ($tag->attrs as $attr){ |
|
85 | + if (!\is_string($attr->value) || !\is_string($attr->name)){ |
|
86 | 86 | continue; |
87 | 87 | } |
88 | 88 | $options[$attr->name] = \trim($attr->value, '\'"'); |
89 | 89 | } |
90 | 90 | |
91 | - switch (\strtolower($tag->name)) { |
|
91 | + switch (\strtolower($tag->name)){ |
|
92 | 92 | case 'use': |
93 | 93 | case 'use:element': |
94 | 94 | $this->assertHasOption('path', $options, $tag); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | private function assertHasOption(string $option, array $options, Tag $tag): void |
136 | 136 | { |
137 | - if (!isset($options[$option])) { |
|
137 | + if (!isset($options[$option])){ |
|
138 | 138 | throw new ImportException(\sprintf('Missing `%s` option', $option), $tag->getContext()); |
139 | 139 | } |
140 | 140 | } |
@@ -32,7 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
34 | 34 | { |
35 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)) { |
|
35 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)) |
|
36 | + { |
|
36 | 37 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
37 | 38 | } |
38 | 39 | |
@@ -41,23 +42,28 @@ discard block |
||
41 | 42 | |
42 | 43 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
43 | 44 | { |
44 | - if (!$node instanceof Tag) { |
|
45 | + if (!$node instanceof Tag) |
|
46 | + { |
|
45 | 47 | return null; |
46 | 48 | } |
47 | 49 | |
48 | 50 | $importCtx = ImportContext::on($ctx); |
49 | 51 | |
50 | 52 | // import definition |
51 | - if (\str_starts_with($node->name, $this->useKeyword)) { |
|
53 | + if (\str_starts_with($node->name, $this->useKeyword)) |
|
54 | + { |
|
52 | 55 | $importCtx->add($this->makeImport($node)); |
53 | 56 | |
54 | 57 | return self::REMOVE_NODE; |
55 | 58 | } |
56 | 59 | |
57 | 60 | // imported tag |
58 | - try { |
|
61 | + try |
|
62 | + { |
|
59 | 63 | $import = $importCtx->resolve($this->builder, $node->name); |
60 | - } catch (\Throwable $e) { |
|
64 | + } |
|
65 | + catch (\Throwable $e) |
|
66 | + { |
|
61 | 67 | throw new ImportException( |
62 | 68 | \sprintf('Unable to resolve import `%s`', $node->name), |
63 | 69 | $node->getContext(), |
@@ -65,7 +71,8 @@ discard block |
||
65 | 71 | ); |
66 | 72 | } |
67 | 73 | |
68 | - if ($import !== null) { |
|
74 | + if ($import !== null) |
|
75 | + { |
|
69 | 76 | $node = $this->merger->merge($import, $node); |
70 | 77 | |
71 | 78 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -81,14 +88,17 @@ discard block |
||
81 | 88 | private function makeImport(Tag $tag): ImportInterface |
82 | 89 | { |
83 | 90 | $options = []; |
84 | - foreach ($tag->attrs as $attr) { |
|
85 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
91 | + foreach ($tag->attrs as $attr) |
|
92 | + { |
|
93 | + if (!\is_string($attr->value) || !\is_string($attr->name)) |
|
94 | + { |
|
86 | 95 | continue; |
87 | 96 | } |
88 | 97 | $options[$attr->name] = \trim($attr->value, '\'"'); |
89 | 98 | } |
90 | 99 | |
91 | - switch (\strtolower($tag->name)) { |
|
100 | + switch (\strtolower($tag->name)) |
|
101 | + { |
|
92 | 102 | case 'use': |
93 | 103 | case 'use:element': |
94 | 104 | $this->assertHasOption('path', $options, $tag); |
@@ -134,7 +144,8 @@ discard block |
||
134 | 144 | |
135 | 145 | private function assertHasOption(string $option, array $options, Tag $tag): void |
136 | 146 | { |
137 | - if (!isset($options[$option])) { |
|
147 | + if (!isset($options[$option])) |
|
148 | + { |
|
138 | 149 | throw new ImportException(\sprintf('Missing `%s` option', $option), $tag->getContext()); |
139 | 150 | } |
140 | 151 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | public function __construct( |
16 | 16 | private readonly array $blocks |
17 | - ) { |
|
17 | + ){ |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function has(string $name): bool |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | { |
24 | 24 | $blocks = [self::CONTEXT_KEY => []]; |
25 | 25 | |
26 | - foreach ($caller->attrs as $attr) { |
|
27 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
26 | + foreach ($caller->attrs as $attr){ |
|
27 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface){ |
|
28 | 28 | // ignore name when attribute is dynamic |
29 | 29 | $blocks[\sprintf('attr-%s', \count($blocks))] = $attr; |
30 | 30 | continue; |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | |
40 | - foreach ($caller->nodes as $node) { |
|
41 | - if ($node instanceof Block) { |
|
40 | + foreach ($caller->nodes as $node){ |
|
41 | + if ($node instanceof Block){ |
|
42 | 42 | $blocks[$node->name] = $node->nodes; |
43 | - } else { |
|
43 | + }else{ |
|
44 | 44 | \assert( |
45 | 45 | \is_array($blocks[self::CONTEXT_KEY]) || $blocks[self::CONTEXT_KEY] instanceof \ArrayAccess |
46 | 46 | ); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - if ($blocks[self::CONTEXT_KEY] === []) { |
|
52 | + if ($blocks[self::CONTEXT_KEY] === []){ |
|
53 | 53 | unset($blocks[self::CONTEXT_KEY]); |
54 | 54 | } |
55 | 55 |
@@ -23,8 +23,10 @@ discard block |
||
23 | 23 | { |
24 | 24 | $blocks = [self::CONTEXT_KEY => []]; |
25 | 25 | |
26 | - foreach ($caller->attrs as $attr) { |
|
27 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
26 | + foreach ($caller->attrs as $attr) |
|
27 | + { |
|
28 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) |
|
29 | + { |
|
28 | 30 | // ignore name when attribute is dynamic |
29 | 31 | $blocks[\sprintf('attr-%s', \count($blocks))] = $attr; |
30 | 32 | continue; |
@@ -37,10 +39,14 @@ discard block |
||
37 | 39 | } |
38 | 40 | |
39 | 41 | |
40 | - foreach ($caller->nodes as $node) { |
|
41 | - if ($node instanceof Block) { |
|
42 | + foreach ($caller->nodes as $node) |
|
43 | + { |
|
44 | + if ($node instanceof Block) |
|
45 | + { |
|
42 | 46 | $blocks[$node->name] = $node->nodes; |
43 | - } else { |
|
47 | + } |
|
48 | + else |
|
49 | + { |
|
44 | 50 | \assert( |
45 | 51 | \is_array($blocks[self::CONTEXT_KEY]) || $blocks[self::CONTEXT_KEY] instanceof \ArrayAccess |
46 | 52 | ); |
@@ -49,7 +55,8 @@ discard block |
||
49 | 55 | } |
50 | 56 | } |
51 | 57 | |
52 | - if ($blocks[self::CONTEXT_KEY] === []) { |
|
58 | + if ($blocks[self::CONTEXT_KEY] === []) |
|
59 | + { |
|
53 | 60 | unset($blocks[self::CONTEXT_KEY]); |
54 | 61 | } |
55 | 62 |
@@ -20,15 +20,15 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
23 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE){ |
|
24 | 24 | return null; |
25 | 25 | } |
26 | 26 | |
27 | - if ($node->value instanceof Nil) { |
|
27 | + if ($node->value instanceof Nil){ |
|
28 | 28 | return new Aggregate($node->getContext()); |
29 | 29 | } |
30 | 30 | |
31 | - if (!\is_string($node->value)) { |
|
31 | + if (!\is_string($node->value)){ |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 |
@@ -20,15 +20,18 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
23 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) |
|
24 | + { |
|
24 | 25 | return null; |
25 | 26 | } |
26 | 27 | |
27 | - if ($node->value instanceof Nil) { |
|
28 | + if ($node->value instanceof Nil) |
|
29 | + { |
|
28 | 30 | return new Aggregate($node->getContext()); |
29 | 31 | } |
30 | 32 | |
31 | - if (!\is_string($node->value)) { |
|
33 | + if (!\is_string($node->value)) |
|
34 | + { |
|
32 | 35 | return null; |
33 | 36 | } |
34 | 37 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
21 | 21 | { |
22 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) { |
|
22 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)){ |
|
23 | 23 | return $this->registerAggregate(StackContext::on($ctx), $node); |
24 | 24 | } |
25 | 25 | |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | |
34 | - private function registerAggregate(StackContext $ctx, Tag $node): Aggregate|Tag |
|
34 | + private function registerAggregate(StackContext $ctx, Tag $node): Aggregate | Tag |
|
35 | 35 | { |
36 | 36 | $name = $this->stackName($node); |
37 | - if ($name === null) { |
|
37 | + if ($name === null){ |
|
38 | 38 | return $node; |
39 | 39 | } |
40 | 40 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | private function stackName(Tag $tag): ?string |
51 | 51 | { |
52 | 52 | $options = []; |
53 | - foreach ($tag->attrs as $attr) { |
|
54 | - if (\is_string($attr->value)) { |
|
53 | + foreach ($tag->attrs as $attr){ |
|
54 | + if (\is_string($attr->value)){ |
|
55 | 55 | $options[$attr->name] = \trim($attr->value, '\'"'); |
56 | 56 | } |
57 | 57 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | private function stackLevel(Tag $tag): int |
63 | 63 | { |
64 | 64 | $options = []; |
65 | - foreach ($tag->attrs as $attr) { |
|
66 | - if (\is_string($attr->value)) { |
|
65 | + foreach ($tag->attrs as $attr){ |
|
66 | + if (\is_string($attr->value)){ |
|
67 | 67 | $options[$attr->name] = \trim($attr->value, '\'"'); |
68 | 68 | } |
69 | 69 | } |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | |
20 | 20 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
21 | 21 | { |
22 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) { |
|
22 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) |
|
23 | + { |
|
23 | 24 | return $this->registerAggregate(StackContext::on($ctx), $node); |
24 | 25 | } |
25 | 26 | |
@@ -34,7 +35,8 @@ discard block |
||
34 | 35 | private function registerAggregate(StackContext $ctx, Tag $node): Aggregate|Tag |
35 | 36 | { |
36 | 37 | $name = $this->stackName($node); |
37 | - if ($name === null) { |
|
38 | + if ($name === null) |
|
39 | + { |
|
38 | 40 | return $node; |
39 | 41 | } |
40 | 42 | |
@@ -50,8 +52,10 @@ discard block |
||
50 | 52 | private function stackName(Tag $tag): ?string |
51 | 53 | { |
52 | 54 | $options = []; |
53 | - foreach ($tag->attrs as $attr) { |
|
54 | - if (\is_string($attr->value)) { |
|
55 | + foreach ($tag->attrs as $attr) |
|
56 | + { |
|
57 | + if (\is_string($attr->value)) |
|
58 | + { |
|
55 | 59 | $options[$attr->name] = \trim($attr->value, '\'"'); |
56 | 60 | } |
57 | 61 | } |
@@ -62,8 +66,10 @@ discard block |
||
62 | 66 | private function stackLevel(Tag $tag): int |
63 | 67 | { |
64 | 68 | $options = []; |
65 | - foreach ($tag->attrs as $attr) { |
|
66 | - if (\is_string($attr->value)) { |
|
69 | + foreach ($tag->attrs as $attr) |
|
70 | + { |
|
71 | + if (\is_string($attr->value)) |
|
72 | + { |
|
67 | 73 | $options[$attr->name] = \trim($attr->value, '\'"'); |
68 | 74 | } |
69 | 75 | } |