@@ -21,59 +21,59 @@ discard block |
||
21 | 21 | |
22 | 22 | return RectorConfig::configure() |
23 | 23 | ->withPaths([ |
24 | - __DIR__ . '/src/*/src', |
|
25 | - __DIR__ . '/src/*/tests', |
|
26 | - __DIR__ . '/tests', |
|
24 | + __DIR__.'/src/*/src', |
|
25 | + __DIR__.'/src/*/tests', |
|
26 | + __DIR__.'/tests', |
|
27 | 27 | ]) |
28 | 28 | ->withParallel() |
29 | 29 | ->withSkip([ |
30 | 30 | IfIssetToCoalescingRector::class, |
31 | 31 | RemoveUnusedPrivatePropertyRector::class => [ |
32 | - __DIR__ . '/src/Scaffolder/src/Command/BootloaderCommand.php', |
|
33 | - __DIR__ . '/src/Scaffolder/src/Command/CommandCommand.php', |
|
34 | - __DIR__ . '/src/Scaffolder/src/Command/ConfigCommand.php', |
|
35 | - __DIR__ . '/src/Scaffolder/src/Command/ControllerCommand.php', |
|
36 | - __DIR__ . '/src/Scaffolder/src/Command/FilterCommand.php', |
|
37 | - __DIR__ . '/src/Scaffolder/src/Command/JobHandlerCommand.php', |
|
38 | - __DIR__ . '/src/Scaffolder/src/Command/MiddlewareCommand.php', |
|
39 | - __DIR__ . '/src/Console/tests/PromptArgumentsTest.php', |
|
32 | + __DIR__.'/src/Scaffolder/src/Command/BootloaderCommand.php', |
|
33 | + __DIR__.'/src/Scaffolder/src/Command/CommandCommand.php', |
|
34 | + __DIR__.'/src/Scaffolder/src/Command/ConfigCommand.php', |
|
35 | + __DIR__.'/src/Scaffolder/src/Command/ControllerCommand.php', |
|
36 | + __DIR__.'/src/Scaffolder/src/Command/FilterCommand.php', |
|
37 | + __DIR__.'/src/Scaffolder/src/Command/JobHandlerCommand.php', |
|
38 | + __DIR__.'/src/Scaffolder/src/Command/MiddlewareCommand.php', |
|
39 | + __DIR__.'/src/Console/tests/PromptArgumentsTest.php', |
|
40 | 40 | ], |
41 | 41 | RemoveUnusedPrivateMethodRector::class => [ |
42 | - __DIR__ . '/src/Boot/src/Bootloader/ConfigurationBootloader.php', |
|
43 | - __DIR__ . '/src/Broadcasting/src/Bootloader/BroadcastingBootloader.php', |
|
44 | - __DIR__ . '/src/Cache/src/Bootloader/CacheBootloader.php', |
|
45 | - __DIR__ . '/src/Serializer/src/Bootloader/SerializerBootloader.php', |
|
46 | - __DIR__ . '/src/Validation/src/Bootloader/ValidationBootloader.php', |
|
47 | - __DIR__ . '/src/Translator/tests/IndexerTest.php', |
|
48 | - __DIR__ . '/src/Tokenizer/tests/ReflectionFileTest.php', |
|
49 | - __DIR__ . '/src/Core/tests/SingletonsTest.php', |
|
42 | + __DIR__.'/src/Boot/src/Bootloader/ConfigurationBootloader.php', |
|
43 | + __DIR__.'/src/Broadcasting/src/Bootloader/BroadcastingBootloader.php', |
|
44 | + __DIR__.'/src/Cache/src/Bootloader/CacheBootloader.php', |
|
45 | + __DIR__.'/src/Serializer/src/Bootloader/SerializerBootloader.php', |
|
46 | + __DIR__.'/src/Validation/src/Bootloader/ValidationBootloader.php', |
|
47 | + __DIR__.'/src/Translator/tests/IndexerTest.php', |
|
48 | + __DIR__.'/src/Tokenizer/tests/ReflectionFileTest.php', |
|
49 | + __DIR__.'/src/Core/tests/SingletonsTest.php', |
|
50 | 50 | ], |
51 | 51 | RemoveUselessVarTagRector::class => [ |
52 | - __DIR__ . '/src/Console/src/Traits/HelpersTrait.php', |
|
52 | + __DIR__.'/src/Console/src/Traits/HelpersTrait.php', |
|
53 | 53 | ], |
54 | 54 | RemoveAlwaysTrueIfConditionRector::class => [ |
55 | - __DIR__ . '/src/Boot/src/BootloadManager/Initializer.php', |
|
56 | - __DIR__ . '/src/Stempler/src/Traverser.php', |
|
57 | - __DIR__ . '/src/Prototype/src/NodeVisitors/LocateProperties.php', |
|
58 | - __DIR__ . '/src/Prototype/src/NodeVisitors/RemoveTrait.php', |
|
59 | - __DIR__ . '/src/Logger/src/ListenerRegistry.php', |
|
60 | - __DIR__ . '/src/Stempler/src/Transform/Merge/ExtendsParent.php', |
|
55 | + __DIR__.'/src/Boot/src/BootloadManager/Initializer.php', |
|
56 | + __DIR__.'/src/Stempler/src/Traverser.php', |
|
57 | + __DIR__.'/src/Prototype/src/NodeVisitors/LocateProperties.php', |
|
58 | + __DIR__.'/src/Prototype/src/NodeVisitors/RemoveTrait.php', |
|
59 | + __DIR__.'/src/Logger/src/ListenerRegistry.php', |
|
60 | + __DIR__.'/src/Stempler/src/Transform/Merge/ExtendsParent.php', |
|
61 | 61 | ], |
62 | 62 | RemoveExtraParametersRector::class => [ |
63 | - __DIR__ . '/src/Boot/src/BootloadManager/AbstractBootloadManager.php', |
|
63 | + __DIR__.'/src/Boot/src/BootloadManager/AbstractBootloadManager.php', |
|
64 | 64 | ], |
65 | 65 | RemoveUnusedPrivateMethodParameterRector::class => [ |
66 | - __DIR__ . '/src/Core/src/Internal/Factory.php', |
|
67 | - __DIR__ . '/src/Core/tests/InjectableTest.php', |
|
66 | + __DIR__.'/src/Core/src/Internal/Factory.php', |
|
67 | + __DIR__.'/src/Core/tests/InjectableTest.php', |
|
68 | 68 | ], |
69 | 69 | RemoveDoubleAssignRector::class => [ |
70 | - __DIR__ . '/src/Core/tests/Scope/FinalizeAttributeTest.php', |
|
70 | + __DIR__.'/src/Core/tests/Scope/FinalizeAttributeTest.php', |
|
71 | 71 | ], |
72 | 72 | RemoveUnusedVariableAssignRector::class => [ |
73 | - __DIR__ . '/src/Core/tests/ExceptionsTest.php', |
|
73 | + __DIR__.'/src/Core/tests/ExceptionsTest.php', |
|
74 | 74 | ], |
75 | 75 | RemoveDeadStmtRector::class => [ |
76 | - __DIR__ . '/src/Core/tests/ExceptionsTest.php', |
|
76 | + __DIR__.'/src/Core/tests/ExceptionsTest.php', |
|
77 | 77 | ], |
78 | 78 | |
79 | 79 | // to be enabled later for bc break 4.x |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | RemoveUnusedPromotedPropertyRector::class, |
83 | 83 | |
84 | 84 | // start with short open tag |
85 | - __DIR__ . '/src/Views/tests/fixtures/other/var.php', |
|
86 | - __DIR__ . '/tests/app/views/native.php', |
|
85 | + __DIR__.'/src/Views/tests/fixtures/other/var.php', |
|
86 | + __DIR__.'/tests/app/views/native.php', |
|
87 | 87 | |
88 | 88 | // example code for test |
89 | 89 | '*/Fixture/*', |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | '*/Stubs/*', |
94 | 94 | '*/tests/Classes/*', |
95 | 95 | '*/tests/Internal/*', |
96 | - __DIR__ . '/src/Console/tests/Configurator', |
|
96 | + __DIR__.'/src/Console/tests/Configurator', |
|
97 | 97 | |
98 | 98 | // cache |
99 | 99 | '*/runtime/cache/*', |
100 | 100 | |
101 | 101 | ReadOnlyPropertyRector::class => [ |
102 | 102 | // used by Configurator |
103 | - __DIR__ . '/src/Scaffolder/src/Command', |
|
103 | + __DIR__.'/src/Scaffolder/src/Command', |
|
104 | 104 | ], |
105 | 105 | ]) |
106 | 106 | ->withPhpSets(php81: true) |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function __construct( |
36 | 36 | private readonly string $defaultFilter = self::DEFAULT_FILTER, |
37 | 37 | private array $directives = [] |
38 | - ) { |
|
38 | + ){ |
|
39 | 39 | $this->traverser = new Traverser(); |
40 | 40 | $this->traverser->addVisitor($this); |
41 | 41 | } |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | |
56 | 56 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
57 | 57 | { |
58 | - if ($node instanceof Output) { |
|
58 | + if ($node instanceof Output){ |
|
59 | 59 | return $this->output($node, $ctx); |
60 | 60 | } |
61 | 61 | |
62 | - if ($node instanceof Directive) { |
|
62 | + if ($node instanceof Directive){ |
|
63 | 63 | return $this->directive($node); |
64 | 64 | } |
65 | 65 | |
66 | - if ($node instanceof Template) { |
|
66 | + if ($node instanceof Template){ |
|
67 | 67 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
68 | - if ($extendsTag instanceof Tag) { |
|
68 | + if ($extendsTag instanceof Tag){ |
|
69 | 69 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
70 | 70 | } |
71 | 71 | } |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | |
76 | 76 | private function directive(Directive $node): PHP |
77 | 77 | { |
78 | - foreach ($this->directives as $renderer) { |
|
78 | + foreach ($this->directives as $renderer){ |
|
79 | 79 | $result = $renderer->render($node); |
80 | - if ($result !== null) { |
|
80 | + if ($result !== null){ |
|
81 | 81 | return new PHP($result, \token_get_all($result), $node->getContext()); |
82 | 82 | } |
83 | 83 | } |
@@ -94,18 +94,18 @@ discard block |
||
94 | 94 | * In future this method can support context aware escaping based on tag location. |
95 | 95 | */ |
96 | 96 | |
97 | - if ($node->rawOutput) { |
|
98 | - $result = \sprintf('<?php echo %s; ?>', \trim((string) $node->body)); |
|
99 | - } else { |
|
97 | + if ($node->rawOutput){ |
|
98 | + $result = \sprintf('<?php echo %s; ?>', \trim((string)$node->body)); |
|
99 | + }else{ |
|
100 | 100 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
101 | 101 | |
102 | - $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string) $node->body)); |
|
102 | + $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string)$node->body)); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return new PHP( |
106 | 106 | $result, |
107 | 107 | \token_get_all($result), |
108 | - $node->getContext()->withValue(PHP::ORIGINAL_BODY, \trim((string) $node->body)) |
|
108 | + $node->getContext()->withValue(PHP::ORIGINAL_BODY, \trim((string)$node->body)) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -114,22 +114,22 @@ discard block |
||
114 | 114 | // only "interesting" nodes |
115 | 115 | $context = []; |
116 | 116 | |
117 | - foreach (\array_reverse($ctx->getScope()) as $node) { |
|
118 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
117 | + foreach (\array_reverse($ctx->getScope()) as $node){ |
|
118 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim){ |
|
119 | 119 | $context[] = $node; |
120 | 120 | } |
121 | 121 | |
122 | - if (\count($context) === 2) { |
|
122 | + if (\count($context) === 2){ |
|
123 | 123 | break; |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - if (\count($context) !== 2) { |
|
127 | + if (\count($context) !== 2){ |
|
128 | 128 | return $this->defaultFilter; |
129 | 129 | } |
130 | 130 | |
131 | 131 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
132 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
132 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script'){ |
|
133 | 133 | return \sprintf( |
134 | 134 | 'json_encode(%s, %s, %s)', |
135 | 135 | '%s', |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | // in on* and other attributes |
142 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
142 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style'){ |
|
143 | 143 | return \sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
144 | 144 | } |
145 | 145 |
@@ -55,17 +55,21 @@ discard block |
||
55 | 55 | |
56 | 56 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
57 | 57 | { |
58 | - if ($node instanceof Output) { |
|
58 | + if ($node instanceof Output) |
|
59 | + { |
|
59 | 60 | return $this->output($node, $ctx); |
60 | 61 | } |
61 | 62 | |
62 | - if ($node instanceof Directive) { |
|
63 | + if ($node instanceof Directive) |
|
64 | + { |
|
63 | 65 | return $this->directive($node); |
64 | 66 | } |
65 | 67 | |
66 | - if ($node instanceof Template) { |
|
68 | + if ($node instanceof Template) |
|
69 | + { |
|
67 | 70 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
68 | - if ($extendsTag instanceof Tag) { |
|
71 | + if ($extendsTag instanceof Tag) |
|
72 | + { |
|
69 | 73 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
70 | 74 | } |
71 | 75 | } |
@@ -75,9 +79,11 @@ discard block |
||
75 | 79 | |
76 | 80 | private function directive(Directive $node): PHP |
77 | 81 | { |
78 | - foreach ($this->directives as $renderer) { |
|
82 | + foreach ($this->directives as $renderer) |
|
83 | + { |
|
79 | 84 | $result = $renderer->render($node); |
80 | - if ($result !== null) { |
|
85 | + if ($result !== null) |
|
86 | + { |
|
81 | 87 | return new PHP($result, \token_get_all($result), $node->getContext()); |
82 | 88 | } |
83 | 89 | } |
@@ -94,9 +100,12 @@ discard block |
||
94 | 100 | * In future this method can support context aware escaping based on tag location. |
95 | 101 | */ |
96 | 102 | |
97 | - if ($node->rawOutput) { |
|
103 | + if ($node->rawOutput) |
|
104 | + { |
|
98 | 105 | $result = \sprintf('<?php echo %s; ?>', \trim((string) $node->body)); |
99 | - } else { |
|
106 | + } |
|
107 | + else |
|
108 | + { |
|
100 | 109 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
101 | 110 | |
102 | 111 | $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string) $node->body)); |
@@ -114,22 +123,27 @@ discard block |
||
114 | 123 | // only "interesting" nodes |
115 | 124 | $context = []; |
116 | 125 | |
117 | - foreach (\array_reverse($ctx->getScope()) as $node) { |
|
118 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
126 | + foreach (\array_reverse($ctx->getScope()) as $node) |
|
127 | + { |
|
128 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) |
|
129 | + { |
|
119 | 130 | $context[] = $node; |
120 | 131 | } |
121 | 132 | |
122 | - if (\count($context) === 2) { |
|
133 | + if (\count($context) === 2) |
|
134 | + { |
|
123 | 135 | break; |
124 | 136 | } |
125 | 137 | } |
126 | 138 | |
127 | - if (\count($context) !== 2) { |
|
139 | + if (\count($context) !== 2) |
|
140 | + { |
|
128 | 141 | return $this->defaultFilter; |
129 | 142 | } |
130 | 143 | |
131 | 144 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
132 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
145 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') |
|
146 | + { |
|
133 | 147 | return \sprintf( |
134 | 148 | 'json_encode(%s, %s, %s)', |
135 | 149 | '%s', |
@@ -139,7 +153,8 @@ discard block |
||
139 | 153 | } |
140 | 154 | |
141 | 155 | // in on* and other attributes |
142 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
156 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') |
|
157 | + { |
|
143 | 158 | return \sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
144 | 159 | } |
145 | 160 |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | |
23 | 23 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
24 | 24 | { |
25 | - if ($node instanceof Tag) { |
|
25 | + if ($node instanceof Tag){ |
|
26 | 26 | return $this->makeBlock($node); |
27 | 27 | } |
28 | 28 | |
29 | - if ($node instanceof Inline) { |
|
29 | + if ($node instanceof Inline){ |
|
30 | 30 | $block = new Block($node->name, $node->getContext()); |
31 | - if ($node->value !== null) { |
|
31 | + if ($node->value !== null){ |
|
32 | 32 | $block->nodes[] = new Raw($node->value); |
33 | 33 | } |
34 | 34 | |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | private function makeBlock(Tag $node): ?NodeInterface |
50 | 50 | { |
51 | 51 | $name = null; |
52 | - foreach ($this->prefix as $prefix) { |
|
53 | - if (\str_starts_with($node->name, (string) $prefix)) { |
|
54 | - $name = \substr($node->name, \strlen((string) $prefix)); |
|
52 | + foreach ($this->prefix as $prefix){ |
|
53 | + if (\str_starts_with($node->name, (string)$prefix)){ |
|
54 | + $name = \substr($node->name, \strlen((string)$prefix)); |
|
55 | 55 | break; |
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | - if ($name === null) { |
|
59 | + if ($name === null){ |
|
60 | 60 | return null; |
61 | 61 | } |
62 | 62 |
@@ -22,13 +22,16 @@ discard block |
||
22 | 22 | |
23 | 23 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
24 | 24 | { |
25 | - if ($node instanceof Tag) { |
|
25 | + if ($node instanceof Tag) |
|
26 | + { |
|
26 | 27 | return $this->makeBlock($node); |
27 | 28 | } |
28 | 29 | |
29 | - if ($node instanceof Inline) { |
|
30 | + if ($node instanceof Inline) |
|
31 | + { |
|
30 | 32 | $block = new Block($node->name, $node->getContext()); |
31 | - if ($node->value !== null) { |
|
33 | + if ($node->value !== null) |
|
34 | + { |
|
32 | 35 | $block->nodes[] = new Raw($node->value); |
33 | 36 | } |
34 | 37 | |
@@ -49,14 +52,17 @@ discard block |
||
49 | 52 | private function makeBlock(Tag $node): ?NodeInterface |
50 | 53 | { |
51 | 54 | $name = null; |
52 | - foreach ($this->prefix as $prefix) { |
|
53 | - if (\str_starts_with($node->name, (string) $prefix)) { |
|
55 | + foreach ($this->prefix as $prefix) |
|
56 | + { |
|
57 | + if (\str_starts_with($node->name, (string) $prefix)) |
|
58 | + { |
|
54 | 59 | $name = \substr($node->name, \strlen((string) $prefix)); |
55 | 60 | break; |
56 | 61 | } |
57 | 62 | } |
58 | 63 | |
59 | - if ($name === null) { |
|
64 | + if ($name === null) |
|
65 | + { |
|
60 | 66 | return null; |
61 | 67 | } |
62 | 68 |
@@ -22,16 +22,16 @@ |
||
22 | 22 | public string $path, |
23 | 23 | ?string $prefix, |
24 | 24 | Context $context = null |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | $this->prefix = $prefix ?? \substr($path, \strrpos($path, '/') + 1); |
27 | 27 | $this->context = $context; |
28 | 28 | } |
29 | 29 | |
30 | 30 | public function resolve(Builder $builder, string $name): ?Template |
31 | 31 | { |
32 | - $path = \substr($name, \strlen((string) $this->prefix) + 1); |
|
32 | + $path = \substr($name, \strlen((string)$this->prefix) + 1); |
|
33 | 33 | $path = \str_replace('.', DIRECTORY_SEPARATOR, $path); |
34 | 34 | |
35 | - return $builder->load($this->path . DIRECTORY_SEPARATOR . $path); |
|
35 | + return $builder->load($this->path.DIRECTORY_SEPARATOR.$path); |
|
36 | 36 | } |
37 | 37 | } |
@@ -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,23 +147,23 @@ 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) { |
|
166 | - $name = \stripcslashes(\substr((string) $token[1], 1, -1)); |
|
165 | + if ($name === null){ |
|
166 | + $name = \stripcslashes(\substr((string)$token[1], 1, -1)); |
|
167 | 167 | } |
168 | 168 | $value .= $token[1]; |
169 | 169 | break; |
@@ -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((string) $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 | } |
@@ -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 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | return $this->exportValue($node); |
138 | 138 | |
139 | 139 | case $node instanceof Output: |
140 | - return \trim((string) $node->body); |
|
140 | + return \trim((string)$node->body); |
|
141 | 141 | |
142 | 142 | case $node instanceof PHP: |
143 | 143 | return $node->getContext()?->getValue(PHP::ORIGINAL_BODY) |
@@ -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 | } |
@@ -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; |
@@ -21,20 +21,20 @@ discard block |
||
21 | 21 | private readonly GlobalVariablesInterface $globalVariables, |
22 | 22 | FactoryInterface $factory, |
23 | 23 | private ContextInterface $context = new ViewContext() |
24 | - ) { |
|
24 | + ){ |
|
25 | 25 | $this->loader = $factory->make(LoaderInterface::class, [ |
26 | 26 | 'namespaces' => $config->getNamespaces(), |
27 | 27 | ]); |
28 | 28 | |
29 | - foreach ($this->config->getDependencies() as $dependency) { |
|
29 | + foreach ($this->config->getDependencies() as $dependency){ |
|
30 | 30 | $this->addDependency($dependency->resolve($factory)); |
31 | 31 | } |
32 | 32 | |
33 | - foreach ($this->config->getEngines() as $engine) { |
|
33 | + foreach ($this->config->getEngines() as $engine){ |
|
34 | 34 | $this->addEngine($engine->resolve($factory)); |
35 | 35 | } |
36 | 36 | |
37 | - if ($this->config->isCacheEnabled()) { |
|
37 | + if ($this->config->isCacheEnabled()){ |
|
38 | 38 | $this->cache = new ViewCache(); |
39 | 39 | } |
40 | 40 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | // Rotate all possible context variants and warm up cache |
93 | 93 | $generator = new ContextGenerator($this->context); |
94 | - foreach ($generator->generate() as $context) { |
|
94 | + foreach ($generator->generate() as $context){ |
|
95 | 95 | $engine->reset($path, $context); |
96 | 96 | $engine->compile($path, $context); |
97 | 97 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | // Rotate all possible context variants and warm up cache |
110 | 110 | $generator = new ContextGenerator($this->context); |
111 | - foreach ($generator->generate() as $context) { |
|
111 | + foreach ($generator->generate() as $context){ |
|
112 | 112 | $engine->reset($path, $context); |
113 | 113 | } |
114 | 114 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function get(string $path): ViewInterface |
122 | 122 | { |
123 | - if ($this->cache?->has($this->context, $path)) { |
|
123 | + if ($this->cache?->has($this->context, $path)){ |
|
124 | 124 | return $this->cache->get($this->context, $path); |
125 | 125 | } |
126 | 126 | |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | */ |
149 | 149 | private function findEngine(string $path): EngineInterface |
150 | 150 | { |
151 | - foreach ($this->engines as $engine) { |
|
152 | - if ($engine->getLoader()->exists($path)) { |
|
151 | + foreach ($this->engines as $engine){ |
|
152 | + if ($engine->getLoader()->exists($path)){ |
|
153 | 153 | return $engine; |
154 | 154 | } |
155 | 155 | } |