@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | public function __construct( |
20 | 20 | private readonly ?DirectiveRendererInterface $directiveRenderer = null, |
21 | 21 | private readonly string $defaultFilter = self::DEFAULT_FILTER |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
26 | 26 | { |
27 | - switch (true) { |
|
27 | + switch (true){ |
|
28 | 28 | case $node instanceof Output: |
29 | 29 | $this->output($result, $node); |
30 | 30 | return true; |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | */ |
42 | 42 | private function directive(Compiler\Result $source, Directive $directive): void |
43 | 43 | { |
44 | - if ($this->directiveRenderer !== null) { |
|
44 | + if ($this->directiveRenderer !== null){ |
|
45 | 45 | $result = $this->directiveRenderer->render($directive); |
46 | - if ($result !== null) { |
|
46 | + if ($result !== null){ |
|
47 | 47 | $source->push($result, $directive->getContext()); |
48 | 48 | return; |
49 | 49 | } |
@@ -57,15 +57,15 @@ discard block |
||
57 | 57 | |
58 | 58 | private function output(Compiler\Result $source, Output $output): void |
59 | 59 | { |
60 | - if ($output->rawOutput) { |
|
61 | - $source->push(\sprintf('<?php echo %s; ?>', \trim((string) $output->body)), $output->getContext()); |
|
60 | + if ($output->rawOutput){ |
|
61 | + $source->push(\sprintf('<?php echo %s; ?>', \trim((string)$output->body)), $output->getContext()); |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | 65 | $filter = $output->filter ?? $this->defaultFilter; |
66 | 66 | |
67 | 67 | $source->push( |
68 | - \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string) $output->body)), |
|
68 | + \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string)$output->body)), |
|
69 | 69 | $output->getContext() |
70 | 70 | ); |
71 | 71 | } |
@@ -24,7 +24,8 @@ discard block |
||
24 | 24 | |
25 | 25 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
26 | 26 | { |
27 | - switch (true) { |
|
27 | + switch (true) |
|
28 | + { |
|
28 | 29 | case $node instanceof Output: |
29 | 30 | $this->output($result, $node); |
30 | 31 | return true; |
@@ -41,9 +42,11 @@ discard block |
||
41 | 42 | */ |
42 | 43 | private function directive(Compiler\Result $source, Directive $directive): void |
43 | 44 | { |
44 | - if ($this->directiveRenderer !== null) { |
|
45 | + if ($this->directiveRenderer !== null) |
|
46 | + { |
|
45 | 47 | $result = $this->directiveRenderer->render($directive); |
46 | - if ($result !== null) { |
|
48 | + if ($result !== null) |
|
49 | + { |
|
47 | 50 | $source->push($result, $directive->getContext()); |
48 | 51 | return; |
49 | 52 | } |
@@ -57,7 +60,8 @@ discard block |
||
57 | 60 | |
58 | 61 | private function output(Compiler\Result $source, Output $output): void |
59 | 62 | { |
60 | - if ($output->rawOutput) { |
|
63 | + if ($output->rawOutput) |
|
64 | + { |
|
61 | 65 | $source->push(\sprintf('<?php echo %s; ?>', \trim((string) $output->body)), $output->getContext()); |
62 | 66 | return; |
63 | 67 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | public function __construct( |
48 | 48 | private readonly ?DirectiveRendererInterface $directiveRenderer = null |
49 | - ) { |
|
49 | + ){ |
|
50 | 50 | $this->echo = new BracesGrammar( |
51 | 51 | '{{', |
52 | 52 | '}}', |
@@ -67,33 +67,33 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function parse(Buffer $src): \Generator |
69 | 69 | { |
70 | - while ($n = $src->next()) { |
|
71 | - if (!$n instanceof Byte) { |
|
70 | + while ($n = $src->next()){ |
|
71 | + if (!$n instanceof Byte){ |
|
72 | 72 | yield $n; |
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | |
76 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
76 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR){ |
|
77 | 77 | if ( |
78 | 78 | $this->echo->nextToken($src) || |
79 | 79 | $this->raw->nextToken($src) || |
80 | 80 | $src->lookaheadByte() === DirectiveGrammar::DIRECTIVE_CHAR |
81 | - ) { |
|
81 | + ){ |
|
82 | 82 | // escaped echo sequence, hide directive byte |
83 | 83 | yield $src->next(); |
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $directive = new DirectiveGrammar(); |
88 | - if ($directive->parse($src, $n->offset)) { |
|
89 | - if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
88 | + if ($directive->parse($src, $n->offset)){ |
|
89 | + if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE){ |
|
90 | 90 | // configure braces syntax |
91 | 91 | $this->declare($directive->getBody()); |
92 | - } else { |
|
92 | + }else{ |
|
93 | 93 | if ( |
94 | 94 | $this->directiveRenderer !== null |
95 | 95 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
96 | - ) { |
|
96 | + ){ |
|
97 | 97 | // directive opening char |
98 | 98 | yield $n; |
99 | 99 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | |
115 | 115 | /** @var BracesGrammar|null $braces */ |
116 | 116 | $braces = null; |
117 | - if ($this->echo->starts($src, $n)) { |
|
117 | + if ($this->echo->starts($src, $n)){ |
|
118 | 118 | $braces = clone $this->echo; |
119 | - } elseif ($this->raw->starts($src, $n)) { |
|
119 | + } elseif ($this->raw->starts($src, $n)){ |
|
120 | 120 | $braces = clone $this->raw; |
121 | 121 | } |
122 | 122 | |
123 | - if ($braces !== null) { |
|
123 | + if ($braces !== null){ |
|
124 | 124 | $echo = $braces->parse($src, $n); |
125 | - if ($echo !== null) { |
|
125 | + if ($echo !== null){ |
|
126 | 126 | yield from $echo; |
127 | 127 | continue; |
128 | 128 | } |
@@ -154,20 +154,20 @@ discard block |
||
154 | 154 | }; |
155 | 155 | } |
156 | 156 | |
157 | - private function declare(?string $body): void |
|
157 | + private function declare(?string$body) : void |
|
158 | 158 | { |
159 | - if ($body === null) { |
|
159 | + if ($body === null){ |
|
160 | 160 | return; |
161 | 161 | } |
162 | 162 | |
163 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
164 | - $value = \trim((string) $value, '\'" '); |
|
165 | - switch ($option) { |
|
163 | + foreach ($this->fetchOptions($body) as $option => $value){ |
|
164 | + $value = \trim((string)$value, '\'" '); |
|
165 | + switch ($option){ |
|
166 | 166 | case 'syntax': |
167 | 167 | $this->echo->setActive($value !== 'off'); |
168 | 168 | $this->raw->setActive($value !== 'off'); |
169 | 169 | |
170 | - if ($value === 'default') { |
|
170 | + if ($value === 'default'){ |
|
171 | 171 | $this->echo->setStartSequence('{{'); |
172 | 172 | $this->echo->setEndSequence('}}'); |
173 | 173 | $this->raw->setStartSequence('{!!'); |
@@ -204,10 +204,10 @@ discard block |
||
204 | 204 | $keyword = null; |
205 | 205 | |
206 | 206 | /** @var Token $token */ |
207 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
208 | - switch ($token->type) { |
|
207 | + foreach ($lexer->parse(new StringStream($body)) as $token){ |
|
208 | + switch ($token->type){ |
|
209 | 209 | case DeclareGrammar::TYPE_KEYWORD: |
210 | - if ($keyword !== null) { |
|
210 | + if ($keyword !== null){ |
|
211 | 211 | $options[$keyword] = $token->content; |
212 | 212 | $keyword = null; |
213 | 213 | break; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $keyword = $token->content; |
216 | 216 | break; |
217 | 217 | case DeclareGrammar::TYPE_QUOTED: |
218 | - if ($keyword !== null) { |
|
218 | + if ($keyword !== null){ |
|
219 | 219 | $options[$keyword] = \trim($token->content, $token->content[0]); |
220 | 220 | $keyword = null; |
221 | 221 | break; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $keyword = \trim($token->content, $token->content[0]); |
225 | 225 | break; |
226 | 226 | case DeclareGrammar::TYPE_COMMA: |
227 | - if ($keyword !== null) { |
|
227 | + if ($keyword !== null){ |
|
228 | 228 | $options[$keyword] = null; |
229 | 229 | $keyword = null; |
230 | 230 | break; |
@@ -67,13 +67,16 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function parse(Buffer $src): \Generator |
69 | 69 | { |
70 | - while ($n = $src->next()) { |
|
71 | - if (!$n instanceof Byte) { |
|
70 | + while ($n = $src->next()) |
|
71 | + { |
|
72 | + if (!$n instanceof Byte) |
|
73 | + { |
|
72 | 74 | yield $n; |
73 | 75 | continue; |
74 | 76 | } |
75 | 77 | |
76 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
78 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) |
|
79 | + { |
|
77 | 80 | if ( |
78 | 81 | $this->echo->nextToken($src) || |
79 | 82 | $this->raw->nextToken($src) || |
@@ -85,11 +88,15 @@ discard block |
||
85 | 88 | } |
86 | 89 | |
87 | 90 | $directive = new DirectiveGrammar(); |
88 | - if ($directive->parse($src, $n->offset)) { |
|
89 | - if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
91 | + if ($directive->parse($src, $n->offset)) |
|
92 | + { |
|
93 | + if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) |
|
94 | + { |
|
90 | 95 | // configure braces syntax |
91 | 96 | $this->declare($directive->getBody()); |
92 | - } else { |
|
97 | + } |
|
98 | + else |
|
99 | + { |
|
93 | 100 | if ( |
94 | 101 | $this->directiveRenderer !== null |
95 | 102 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
@@ -114,15 +121,20 @@ discard block |
||
114 | 121 | |
115 | 122 | /** @var BracesGrammar|null $braces */ |
116 | 123 | $braces = null; |
117 | - if ($this->echo->starts($src, $n)) { |
|
124 | + if ($this->echo->starts($src, $n)) |
|
125 | + { |
|
118 | 126 | $braces = clone $this->echo; |
119 | - } elseif ($this->raw->starts($src, $n)) { |
|
127 | + } |
|
128 | + elseif ($this->raw->starts($src, $n)) |
|
129 | + { |
|
120 | 130 | $braces = clone $this->raw; |
121 | 131 | } |
122 | 132 | |
123 | - if ($braces !== null) { |
|
133 | + if ($braces !== null) |
|
134 | + { |
|
124 | 135 | $echo = $braces->parse($src, $n); |
125 | - if ($echo !== null) { |
|
136 | + if ($echo !== null) |
|
137 | + { |
|
126 | 138 | yield from $echo; |
127 | 139 | continue; |
128 | 140 | } |
@@ -156,18 +168,22 @@ discard block |
||
156 | 168 | |
157 | 169 | private function declare(?string $body): void |
158 | 170 | { |
159 | - if ($body === null) { |
|
171 | + if ($body === null) |
|
172 | + { |
|
160 | 173 | return; |
161 | 174 | } |
162 | 175 | |
163 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
176 | + foreach ($this->fetchOptions($body) as $option => $value) |
|
177 | + { |
|
164 | 178 | $value = \trim((string) $value, '\'" '); |
165 | - switch ($option) { |
|
179 | + switch ($option) |
|
180 | + { |
|
166 | 181 | case 'syntax': |
167 | 182 | $this->echo->setActive($value !== 'off'); |
168 | 183 | $this->raw->setActive($value !== 'off'); |
169 | 184 | |
170 | - if ($value === 'default') { |
|
185 | + if ($value === 'default') |
|
186 | + { |
|
171 | 187 | $this->echo->setStartSequence('{{'); |
172 | 188 | $this->echo->setEndSequence('}}'); |
173 | 189 | $this->raw->setStartSequence('{!!'); |
@@ -204,10 +220,13 @@ discard block |
||
204 | 220 | $keyword = null; |
205 | 221 | |
206 | 222 | /** @var Token $token */ |
207 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
208 | - switch ($token->type) { |
|
223 | + foreach ($lexer->parse(new StringStream($body)) as $token) |
|
224 | + { |
|
225 | + switch ($token->type) |
|
226 | + { |
|
209 | 227 | case DeclareGrammar::TYPE_KEYWORD: |
210 | - if ($keyword !== null) { |
|
228 | + if ($keyword !== null) |
|
229 | + { |
|
211 | 230 | $options[$keyword] = $token->content; |
212 | 231 | $keyword = null; |
213 | 232 | break; |
@@ -215,7 +234,8 @@ discard block |
||
215 | 234 | $keyword = $token->content; |
216 | 235 | break; |
217 | 236 | case DeclareGrammar::TYPE_QUOTED: |
218 | - if ($keyword !== null) { |
|
237 | + if ($keyword !== null) |
|
238 | + { |
|
219 | 239 | $options[$keyword] = \trim($token->content, $token->content[0]); |
220 | 240 | $keyword = null; |
221 | 241 | break; |
@@ -224,7 +244,8 @@ discard block |
||
224 | 244 | $keyword = \trim($token->content, $token->content[0]); |
225 | 245 | break; |
226 | 246 | case DeclareGrammar::TYPE_COMMA: |
227 | - if ($keyword !== null) { |
|
247 | + if ($keyword !== null) |
|
248 | + { |
|
228 | 249 | $options[$keyword] = null; |
229 | 250 | $keyword = null; |
230 | 251 | break; |
@@ -11,7 +11,7 @@ |
||
11 | 11 | public function __construct( |
12 | 12 | string $reason = '', |
13 | 13 | private readonly ?OptionsInterface $options = null |
14 | - ) { |
|
14 | + ){ |
|
15 | 15 | parent::__construct($reason); |
16 | 16 | } |
17 | 17 |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function makeSchema(string $name, array $schema): array |
44 | 44 | { |
45 | - if (empty($schema)) { |
|
45 | + if (empty($schema)){ |
|
46 | 46 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
47 | 47 | } |
48 | 48 | |
49 | 49 | $result = []; |
50 | - foreach ($schema as $field => $definition) { |
|
50 | + foreach ($schema as $field => $definition){ |
|
51 | 51 | $optional = false; |
52 | 52 | |
53 | 53 | // short definition |
54 | - if (\is_string($definition)) { |
|
54 | + if (\is_string($definition)){ |
|
55 | 55 | // simple scalar field definition |
56 | - if (!\class_exists($definition)) { |
|
56 | + if (!\class_exists($definition)){ |
|
57 | 57 | [$source, $origin] = $this->parseDefinition($field, $definition); |
58 | 58 | $result[$field] = [ |
59 | 59 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +74,25 @@ discard block |
||
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - if (!\is_array($definition) || $definition === []) { |
|
77 | + if (!\is_array($definition) || $definition === []){ |
|
78 | 78 | throw new SchemaException( |
79 | 79 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
83 | 83 | // complex definition |
84 | - if (!empty($definition[self::ORIGIN])) { |
|
84 | + if (!empty($definition[self::ORIGIN])){ |
|
85 | 85 | $origin = $definition[self::ORIGIN]; |
86 | 86 | |
87 | 87 | // [class, 'data:something.*'] vs [class, 'data:something'] |
88 | 88 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
89 | - $origin = \rtrim((string) $origin, '.*'); |
|
90 | - } else { |
|
89 | + $origin = \rtrim((string)$origin, '.*'); |
|
90 | + }else{ |
|
91 | 91 | $origin = $field; |
92 | 92 | $iterate = true; |
93 | 93 | } |
94 | 94 | |
95 | - if (!empty($definition[self::OPTIONAL])) { |
|
95 | + if (!empty($definition[self::OPTIONAL])){ |
|
96 | 96 | $optional = true; |
97 | 97 | } |
98 | 98 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | self::SCHEMA_OPTIONAL => $optional, |
106 | 106 | ]; |
107 | 107 | |
108 | - if ($iterate) { |
|
108 | + if ($iterate){ |
|
109 | 109 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
110 | 110 | |
111 | 111 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | private function parseDefinition(string $field, string $definition): array |
130 | 130 | { |
131 | - if (!\str_contains($definition, ':')) { |
|
131 | + if (!\str_contains($definition, ':')){ |
|
132 | 132 | return ['data', empty($definition) ? $field : $definition]; |
133 | 133 | } |
134 | 134 |
@@ -42,18 +42,22 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function makeSchema(string $name, array $schema): array |
44 | 44 | { |
45 | - if (empty($schema)) { |
|
45 | + if (empty($schema)) |
|
46 | + { |
|
46 | 47 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
47 | 48 | } |
48 | 49 | |
49 | 50 | $result = []; |
50 | - foreach ($schema as $field => $definition) { |
|
51 | + foreach ($schema as $field => $definition) |
|
52 | + { |
|
51 | 53 | $optional = false; |
52 | 54 | |
53 | 55 | // short definition |
54 | - if (\is_string($definition)) { |
|
56 | + if (\is_string($definition)) |
|
57 | + { |
|
55 | 58 | // simple scalar field definition |
56 | - if (!\class_exists($definition)) { |
|
59 | + if (!\class_exists($definition)) |
|
60 | + { |
|
57 | 61 | [$source, $origin] = $this->parseDefinition($field, $definition); |
58 | 62 | $result[$field] = [ |
59 | 63 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +78,30 @@ discard block |
||
74 | 78 | continue; |
75 | 79 | } |
76 | 80 | |
77 | - if (!\is_array($definition) || $definition === []) { |
|
81 | + if (!\is_array($definition) || $definition === []) |
|
82 | + { |
|
78 | 83 | throw new SchemaException( |
79 | 84 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
80 | 85 | ); |
81 | 86 | } |
82 | 87 | |
83 | 88 | // complex definition |
84 | - if (!empty($definition[self::ORIGIN])) { |
|
89 | + if (!empty($definition[self::ORIGIN])) |
|
90 | + { |
|
85 | 91 | $origin = $definition[self::ORIGIN]; |
86 | 92 | |
87 | 93 | // [class, 'data:something.*'] vs [class, 'data:something'] |
88 | 94 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
89 | 95 | $origin = \rtrim((string) $origin, '.*'); |
90 | - } else { |
|
96 | + } |
|
97 | + else |
|
98 | + { |
|
91 | 99 | $origin = $field; |
92 | 100 | $iterate = true; |
93 | 101 | } |
94 | 102 | |
95 | - if (!empty($definition[self::OPTIONAL])) { |
|
103 | + if (!empty($definition[self::OPTIONAL])) |
|
104 | + { |
|
96 | 105 | $optional = true; |
97 | 106 | } |
98 | 107 | |
@@ -105,7 +114,8 @@ discard block |
||
105 | 114 | self::SCHEMA_OPTIONAL => $optional, |
106 | 115 | ]; |
107 | 116 | |
108 | - if ($iterate) { |
|
117 | + if ($iterate) |
|
118 | + { |
|
109 | 119 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
110 | 120 | |
111 | 121 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -128,7 +138,8 @@ discard block |
||
128 | 138 | */ |
129 | 139 | private function parseDefinition(string $field, string $definition): array |
130 | 140 | { |
131 | - if (!\str_contains($definition, ':')) { |
|
141 | + if (!\str_contains($definition, ':')) |
|
142 | + { |
|
132 | 143 | return ['data', empty($definition) ? $field : $definition]; |
133 | 144 | } |
134 | 145 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct(array $items = []) |
28 | 28 | { |
29 | - foreach ($items as $item) { |
|
29 | + foreach ($items as $item){ |
|
30 | 30 | $this->addItem($item); |
31 | 31 | } |
32 | 32 | } |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | $header = new static(); |
42 | 42 | |
43 | 43 | $parts = \explode(',', $raw); |
44 | - foreach ($parts as $part) { |
|
44 | + foreach ($parts as $part){ |
|
45 | 45 | $part = \trim($part); |
46 | - if ($part !== '') { |
|
46 | + if ($part !== ''){ |
|
47 | 47 | $header->addItem($part); |
48 | 48 | } |
49 | 49 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | return $header; |
52 | 52 | } |
53 | 53 | |
54 | - public function add(AcceptHeaderItem|string $item): self |
|
54 | + public function add(AcceptHeaderItem | string $item): self |
|
55 | 55 | { |
56 | 56 | $header = clone $this; |
57 | 57 | $header->addItem($item); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function getAll(): array |
76 | 76 | { |
77 | - if (!$this->sorted) { |
|
77 | + if (!$this->sorted){ |
|
78 | 78 | /** |
79 | 79 | * Sort item in descending order. |
80 | 80 | */ |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | /** |
90 | 90 | * Add new item to list. |
91 | 91 | */ |
92 | - private function addItem(AcceptHeaderItem|string $item): void |
|
92 | + private function addItem(AcceptHeaderItem | string $item): void |
|
93 | 93 | { |
94 | - if (\is_string($item)) { |
|
94 | + if (\is_string($item)){ |
|
95 | 95 | $item = AcceptHeaderItem::fromString($item); |
96 | 96 | } |
97 | 97 | |
98 | - $value = \strtolower((string) $item->getValue()); |
|
99 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
98 | + $value = \strtolower((string)$item->getValue()); |
|
99 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
100 | 100 | $this->sorted = false; |
101 | 101 | $this->items[$value] = $item; |
102 | 102 | } |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * Compare to header items, witch one is preferable. |
107 | 107 | * Return 1 if first value preferable or -1 if second, 0 in case of same weight. |
108 | 108 | */ |
109 | - private static function compare(AcceptHeaderItem|string $a, AcceptHeaderItem|string $b): int |
|
109 | + private static function compare(AcceptHeaderItem | string $a, AcceptHeaderItem | string $b): int |
|
110 | 110 | { |
111 | - if ($a->getQuality() === $b->getQuality()) { |
|
111 | + if ($a->getQuality() === $b->getQuality()){ |
|
112 | 112 | // If quality are same value with more params has more weight. |
113 | - if (\count($a->getParams()) === \count($b->getParams())) { |
|
113 | + if (\count($a->getParams()) === \count($b->getParams())){ |
|
114 | 114 | // If quality and params then check for specific type or subtype. |
115 | 115 | // Means */* or * has less weight. |
116 | 116 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | private static function compareValue(string $a, string $b): int |
130 | 130 | { |
131 | 131 | // Check "Accept" headers values with it is type and subtype. |
132 | - if (\str_contains($a, '/') && \str_contains($b, '/')) { |
|
132 | + if (\str_contains($a, '/') && \str_contains($b, '/')){ |
|
133 | 133 | [$typeA, $subtypeA] = \explode('/', $a, 2); |
134 | 134 | [$typeB, $subtypeB] = \explode('/', $b, 2); |
135 | 135 | |
136 | - if ($typeA === $typeB) { |
|
136 | + if ($typeA === $typeB){ |
|
137 | 137 | return static::compareAtomic($subtypeA, $subtypeB); |
138 | 138 | } |
139 | 139 | |
@@ -145,23 +145,23 @@ discard block |
||
145 | 145 | |
146 | 146 | private static function compareAtomic(string $a, string $b): int |
147 | 147 | { |
148 | - if (\mb_strpos($a, '*/') === 0) { |
|
148 | + if (\mb_strpos($a, '*/') === 0){ |
|
149 | 149 | $a = '*'; |
150 | 150 | } |
151 | 151 | |
152 | - if (\mb_strpos($b, '*/') === 0) { |
|
152 | + if (\mb_strpos($b, '*/') === 0){ |
|
153 | 153 | $b = '*'; |
154 | 154 | } |
155 | 155 | |
156 | - if (\strtolower($a) === \strtolower($b)) { |
|
156 | + if (\strtolower($a) === \strtolower($b)){ |
|
157 | 157 | return 0; |
158 | 158 | } |
159 | 159 | |
160 | - if ($a === '*') { |
|
160 | + if ($a === '*'){ |
|
161 | 161 | return -1; |
162 | 162 | } |
163 | 163 | |
164 | - if ($b === '*') { |
|
164 | + if ($b === '*'){ |
|
165 | 165 | return 1; |
166 | 166 | } |
167 | 167 |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct(array $items = []) |
28 | 28 | { |
29 | - foreach ($items as $item) { |
|
29 | + foreach ($items as $item) |
|
30 | + { |
|
30 | 31 | $this->addItem($item); |
31 | 32 | } |
32 | 33 | } |
@@ -41,9 +42,11 @@ discard block |
||
41 | 42 | $header = new static(); |
42 | 43 | |
43 | 44 | $parts = \explode(',', $raw); |
44 | - foreach ($parts as $part) { |
|
45 | + foreach ($parts as $part) |
|
46 | + { |
|
45 | 47 | $part = \trim($part); |
46 | - if ($part !== '') { |
|
48 | + if ($part !== '') |
|
49 | + { |
|
47 | 50 | $header->addItem($part); |
48 | 51 | } |
49 | 52 | } |
@@ -74,7 +77,8 @@ discard block |
||
74 | 77 | */ |
75 | 78 | public function getAll(): array |
76 | 79 | { |
77 | - if (!$this->sorted) { |
|
80 | + if (!$this->sorted) |
|
81 | + { |
|
78 | 82 | /** |
79 | 83 | * Sort item in descending order. |
80 | 84 | */ |
@@ -91,12 +95,14 @@ discard block |
||
91 | 95 | */ |
92 | 96 | private function addItem(AcceptHeaderItem|string $item): void |
93 | 97 | { |
94 | - if (\is_string($item)) { |
|
98 | + if (\is_string($item)) |
|
99 | + { |
|
95 | 100 | $item = AcceptHeaderItem::fromString($item); |
96 | 101 | } |
97 | 102 | |
98 | 103 | $value = \strtolower((string) $item->getValue()); |
99 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
104 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
105 | + { |
|
100 | 106 | $this->sorted = false; |
101 | 107 | $this->items[$value] = $item; |
102 | 108 | } |
@@ -108,9 +114,11 @@ discard block |
||
108 | 114 | */ |
109 | 115 | private static function compare(AcceptHeaderItem|string $a, AcceptHeaderItem|string $b): int |
110 | 116 | { |
111 | - if ($a->getQuality() === $b->getQuality()) { |
|
117 | + if ($a->getQuality() === $b->getQuality()) |
|
118 | + { |
|
112 | 119 | // If quality are same value with more params has more weight. |
113 | - if (\count($a->getParams()) === \count($b->getParams())) { |
|
120 | + if (\count($a->getParams()) === \count($b->getParams())) |
|
121 | + { |
|
114 | 122 | // If quality and params then check for specific type or subtype. |
115 | 123 | // Means */* or * has less weight. |
116 | 124 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -129,11 +137,13 @@ discard block |
||
129 | 137 | private static function compareValue(string $a, string $b): int |
130 | 138 | { |
131 | 139 | // Check "Accept" headers values with it is type and subtype. |
132 | - if (\str_contains($a, '/') && \str_contains($b, '/')) { |
|
140 | + if (\str_contains($a, '/') && \str_contains($b, '/')) |
|
141 | + { |
|
133 | 142 | [$typeA, $subtypeA] = \explode('/', $a, 2); |
134 | 143 | [$typeB, $subtypeB] = \explode('/', $b, 2); |
135 | 144 | |
136 | - if ($typeA === $typeB) { |
|
145 | + if ($typeA === $typeB) |
|
146 | + { |
|
137 | 147 | return static::compareAtomic($subtypeA, $subtypeB); |
138 | 148 | } |
139 | 149 | |
@@ -145,23 +155,28 @@ discard block |
||
145 | 155 | |
146 | 156 | private static function compareAtomic(string $a, string $b): int |
147 | 157 | { |
148 | - if (\mb_strpos($a, '*/') === 0) { |
|
158 | + if (\mb_strpos($a, '*/') === 0) |
|
159 | + { |
|
149 | 160 | $a = '*'; |
150 | 161 | } |
151 | 162 | |
152 | - if (\mb_strpos($b, '*/') === 0) { |
|
163 | + if (\mb_strpos($b, '*/') === 0) |
|
164 | + { |
|
153 | 165 | $b = '*'; |
154 | 166 | } |
155 | 167 | |
156 | - if (\strtolower($a) === \strtolower($b)) { |
|
168 | + if (\strtolower($a) === \strtolower($b)) |
|
169 | + { |
|
157 | 170 | return 0; |
158 | 171 | } |
159 | 172 | |
160 | - if ($a === '*') { |
|
173 | + if ($a === '*') |
|
174 | + { |
|
161 | 175 | return -1; |
162 | 176 | } |
163 | 177 | |
164 | - if ($b === '*') { |
|
178 | + if ($b === '*') |
|
179 | + { |
|
165 | 180 | return 1; |
166 | 181 | } |
167 | 182 |
@@ -10,7 +10,7 @@ |
||
10 | 10 | { |
11 | 11 | public function __construct( |
12 | 12 | private readonly DebugMode $debugMode |
13 | - ) { |
|
13 | + ){ |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | public function suppressed(): bool |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $class = $this->classify($name); |
69 | 69 | $postfix = $this->elementPostfix($element); |
70 | 70 | |
71 | - return \str_ends_with($class, $postfix) ? $class : $class . $postfix; |
|
71 | + return \str_ends_with($class, $postfix) ? $class : $class.$postfix; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function classNamespace(string $element, string $name = ''): string |
78 | 78 | { |
79 | - $localNamespace = \trim((string) $this->getOption($element, 'namespace', ''), '\\'); |
|
79 | + $localNamespace = \trim((string)$this->getOption($element, 'namespace', ''), '\\'); |
|
80 | 80 | ['namespace' => $namespace] = $this->parseName($name); |
81 | 81 | |
82 | - if (!empty($namespace)) { |
|
83 | - $localNamespace .= '\\' . $this->classify($namespace); |
|
82 | + if (!empty($namespace)){ |
|
83 | + $localNamespace .= '\\'.$this->classify($namespace); |
|
84 | 84 | } |
85 | 85 | |
86 | - if (empty($this->baseNamespace($element))) { |
|
86 | + if (empty($this->baseNamespace($element))){ |
|
87 | 87 | return $localNamespace; |
88 | 88 | } |
89 | 89 | |
90 | - return \trim($this->baseNamespace($element) . '\\' . $localNamespace, '\\'); |
|
90 | + return \trim($this->baseNamespace($element).'\\'.$localNamespace, '\\'); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | return $this->joinPathChunks([ |
105 | 105 | $this->declarationDirectory($element), |
106 | 106 | \str_replace('\\', '/', $elementNamespace), |
107 | - $this->className($element, $name) . '.php', |
|
107 | + $this->className($element, $name).'.php', |
|
108 | 108 | ], '/'); |
109 | 109 | } |
110 | 110 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | $class = $this->getOption($element, 'class'); |
119 | 119 | |
120 | - if (empty($class)) { |
|
120 | + if (empty($class)){ |
|
121 | 121 | throw new ScaffolderException( |
122 | 122 | \sprintf("Unable to scaffold '%s', no declaration class found", $element), |
123 | 123 | ); |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | { |
166 | 166 | $declaration = $this->getDeclaration($element); |
167 | 167 | |
168 | - if ($declaration === []) { |
|
168 | + if ($declaration === []){ |
|
169 | 169 | throw new ScaffolderException(\sprintf("Undefined declaration '%s'.", $element)); |
170 | 170 | } |
171 | 171 | |
172 | - if (\array_key_exists($section, $declaration)) { |
|
172 | + if (\array_key_exists($section, $declaration)){ |
|
173 | 173 | return $declaration[$section]; |
174 | 174 | } |
175 | 175 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | { |
188 | 188 | $name = \str_replace('/', '\\', $name); |
189 | 189 | |
190 | - if (str_contains($name, '\\')) { |
|
190 | + if (str_contains($name, '\\')){ |
|
191 | 191 | $names = \explode('\\', $name); |
192 | 192 | $class = \array_pop($names); |
193 | 193 | |
@@ -205,23 +205,23 @@ discard block |
||
205 | 205 | { |
206 | 206 | $declaration = $this->getDeclaration($element); |
207 | 207 | |
208 | - if (\array_key_exists('baseNamespace', $declaration)) { |
|
208 | + if (\array_key_exists('baseNamespace', $declaration)){ |
|
209 | 209 | return \trim((string)$this->getOption($element, 'baseNamespace', ''), '\\'); |
210 | 210 | } |
211 | 211 | |
212 | - return \trim((string) $this->config['namespace'], '\\'); |
|
212 | + return \trim((string)$this->config['namespace'], '\\'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | private function joinPathChunks(array $chunks, string $joint): string |
216 | 216 | { |
217 | 217 | $firstChunkIterated = false; |
218 | 218 | $joinedPath = ''; |
219 | - foreach ($chunks as $chunk) { |
|
220 | - if (!$firstChunkIterated) { |
|
219 | + foreach ($chunks as $chunk){ |
|
220 | + if (!$firstChunkIterated){ |
|
221 | 221 | $firstChunkIterated = true; |
222 | 222 | $joinedPath = $chunk; |
223 | - } else { |
|
224 | - $joinedPath = \rtrim((string) $joinedPath, $joint) . $joint . \ltrim((string) $chunk, $joint); |
|
223 | + }else{ |
|
224 | + $joinedPath = \rtrim((string)$joinedPath, $joint).$joint.\ltrim((string)$chunk, $joint); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 |
@@ -79,11 +79,13 @@ discard block |
||
79 | 79 | $localNamespace = \trim((string) $this->getOption($element, 'namespace', ''), '\\'); |
80 | 80 | ['namespace' => $namespace] = $this->parseName($name); |
81 | 81 | |
82 | - if (!empty($namespace)) { |
|
82 | + if (!empty($namespace)) |
|
83 | + { |
|
83 | 84 | $localNamespace .= '\\' . $this->classify($namespace); |
84 | 85 | } |
85 | 86 | |
86 | - if (empty($this->baseNamespace($element))) { |
|
87 | + if (empty($this->baseNamespace($element))) |
|
88 | + { |
|
87 | 89 | return $localNamespace; |
88 | 90 | } |
89 | 91 | |
@@ -117,7 +119,8 @@ discard block |
||
117 | 119 | { |
118 | 120 | $class = $this->getOption($element, 'class'); |
119 | 121 | |
120 | - if (empty($class)) { |
|
122 | + if (empty($class)) |
|
123 | + { |
|
121 | 124 | throw new ScaffolderException( |
122 | 125 | \sprintf("Unable to scaffold '%s', no declaration class found", $element), |
123 | 126 | ); |
@@ -165,11 +168,13 @@ discard block |
||
165 | 168 | { |
166 | 169 | $declaration = $this->getDeclaration($element); |
167 | 170 | |
168 | - if ($declaration === []) { |
|
171 | + if ($declaration === []) |
|
172 | + { |
|
169 | 173 | throw new ScaffolderException(\sprintf("Undefined declaration '%s'.", $element)); |
170 | 174 | } |
171 | 175 | |
172 | - if (\array_key_exists($section, $declaration)) { |
|
176 | + if (\array_key_exists($section, $declaration)) |
|
177 | + { |
|
173 | 178 | return $declaration[$section]; |
174 | 179 | } |
175 | 180 | |
@@ -187,7 +192,8 @@ discard block |
||
187 | 192 | { |
188 | 193 | $name = \str_replace('/', '\\', $name); |
189 | 194 | |
190 | - if (str_contains($name, '\\')) { |
|
195 | + if (str_contains($name, '\\')) |
|
196 | + { |
|
191 | 197 | $names = \explode('\\', $name); |
192 | 198 | $class = \array_pop($names); |
193 | 199 | |
@@ -205,7 +211,8 @@ discard block |
||
205 | 211 | { |
206 | 212 | $declaration = $this->getDeclaration($element); |
207 | 213 | |
208 | - if (\array_key_exists('baseNamespace', $declaration)) { |
|
214 | + if (\array_key_exists('baseNamespace', $declaration)) |
|
215 | + { |
|
209 | 216 | return \trim((string)$this->getOption($element, 'baseNamespace', ''), '\\'); |
210 | 217 | } |
211 | 218 | |
@@ -216,11 +223,15 @@ discard block |
||
216 | 223 | { |
217 | 224 | $firstChunkIterated = false; |
218 | 225 | $joinedPath = ''; |
219 | - foreach ($chunks as $chunk) { |
|
220 | - if (!$firstChunkIterated) { |
|
226 | + foreach ($chunks as $chunk) |
|
227 | + { |
|
228 | + if (!$firstChunkIterated) |
|
229 | + { |
|
221 | 230 | $firstChunkIterated = true; |
222 | 231 | $joinedPath = $chunk; |
223 | - } else { |
|
232 | + } |
|
233 | + else |
|
234 | + { |
|
224 | 235 | $joinedPath = \rtrim((string) $joinedPath, $joint) . $joint . \ltrim((string) $chunk, $joint); |
225 | 236 | } |
226 | 237 | } |
@@ -39,14 +39,14 @@ |
||
39 | 39 | { |
40 | 40 | $declaration = $this->createDeclaration(CommandDeclaration::class, [ |
41 | 41 | 'description' => $this->description, |
42 | - 'alias' => $this->alias ?? \strtolower((string) \preg_replace('/(?<!^)[A-Z]/', ':$0', $this->name)), |
|
42 | + 'alias' => $this->alias ?? \strtolower((string)\preg_replace('/(?<!^)[A-Z]/', ':$0', $this->name)), |
|
43 | 43 | ]); |
44 | 44 | |
45 | - foreach ($this->arguments as $argument) { |
|
45 | + foreach ($this->arguments as $argument){ |
|
46 | 46 | $declaration->addArgument($argument); |
47 | 47 | } |
48 | 48 | |
49 | - foreach ($this->options as $option) { |
|
49 | + foreach ($this->options as $option){ |
|
50 | 50 | $declaration->addOption($option); |
51 | 51 | } |
52 | 52 |
@@ -42,11 +42,13 @@ |
||
42 | 42 | 'alias' => $this->alias ?? \strtolower((string) \preg_replace('/(?<!^)[A-Z]/', ':$0', $this->name)), |
43 | 43 | ]); |
44 | 44 | |
45 | - foreach ($this->arguments as $argument) { |
|
45 | + foreach ($this->arguments as $argument) |
|
46 | + { |
|
46 | 47 | $declaration->addArgument($argument); |
47 | 48 | } |
48 | 49 | |
49 | - foreach ($this->options as $option) { |
|
50 | + foreach ($this->options as $option) |
|
51 | + { |
|
50 | 52 | $declaration->addOption($option); |
51 | 53 | } |
52 | 54 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | { |
13 | 13 | public function __construct( |
14 | 14 | private readonly LoggerInterface $logger = new NullLogger() |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | public function report(\Throwable $exception): void |