@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | |
39 | 39 | public function parse(Buffer $src): \Generator |
40 | 40 | { |
41 | - while ($n = $src->next()) { |
|
42 | - if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{') { |
|
41 | + while ($n = $src->next()){ |
|
42 | + if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{'){ |
|
43 | 43 | yield $n; |
44 | 44 | continue; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $binding = (clone $this)->parseGrammar($src, $n->offset); |
48 | - if ($binding === null) { |
|
48 | + if ($binding === null){ |
|
49 | 49 | yield $n; |
50 | 50 | $src->replay($n->offset); |
51 | 51 | continue; |
@@ -80,27 +80,27 @@ discard block |
||
80 | 80 | private function parseGrammar(Buffer $src, int $offset): ?array |
81 | 81 | { |
82 | 82 | $this->tokens = [ |
83 | - new Token(self::TYPE_OPEN_TAG, $offset, '$' . $src->next()->char), |
|
83 | + new Token(self::TYPE_OPEN_TAG, $offset, '$'.$src->next()->char), |
|
84 | 84 | ]; |
85 | 85 | |
86 | - while ($n = $src->next()) { |
|
87 | - if (!$n instanceof Byte) { |
|
86 | + while ($n = $src->next()){ |
|
87 | + if (!$n instanceof Byte){ |
|
88 | 88 | // no other grammars are allowed |
89 | 89 | return null; |
90 | 90 | } |
91 | 91 | |
92 | - switch ($n->char) { |
|
92 | + switch ($n->char){ |
|
93 | 93 | case '"': |
94 | 94 | case "'": |
95 | - if ($this->default === null) { |
|
95 | + if ($this->default === null){ |
|
96 | 96 | // " and ' not allowed in names |
97 | 97 | return null; |
98 | 98 | } |
99 | 99 | |
100 | 100 | $this->default[] = $n; |
101 | - while ($nn = $src->next()) { |
|
101 | + while ($nn = $src->next()){ |
|
102 | 102 | $this->default[] = $nn; |
103 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
103 | + if ($nn instanceof Byte && $nn->char === $n->char){ |
|
104 | 104 | break; |
105 | 105 | } |
106 | 106 | } |
@@ -133,17 +133,17 @@ discard block |
||
133 | 133 | break; |
134 | 134 | |
135 | 135 | default: |
136 | - if ($this->default !== null) { |
|
136 | + if ($this->default !== null){ |
|
137 | 137 | // default allows spaces |
138 | 138 | $this->default[] = $n; |
139 | 139 | break; |
140 | 140 | } |
141 | 141 | |
142 | - if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
142 | + if (\preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
143 | 143 | break; |
144 | 144 | } |
145 | 145 | |
146 | - if (\preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
146 | + if (\preg_match(self::REGEXP_KEYWORD, $n->char)){ |
|
147 | 147 | $this->name[] = $n; |
148 | 148 | break; |
149 | 149 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | - if (!$this->isValid()) { |
|
155 | + if (!$this->isValid()){ |
|
156 | 156 | return null; |
157 | 157 | } |
158 | 158 | |
@@ -161,25 +161,25 @@ discard block |
||
161 | 161 | |
162 | 162 | private function isValid(): bool |
163 | 163 | { |
164 | - if (\count($this->tokens) < 3) { |
|
164 | + if (\count($this->tokens) < 3){ |
|
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | 168 | $hasName = false; |
169 | 169 | $hasDefault = null; |
170 | - foreach ($this->tokens as $token) { |
|
171 | - if ($token->type === self::TYPE_NAME) { |
|
170 | + foreach ($this->tokens as $token){ |
|
171 | + if ($token->type === self::TYPE_NAME){ |
|
172 | 172 | $hasName = true; |
173 | 173 | continue; |
174 | 174 | } |
175 | 175 | |
176 | - if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null) { |
|
176 | + if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null){ |
|
177 | 177 | $hasDefault = false; |
178 | 178 | continue; |
179 | 179 | } |
180 | 180 | |
181 | - if ($token->type === self::TYPE_DEFAULT) { |
|
182 | - if ($hasDefault === true) { |
|
181 | + if ($token->type === self::TYPE_DEFAULT){ |
|
182 | + if ($hasDefault === true){ |
|
183 | 183 | // multiple default value |
184 | 184 | return false; |
185 | 185 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function flushName(): void |
198 | 198 | { |
199 | - if ($this->name === []) { |
|
199 | + if ($this->name === []){ |
|
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | private function flushDefault(): void |
211 | 211 | { |
212 | - if ($this->default === [] || $this->default === null) { |
|
212 | + if ($this->default === [] || $this->default === null){ |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 |
@@ -38,14 +38,17 @@ discard block |
||
38 | 38 | |
39 | 39 | public function parse(Buffer $src): \Generator |
40 | 40 | { |
41 | - while ($n = $src->next()) { |
|
42 | - if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{') { |
|
41 | + while ($n = $src->next()) |
|
42 | + { |
|
43 | + if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{') |
|
44 | + { |
|
43 | 45 | yield $n; |
44 | 46 | continue; |
45 | 47 | } |
46 | 48 | |
47 | 49 | $binding = (clone $this)->parseGrammar($src, $n->offset); |
48 | - if ($binding === null) { |
|
50 | + if ($binding === null) |
|
51 | + { |
|
49 | 52 | yield $n; |
50 | 53 | $src->replay($n->offset); |
51 | 54 | continue; |
@@ -83,24 +86,30 @@ discard block |
||
83 | 86 | new Token(self::TYPE_OPEN_TAG, $offset, '$' . $src->next()->char), |
84 | 87 | ]; |
85 | 88 | |
86 | - while ($n = $src->next()) { |
|
87 | - if (!$n instanceof Byte) { |
|
89 | + while ($n = $src->next()) |
|
90 | + { |
|
91 | + if (!$n instanceof Byte) |
|
92 | + { |
|
88 | 93 | // no other grammars are allowed |
89 | 94 | return null; |
90 | 95 | } |
91 | 96 | |
92 | - switch ($n->char) { |
|
97 | + switch ($n->char) |
|
98 | + { |
|
93 | 99 | case '"': |
94 | 100 | case "'": |
95 | - if ($this->default === null) { |
|
101 | + if ($this->default === null) |
|
102 | + { |
|
96 | 103 | // " and ' not allowed in names |
97 | 104 | return null; |
98 | 105 | } |
99 | 106 | |
100 | 107 | $this->default[] = $n; |
101 | - while ($nn = $src->next()) { |
|
108 | + while ($nn = $src->next()) |
|
109 | + { |
|
102 | 110 | $this->default[] = $nn; |
103 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
111 | + if ($nn instanceof Byte && $nn->char === $n->char) |
|
112 | + { |
|
104 | 113 | break; |
105 | 114 | } |
106 | 115 | } |
@@ -133,17 +142,20 @@ discard block |
||
133 | 142 | break; |
134 | 143 | |
135 | 144 | default: |
136 | - if ($this->default !== null) { |
|
145 | + if ($this->default !== null) |
|
146 | + { |
|
137 | 147 | // default allows spaces |
138 | 148 | $this->default[] = $n; |
139 | 149 | break; |
140 | 150 | } |
141 | 151 | |
142 | - if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
152 | + if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
153 | + { |
|
143 | 154 | break; |
144 | 155 | } |
145 | 156 | |
146 | - if (\preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
157 | + if (\preg_match(self::REGEXP_KEYWORD, $n->char)) |
|
158 | + { |
|
147 | 159 | $this->name[] = $n; |
148 | 160 | break; |
149 | 161 | } |
@@ -152,7 +164,8 @@ discard block |
||
152 | 164 | } |
153 | 165 | } |
154 | 166 | |
155 | - if (!$this->isValid()) { |
|
167 | + if (!$this->isValid()) |
|
168 | + { |
|
156 | 169 | return null; |
157 | 170 | } |
158 | 171 | |
@@ -161,25 +174,31 @@ discard block |
||
161 | 174 | |
162 | 175 | private function isValid(): bool |
163 | 176 | { |
164 | - if (\count($this->tokens) < 3) { |
|
177 | + if (\count($this->tokens) < 3) |
|
178 | + { |
|
165 | 179 | return false; |
166 | 180 | } |
167 | 181 | |
168 | 182 | $hasName = false; |
169 | 183 | $hasDefault = null; |
170 | - foreach ($this->tokens as $token) { |
|
171 | - if ($token->type === self::TYPE_NAME) { |
|
184 | + foreach ($this->tokens as $token) |
|
185 | + { |
|
186 | + if ($token->type === self::TYPE_NAME) |
|
187 | + { |
|
172 | 188 | $hasName = true; |
173 | 189 | continue; |
174 | 190 | } |
175 | 191 | |
176 | - if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null) { |
|
192 | + if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null) |
|
193 | + { |
|
177 | 194 | $hasDefault = false; |
178 | 195 | continue; |
179 | 196 | } |
180 | 197 | |
181 | - if ($token->type === self::TYPE_DEFAULT) { |
|
182 | - if ($hasDefault === true) { |
|
198 | + if ($token->type === self::TYPE_DEFAULT) |
|
199 | + { |
|
200 | + if ($hasDefault === true) |
|
201 | + { |
|
183 | 202 | // multiple default value |
184 | 203 | return false; |
185 | 204 | } |
@@ -196,7 +215,8 @@ discard block |
||
196 | 215 | */ |
197 | 216 | private function flushName(): void |
198 | 217 | { |
199 | - if ($this->name === []) { |
|
218 | + if ($this->name === []) |
|
219 | + { |
|
200 | 220 | return; |
201 | 221 | } |
202 | 222 | |
@@ -209,7 +229,8 @@ discard block |
||
209 | 229 | */ |
210 | 230 | private function flushDefault(): void |
211 | 231 | { |
212 | - if ($this->default === [] || $this->default === null) { |
|
232 | + if ($this->default === [] || $this->default === null) |
|
233 | + { |
|
213 | 234 | return; |
214 | 235 | } |
215 | 236 |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | |
17 | 17 | public function parse(Buffer $src): \Generator |
18 | 18 | { |
19 | - while ($n = $src->next()) { |
|
20 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
19 | + while ($n = $src->next()){ |
|
20 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?'){ |
|
21 | 21 | yield $n; |
22 | 22 | continue; |
23 | 23 | } |
24 | 24 | |
25 | - $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
|
26 | - if ($php === null) { |
|
25 | + $php = $this->parseGrammar($n->char.$src->nextBytes(), $n->offset); |
|
26 | + if ($php === null){ |
|
27 | 27 | yield $n; |
28 | 28 | $src->replay($n->offset); |
29 | 29 | continue; |
@@ -45,25 +45,25 @@ discard block |
||
45 | 45 | private function parseGrammar(string $content, int $offset): ?Token |
46 | 46 | { |
47 | 47 | $tokens = null; |
48 | - foreach (\token_get_all($content) as $token) { |
|
49 | - if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
48 | + foreach (\token_get_all($content) as $token){ |
|
49 | + if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])){ |
|
50 | 50 | // not php |
51 | 51 | return null; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $tokens[] = $token; |
55 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
55 | + if ($this->is($token, [T_CLOSE_TAG])){ |
|
56 | 56 | break; |
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | - if ($tokens === null) { |
|
60 | + if ($tokens === null){ |
|
61 | 61 | return null; |
62 | 62 | } |
63 | 63 | |
64 | 64 | $buffer = ''; |
65 | - foreach ($tokens as $token) { |
|
66 | - if (!\is_array($token)) { |
|
65 | + foreach ($tokens as $token){ |
|
66 | + if (!\is_array($token)){ |
|
67 | 67 | $buffer .= $token; |
68 | 68 | continue; |
69 | 69 | } |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | return $token; |
77 | 77 | } |
78 | 78 | |
79 | - private function is(array|string $token, array $type): bool |
|
79 | + private function is(array | string $token, array $type): bool |
|
80 | 80 | { |
81 | - if (!\is_array($token)) { |
|
81 | + if (!\is_array($token)){ |
|
82 | 82 | return false; |
83 | 83 | } |
84 | 84 |
@@ -16,14 +16,17 @@ discard block |
||
16 | 16 | |
17 | 17 | public function parse(Buffer $src): \Generator |
18 | 18 | { |
19 | - while ($n = $src->next()) { |
|
20 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
19 | + while ($n = $src->next()) |
|
20 | + { |
|
21 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') |
|
22 | + { |
|
21 | 23 | yield $n; |
22 | 24 | continue; |
23 | 25 | } |
24 | 26 | |
25 | 27 | $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
26 | - if ($php === null) { |
|
28 | + if ($php === null) |
|
29 | + { |
|
27 | 30 | yield $n; |
28 | 31 | $src->replay($n->offset); |
29 | 32 | continue; |
@@ -45,25 +48,31 @@ discard block |
||
45 | 48 | private function parseGrammar(string $content, int $offset): ?Token |
46 | 49 | { |
47 | 50 | $tokens = null; |
48 | - foreach (\token_get_all($content) as $token) { |
|
49 | - if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
51 | + foreach (\token_get_all($content) as $token) |
|
52 | + { |
|
53 | + if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) |
|
54 | + { |
|
50 | 55 | // not php |
51 | 56 | return null; |
52 | 57 | } |
53 | 58 | |
54 | 59 | $tokens[] = $token; |
55 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
60 | + if ($this->is($token, [T_CLOSE_TAG])) |
|
61 | + { |
|
56 | 62 | break; |
57 | 63 | } |
58 | 64 | } |
59 | 65 | |
60 | - if ($tokens === null) { |
|
66 | + if ($tokens === null) |
|
67 | + { |
|
61 | 68 | return null; |
62 | 69 | } |
63 | 70 | |
64 | 71 | $buffer = ''; |
65 | - foreach ($tokens as $token) { |
|
66 | - if (!\is_array($token)) { |
|
72 | + foreach ($tokens as $token) |
|
73 | + { |
|
74 | + if (!\is_array($token)) |
|
75 | + { |
|
67 | 76 | $buffer .= $token; |
68 | 77 | continue; |
69 | 78 | } |
@@ -78,7 +87,8 @@ discard block |
||
78 | 87 | |
79 | 88 | private function is(array|string $token, array $type): bool |
80 | 89 | { |
81 | - if (!\is_array($token)) { |
|
90 | + if (!\is_array($token)) |
|
91 | + { |
|
82 | 92 | return false; |
83 | 93 | } |
84 | 94 |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | public function parse(StreamInterface $src): \Generator |
32 | 32 | { |
33 | 33 | $stream = new Buffer($this->generate($src)); |
34 | - foreach ($this->grammars as $grammar) { |
|
34 | + foreach ($this->grammars as $grammar){ |
|
35 | 35 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
36 | 36 | } |
37 | 37 | |
38 | 38 | // always group raw bytes into raw tokens |
39 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
39 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n){ |
|
40 | 40 | yield $n; |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator |
45 | 45 | { |
46 | - foreach ($grammar->parse($stream) as $n) { |
|
47 | - if ($n instanceof Token && $n->grammar === null) { |
|
46 | + foreach ($grammar->parse($stream) as $n){ |
|
47 | + if ($n instanceof Token && $n->grammar === null){ |
|
48 | 48 | $n->grammar = $grammar::class; |
49 | 49 | } |
50 | 50 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | private function generate(StreamInterface $src): \Generator |
61 | 61 | { |
62 | - while (!$src->isEOI()) { |
|
62 | + while (!$src->isEOI()){ |
|
63 | 63 | yield new Byte($src->getOffset(), $src->peak()); |
64 | 64 | } |
65 | 65 | } |
@@ -31,20 +31,24 @@ discard block |
||
31 | 31 | public function parse(StreamInterface $src): \Generator |
32 | 32 | { |
33 | 33 | $stream = new Buffer($this->generate($src)); |
34 | - foreach ($this->grammars as $grammar) { |
|
34 | + foreach ($this->grammars as $grammar) |
|
35 | + { |
|
35 | 36 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
36 | 37 | } |
37 | 38 | |
38 | 39 | // always group raw bytes into raw tokens |
39 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
40 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n) |
|
41 | + { |
|
40 | 42 | yield $n; |
41 | 43 | } |
42 | 44 | } |
43 | 45 | |
44 | 46 | private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator |
45 | 47 | { |
46 | - foreach ($grammar->parse($stream) as $n) { |
|
47 | - if ($n instanceof Token && $n->grammar === null) { |
|
48 | + foreach ($grammar->parse($stream) as $n) |
|
49 | + { |
|
50 | + if ($n instanceof Token && $n->grammar === null) |
|
51 | + { |
|
48 | 52 | $n->grammar = $grammar::class; |
49 | 53 | } |
50 | 54 | |
@@ -59,7 +63,8 @@ discard block |
||
59 | 63 | */ |
60 | 64 | private function generate(StreamInterface $src): \Generator |
61 | 65 | { |
62 | - while (!$src->isEOI()) { |
|
66 | + while (!$src->isEOI()) |
|
67 | + { |
|
63 | 68 | yield new Byte($src->getOffset(), $src->peak()); |
64 | 69 | } |
65 | 70 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | { |
14 | 14 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
15 | 15 | { |
16 | - if ($node instanceof PHP) { |
|
16 | + if ($node instanceof PHP){ |
|
17 | 17 | $result->push($node->content, $node->getContext()); |
18 | 18 | return true; |
19 | 19 | } |
@@ -13,7 +13,8 @@ |
||
13 | 13 | { |
14 | 14 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
15 | 15 | { |
16 | - if ($node instanceof PHP) { |
|
16 | + if ($node instanceof PHP) |
|
17 | + { |
|
17 | 18 | $result->push($node->content, $node->getContext()); |
18 | 19 | return true; |
19 | 20 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | { |
17 | 17 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
18 | 18 | { |
19 | - switch (true) { |
|
19 | + switch (true){ |
|
20 | 20 | case $node instanceof Tag: |
21 | 21 | $this->tag($compiler, $result, $node); |
22 | 22 | return true; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | { |
39 | 39 | $result->push(\sprintf('<%s', $node->name), $node->getContext()); |
40 | 40 | |
41 | - foreach ($node->attrs as $attr) { |
|
42 | - if (!$attr instanceof Attr) { |
|
41 | + foreach ($node->attrs as $attr){ |
|
42 | + if (!$attr instanceof Attr){ |
|
43 | 43 | $compiler->compile($attr, $result); |
44 | 44 | continue; |
45 | 45 | } |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | |
50 | 50 | $result->push(\sprintf('%s>', $node->void ? '/' : ''), null); |
51 | 51 | |
52 | - foreach ($node->nodes as $child) { |
|
52 | + foreach ($node->nodes as $child){ |
|
53 | 53 | $compiler->compile($child, $result); |
54 | 54 | } |
55 | 55 | |
56 | - if (!$node->void) { |
|
56 | + if (!$node->void){ |
|
57 | 57 | $result->push(\sprintf('</%s>', $node->name), null); |
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | private function attribute(Compiler $compiler, Compiler\Result $result, Attr $node): void |
62 | 62 | { |
63 | - if ($node->name instanceof NodeInterface) { |
|
63 | + if ($node->name instanceof NodeInterface){ |
|
64 | 64 | $result->push(' ', null); |
65 | 65 | $compiler->compile($node->name, $result); |
66 | - } else { |
|
66 | + }else{ |
|
67 | 67 | $result->push(\sprintf(' %s', $node->name), $node->getContext()); |
68 | 68 | } |
69 | 69 | |
70 | 70 | $value = $node->value; |
71 | - if ($value instanceof Nil) { |
|
71 | + if ($value instanceof Nil){ |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | - if ($value instanceof NodeInterface) { |
|
75 | + if ($value instanceof NodeInterface){ |
|
76 | 76 | $result->push('=', null); |
77 | 77 | $compiler->compile($value, $result); |
78 | 78 | return; |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | |
84 | 84 | private function verbatim(Compiler $compiler, Compiler\Result $result, Verbatim $node): void |
85 | 85 | { |
86 | - foreach ($node->nodes as $child) { |
|
87 | - if (\is_string($child)) { |
|
86 | + foreach ($node->nodes as $child){ |
|
87 | + if (\is_string($child)){ |
|
88 | 88 | $result->push($child, null); |
89 | 89 | continue; |
90 | 90 | } |
@@ -16,7 +16,8 @@ discard block |
||
16 | 16 | { |
17 | 17 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
18 | 18 | { |
19 | - switch (true) { |
|
19 | + switch (true) |
|
20 | + { |
|
20 | 21 | case $node instanceof Tag: |
21 | 22 | $this->tag($compiler, $result, $node); |
22 | 23 | return true; |
@@ -38,8 +39,10 @@ discard block |
||
38 | 39 | { |
39 | 40 | $result->push(\sprintf('<%s', $node->name), $node->getContext()); |
40 | 41 | |
41 | - foreach ($node->attrs as $attr) { |
|
42 | - if (!$attr instanceof Attr) { |
|
42 | + foreach ($node->attrs as $attr) |
|
43 | + { |
|
44 | + if (!$attr instanceof Attr) |
|
45 | + { |
|
43 | 46 | $compiler->compile($attr, $result); |
44 | 47 | continue; |
45 | 48 | } |
@@ -49,30 +52,37 @@ discard block |
||
49 | 52 | |
50 | 53 | $result->push(\sprintf('%s>', $node->void ? '/' : ''), null); |
51 | 54 | |
52 | - foreach ($node->nodes as $child) { |
|
55 | + foreach ($node->nodes as $child) |
|
56 | + { |
|
53 | 57 | $compiler->compile($child, $result); |
54 | 58 | } |
55 | 59 | |
56 | - if (!$node->void) { |
|
60 | + if (!$node->void) |
|
61 | + { |
|
57 | 62 | $result->push(\sprintf('</%s>', $node->name), null); |
58 | 63 | } |
59 | 64 | } |
60 | 65 | |
61 | 66 | private function attribute(Compiler $compiler, Compiler\Result $result, Attr $node): void |
62 | 67 | { |
63 | - if ($node->name instanceof NodeInterface) { |
|
68 | + if ($node->name instanceof NodeInterface) |
|
69 | + { |
|
64 | 70 | $result->push(' ', null); |
65 | 71 | $compiler->compile($node->name, $result); |
66 | - } else { |
|
72 | + } |
|
73 | + else |
|
74 | + { |
|
67 | 75 | $result->push(\sprintf(' %s', $node->name), $node->getContext()); |
68 | 76 | } |
69 | 77 | |
70 | 78 | $value = $node->value; |
71 | - if ($value instanceof Nil) { |
|
79 | + if ($value instanceof Nil) |
|
80 | + { |
|
72 | 81 | return; |
73 | 82 | } |
74 | 83 | |
75 | - if ($value instanceof NodeInterface) { |
|
84 | + if ($value instanceof NodeInterface) |
|
85 | + { |
|
76 | 86 | $result->push('=', null); |
77 | 87 | $compiler->compile($value, $result); |
78 | 88 | return; |
@@ -83,8 +93,10 @@ discard block |
||
83 | 93 | |
84 | 94 | private function verbatim(Compiler $compiler, Compiler\Result $result, Verbatim $node): void |
85 | 95 | { |
86 | - foreach ($node->nodes as $child) { |
|
87 | - if (\is_string($child)) { |
|
96 | + foreach ($node->nodes as $child) |
|
97 | + { |
|
98 | + if (\is_string($child)) |
|
99 | + { |
|
88 | 100 | $result->push($child, null); |
89 | 101 | continue; |
90 | 102 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | /** |
29 | 29 | * @throws InvalidArgumentException |
30 | 30 | */ |
31 | - public function file(string|\Stringable $id): FileInterface; |
|
31 | + public function file(string | \Stringable $id): FileInterface; |
|
32 | 32 | |
33 | 33 | public function withDefault(string $name): self; |
34 | 34 | } |
@@ -55,7 +55,8 @@ discard block |
||
55 | 55 | { |
56 | 56 | $name ??= $this->default; |
57 | 57 | |
58 | - if (!isset($this->buckets[$name])) { |
|
58 | + if (!isset($this->buckets[$name])) |
|
59 | + { |
|
59 | 60 | throw new InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
60 | 61 | } |
61 | 62 | |
@@ -71,7 +72,8 @@ discard block |
||
71 | 72 | |
72 | 73 | public function add(string $name, BucketInterface $storage, bool $overwrite = false): void |
73 | 74 | { |
74 | - if (!$overwrite && isset($this->buckets[$name])) { |
|
75 | + if (!$overwrite && isset($this->buckets[$name])) |
|
76 | + { |
|
75 | 77 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
76 | 78 | } |
77 | 79 | |
@@ -97,16 +99,19 @@ discard block |
||
97 | 99 | $uri = $this->uriToString($uri); |
98 | 100 | $result = \parse_url($uri); |
99 | 101 | |
100 | - if ($result === false) { |
|
102 | + if ($result === false) |
|
103 | + { |
|
101 | 104 | $message = 'URI argument must be a valid URI in "[STORAGE]://[PATH_TO_FILE]" format, but `%s` given'; |
102 | 105 | throw new InvalidArgumentException(\sprintf($message, $uri)); |
103 | 106 | } |
104 | 107 | |
105 | - if (!isset($result['scheme'])) { |
|
108 | + if (!isset($result['scheme'])) |
|
109 | + { |
|
106 | 110 | $result['scheme'] = $withScheme ? $this->default : null; |
107 | 111 | } |
108 | 112 | |
109 | - if (!isset($result['host'])) { |
|
113 | + if (!isset($result['host'])) |
|
114 | + { |
|
110 | 115 | $result['host'] = ''; |
111 | 116 | } |
112 | 117 |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | { |
56 | 56 | $name ??= $this->default; |
57 | 57 | |
58 | - if (!isset($this->buckets[$name])) { |
|
58 | + if (!isset($this->buckets[$name])){ |
|
59 | 59 | throw new InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
60 | 60 | } |
61 | 61 | |
62 | 62 | return $this->buckets[$name]; |
63 | 63 | } |
64 | 64 | |
65 | - public function file(string|\Stringable $id): FileInterface |
|
65 | + public function file(string | \Stringable $id): FileInterface |
|
66 | 66 | { |
67 | 67 | [$bucket, $file] = $this->parseUri($id); |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | public function add(string $name, BucketInterface $storage, bool $overwrite = false): void |
73 | 73 | { |
74 | - if (!$overwrite && isset($this->buckets[$name])) { |
|
74 | + if (!$overwrite && isset($this->buckets[$name])){ |
|
75 | 75 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
76 | 76 | } |
77 | 77 | |
@@ -92,35 +92,35 @@ discard block |
||
92 | 92 | * @return array{0: string|null, 1: string} |
93 | 93 | * @throws InvalidArgumentException |
94 | 94 | */ |
95 | - protected function parseUri(string|\Stringable $uri, bool $withScheme = true): array |
|
95 | + protected function parseUri(string | \Stringable $uri, bool $withScheme = true): array |
|
96 | 96 | { |
97 | 97 | $uri = $this->uriToString($uri); |
98 | 98 | $result = \parse_url($uri); |
99 | 99 | |
100 | - if ($result === false) { |
|
100 | + if ($result === false){ |
|
101 | 101 | $message = 'URI argument must be a valid URI in "[STORAGE]://[PATH_TO_FILE]" format, but `%s` given'; |
102 | 102 | throw new InvalidArgumentException(\sprintf($message, $uri)); |
103 | 103 | } |
104 | 104 | |
105 | - if (!isset($result['scheme'])) { |
|
105 | + if (!isset($result['scheme'])){ |
|
106 | 106 | $result['scheme'] = $withScheme ? $this->default : null; |
107 | 107 | } |
108 | 108 | |
109 | - if (!isset($result['host'])) { |
|
109 | + if (!isset($result['host'])){ |
|
110 | 110 | $result['host'] = ''; |
111 | 111 | } |
112 | 112 | |
113 | 113 | return [ |
114 | 114 | $result['scheme'] ?? null, |
115 | - $result['host'] . \rtrim($result['path'] ?? '', '/'), |
|
115 | + $result['host'].\rtrim($result['path'] ?? '', '/'), |
|
116 | 116 | ]; |
117 | 117 | } |
118 | 118 | |
119 | - private function uriToString(string|\Stringable $uri): string |
|
119 | + private function uriToString(string | \Stringable $uri): string |
|
120 | 120 | { |
121 | 121 | return match (true) { |
122 | 122 | \is_string($uri) => $uri, |
123 | - default => (string) $uri, |
|
123 | + default => (string)$uri, |
|
124 | 124 | }; |
125 | 125 | } |
126 | 126 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @throws FileOperationException |
24 | 24 | * @throws InvalidArgumentException |
25 | 25 | */ |
26 | - public function getContents(string|\Stringable $id): string; |
|
26 | + public function getContents(string | \Stringable $id): string; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * {@see BucketInterface::getStream()} |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @throws FileOperationException |
33 | 33 | * @throws InvalidArgumentException |
34 | 34 | */ |
35 | - public function getStream(string|\Stringable $id); |
|
35 | + public function getStream(string | \Stringable $id); |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * {@see BucketInterface::exists()} |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @throws FileOperationException |
41 | 41 | * @throws InvalidArgumentException |
42 | 42 | */ |
43 | - public function exists(string|\Stringable $id): bool; |
|
43 | + public function exists(string | \Stringable $id): bool; |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * {@see BucketInterface::getLastModified()} |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @throws FileOperationException |
50 | 50 | * @throws InvalidArgumentException |
51 | 51 | */ |
52 | - public function getLastModified(string|\Stringable $id): int; |
|
52 | + public function getLastModified(string | \Stringable $id): int; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * {@see BucketInterface::getSize()} |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @throws FileOperationException |
59 | 59 | * @throws InvalidArgumentException |
60 | 60 | */ |
61 | - public function getSize(string|\Stringable $id): int; |
|
61 | + public function getSize(string | \Stringable $id): int; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | *{@see BucketInterface::getMimeType()} |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @throws FileOperationException |
67 | 67 | * @throws InvalidArgumentException |
68 | 68 | */ |
69 | - public function getMimeType(string|\Stringable $id): string; |
|
69 | + public function getMimeType(string | \Stringable $id): string; |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * {@see BucketInterface::getVisibility()} |
@@ -76,5 +76,5 @@ discard block |
||
76 | 76 | * @throws InvalidArgumentException |
77 | 77 | */ |
78 | 78 | #[ExpectedValues(valuesFromClass: Visibility::class)] |
79 | - public function getVisibility(string|\Stringable $id): string; |
|
79 | + public function getVisibility(string | \Stringable $id): string; |
|
80 | 80 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | protected function getStacktrace(\Throwable $e): array |
28 | 28 | { |
29 | 29 | $stacktrace = $e->getTrace(); |
30 | - if (empty($stacktrace)) { |
|
30 | + if (empty($stacktrace)){ |
|
31 | 31 | return []; |
32 | 32 | } |
33 | 33 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | 'line' => $e->getLine(), |
38 | 38 | ] + $stacktrace[0]; |
39 | 39 | |
40 | - if ($stacktrace[0] !== $header) { |
|
40 | + if ($stacktrace[0] !== $header){ |
|
41 | 41 | \array_unshift($stacktrace, $header); |
42 | 42 | } |
43 | 43 |
@@ -27,7 +27,8 @@ discard block |
||
27 | 27 | protected function getStacktrace(\Throwable $e): array |
28 | 28 | { |
29 | 29 | $stacktrace = $e->getTrace(); |
30 | - if (empty($stacktrace)) { |
|
30 | + if (empty($stacktrace)) |
|
31 | + { |
|
31 | 32 | return []; |
32 | 33 | } |
33 | 34 | |
@@ -37,7 +38,8 @@ discard block |
||
37 | 38 | 'line' => $e->getLine(), |
38 | 39 | ] + $stacktrace[0]; |
39 | 40 | |
40 | - if ($stacktrace[0] !== $header) { |
|
41 | + if ($stacktrace[0] !== $header) |
|
42 | + { |
|
41 | 43 | \array_unshift($stacktrace, $header); |
42 | 44 | } |
43 | 45 |