@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | { |
15 | 15 | $core = TestCore::create([ |
16 | 16 | 'root' => __DIR__, |
17 | - 'config' => __DIR__ . '/config' |
|
17 | + 'config' => __DIR__.'/config' |
|
18 | 18 | ])->run(); |
19 | 19 | |
20 | 20 | /** @var TestConfig $config */ |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | { |
28 | 28 | $core = TestCore::create([ |
29 | 29 | 'root' => __DIR__, |
30 | - 'config' => __DIR__ . '/config', |
|
30 | + 'config' => __DIR__.'/config', |
|
31 | 31 | ])->run(); |
32 | 32 | |
33 | 33 | /** @var ConfiguratorInterface $configurator */ |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | public function testInvalidInjector(): void |
41 | 41 | { |
42 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
42 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
43 | 43 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
44 | 44 | $this->expectException(InjectionException::class); |
45 | 45 | $this->expectExceptionMessage($excepted); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | public function testInvalidRuntimeInjector(): void |
67 | 67 | { |
68 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
68 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
69 | 69 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
70 | 70 | $this->expectException(InjectionException::class); |
71 | 71 | $this->expectExceptionMessage($excepted); |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | public function testExtendedInjectorAnonClassObjectParam(): void |
204 | 204 | { |
205 | 205 | $container = new Container(); |
206 | - $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface { |
|
207 | - public function createInjection(\ReflectionClass $class, object|string|null $context = null): object |
|
206 | + $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface{ |
|
207 | + public function createInjection(\ReflectionClass $class, object | string | null $context = null): object |
|
208 | 208 | { |
209 | 209 | return (object)['context' => $context]; |
210 | 210 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | public function testExtendedInjectorAnonClassMixedParam(): void |
220 | 220 | { |
221 | 221 | $container = new Container(); |
222 | - $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface { |
|
222 | + $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface{ |
|
223 | 223 | public function createInjection(\ReflectionClass $class, mixed $context = null): object |
224 | 224 | { |
225 | 225 | return (object)['context' => $context]; |
@@ -24,23 +24,23 @@ discard block |
||
24 | 24 | |
25 | 25 | public function __toString(): string |
26 | 26 | { |
27 | - try { |
|
27 | + try{ |
|
28 | 28 | return $this->getContents(); |
29 | - } catch (\Exception) { |
|
29 | + }catch (\Exception){ |
|
30 | 30 | return ''; |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | 34 | public function close(): void |
35 | 35 | { |
36 | - if ($this->stream !== null) { |
|
36 | + if ($this->stream !== null){ |
|
37 | 37 | $this->detach(); |
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function detach() |
42 | 42 | { |
43 | - if ($this->stream === null) { |
|
43 | + if ($this->stream === null){ |
|
44 | 44 | return null; |
45 | 45 | } |
46 | 46 | $this->stream = null; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | public function rewind(): void |
80 | 80 | { |
81 | - if ($this->stream !== null) { |
|
81 | + if ($this->stream !== null){ |
|
82 | 82 | $this->stream->rewind(); |
83 | 83 | } |
84 | 84 | $this->caret = 0; |
@@ -102,26 +102,26 @@ discard block |
||
102 | 102 | |
103 | 103 | public function read($length): string |
104 | 104 | { |
105 | - if (!$this->readable) { |
|
105 | + if (!$this->readable){ |
|
106 | 106 | throw new RuntimeException('Cannot read from non-readable stream.'); |
107 | 107 | } |
108 | - if ($this->stream === null) { |
|
108 | + if ($this->stream === null){ |
|
109 | 109 | throw new RuntimeException('Cannot read from detached stream.'); |
110 | 110 | } |
111 | - do { |
|
112 | - if ($this->started) { |
|
111 | + do{ |
|
112 | + if ($this->started){ |
|
113 | 113 | $read = (string)$this->stream->send(null); |
114 | - } else { |
|
114 | + }else{ |
|
115 | 115 | $this->started = true; |
116 | 116 | $read = (string)$this->stream->current(); |
117 | 117 | } |
118 | - if (!$this->stream->valid()) { |
|
118 | + if (!$this->stream->valid()){ |
|
119 | 119 | $read .= $this->stream->getReturn(); |
120 | 120 | break; |
121 | 121 | } |
122 | - } while ($read === ''); |
|
122 | + }while ($read === ''); |
|
123 | 123 | $this->caret += \strlen($read); |
124 | - if (!$this->stream->valid()) { |
|
124 | + if (!$this->stream->valid()){ |
|
125 | 125 | $this->size = $this->caret; |
126 | 126 | } |
127 | 127 | return $read; |
@@ -129,19 +129,19 @@ discard block |
||
129 | 129 | |
130 | 130 | public function getContents(): string |
131 | 131 | { |
132 | - if ($this->stream === null) { |
|
132 | + if ($this->stream === null){ |
|
133 | 133 | throw new RuntimeException('Unable to read stream contents.'); |
134 | 134 | } |
135 | 135 | $content = ''; |
136 | - do { |
|
136 | + do{ |
|
137 | 137 | $content .= $this->read(PHP_INT_MAX); |
138 | - } while ($this->stream->valid()); |
|
138 | + }while ($this->stream->valid()); |
|
139 | 139 | return $content; |
140 | 140 | } |
141 | 141 | |
142 | 142 | public function getMetadata($key = null) |
143 | 143 | { |
144 | - if ($this->stream === null) { |
|
144 | + if ($this->stream === null){ |
|
145 | 145 | return $key ? null : []; |
146 | 146 | } |
147 | 147 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'eof' => $this->eof(), |
151 | 151 | ]; |
152 | 152 | |
153 | - if (null === $key) { |
|
153 | + if (null === $key){ |
|
154 | 154 | return $meta; |
155 | 155 | } |
156 | 156 |
@@ -24,23 +24,28 @@ discard block |
||
24 | 24 | |
25 | 25 | public function __toString(): string |
26 | 26 | { |
27 | - try { |
|
27 | + try |
|
28 | + { |
|
28 | 29 | return $this->getContents(); |
29 | - } catch (\Exception) { |
|
30 | + } |
|
31 | + catch (\Exception) |
|
32 | + { |
|
30 | 33 | return ''; |
31 | 34 | } |
32 | 35 | } |
33 | 36 | |
34 | 37 | public function close(): void |
35 | 38 | { |
36 | - if ($this->stream !== null) { |
|
39 | + if ($this->stream !== null) |
|
40 | + { |
|
37 | 41 | $this->detach(); |
38 | 42 | } |
39 | 43 | } |
40 | 44 | |
41 | 45 | public function detach() |
42 | 46 | { |
43 | - if ($this->stream === null) { |
|
47 | + if ($this->stream === null) |
|
48 | + { |
|
44 | 49 | return null; |
45 | 50 | } |
46 | 51 | $this->stream = null; |
@@ -78,7 +83,8 @@ discard block |
||
78 | 83 | |
79 | 84 | public function rewind(): void |
80 | 85 | { |
81 | - if ($this->stream !== null) { |
|
86 | + if ($this->stream !== null) |
|
87 | + { |
|
82 | 88 | $this->stream->rewind(); |
83 | 89 | } |
84 | 90 | $this->caret = 0; |
@@ -102,26 +108,34 @@ discard block |
||
102 | 108 | |
103 | 109 | public function read($length): string |
104 | 110 | { |
105 | - if (!$this->readable) { |
|
111 | + if (!$this->readable) |
|
112 | + { |
|
106 | 113 | throw new RuntimeException('Cannot read from non-readable stream.'); |
107 | 114 | } |
108 | - if ($this->stream === null) { |
|
115 | + if ($this->stream === null) |
|
116 | + { |
|
109 | 117 | throw new RuntimeException('Cannot read from detached stream.'); |
110 | 118 | } |
111 | - do { |
|
112 | - if ($this->started) { |
|
119 | + do |
|
120 | + { |
|
121 | + if ($this->started) |
|
122 | + { |
|
113 | 123 | $read = (string)$this->stream->send(null); |
114 | - } else { |
|
124 | + } |
|
125 | + else |
|
126 | + { |
|
115 | 127 | $this->started = true; |
116 | 128 | $read = (string)$this->stream->current(); |
117 | 129 | } |
118 | - if (!$this->stream->valid()) { |
|
130 | + if (!$this->stream->valid()) |
|
131 | + { |
|
119 | 132 | $read .= $this->stream->getReturn(); |
120 | 133 | break; |
121 | 134 | } |
122 | 135 | } while ($read === ''); |
123 | 136 | $this->caret += \strlen($read); |
124 | - if (!$this->stream->valid()) { |
|
137 | + if (!$this->stream->valid()) |
|
138 | + { |
|
125 | 139 | $this->size = $this->caret; |
126 | 140 | } |
127 | 141 | return $read; |
@@ -129,11 +143,13 @@ discard block |
||
129 | 143 | |
130 | 144 | public function getContents(): string |
131 | 145 | { |
132 | - if ($this->stream === null) { |
|
146 | + if ($this->stream === null) |
|
147 | + { |
|
133 | 148 | throw new RuntimeException('Unable to read stream contents.'); |
134 | 149 | } |
135 | 150 | $content = ''; |
136 | - do { |
|
151 | + do |
|
152 | + { |
|
137 | 153 | $content .= $this->read(PHP_INT_MAX); |
138 | 154 | } while ($this->stream->valid()); |
139 | 155 | return $content; |
@@ -141,7 +157,8 @@ discard block |
||
141 | 157 | |
142 | 158 | public function getMetadata($key = null) |
143 | 159 | { |
144 | - if ($this->stream === null) { |
|
160 | + if ($this->stream === null) |
|
161 | + { |
|
145 | 162 | return $key ? null : []; |
146 | 163 | } |
147 | 164 | |
@@ -150,7 +167,8 @@ discard block |
||
150 | 167 | 'eof' => $this->eof(), |
151 | 168 | ]; |
152 | 169 | |
153 | - if (null === $key) { |
|
170 | + if (null === $key) |
|
171 | + { |
|
154 | 172 | return $meta; |
155 | 173 | } |
156 | 174 |
@@ -20,20 +20,20 @@ |
||
20 | 20 | |
21 | 21 | public function __construct( |
22 | 22 | #[Proxy] protected InvokerInterface $invoker, |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function handle(string $name, string $id, mixed $payload, array $headers = []): void |
27 | 27 | { |
28 | - try { |
|
28 | + try{ |
|
29 | 29 | $params = ['payload' => $payload, 'id' => $id, 'headers' => $headers]; |
30 | 30 | |
31 | - if (\is_array($payload)) { |
|
31 | + if (\is_array($payload)){ |
|
32 | 32 | $params = \array_merge($params, $payload); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $this->invoker->invoke([$this, $this->getHandlerMethod()], $params); |
36 | - } catch (\Throwable $e) { |
|
36 | + }catch (\Throwable $e){ |
|
37 | 37 | $message = \sprintf('[%s] %s', static::class, $e->getMessage()); |
38 | 38 | throw new JobException($message, (int)$e->getCode(), $e); |
39 | 39 | } |
@@ -25,15 +25,19 @@ |
||
25 | 25 | |
26 | 26 | public function handle(string $name, string $id, mixed $payload, array $headers = []): void |
27 | 27 | { |
28 | - try { |
|
28 | + try |
|
29 | + { |
|
29 | 30 | $params = ['payload' => $payload, 'id' => $id, 'headers' => $headers]; |
30 | 31 | |
31 | - if (\is_array($payload)) { |
|
32 | + if (\is_array($payload)) |
|
33 | + { |
|
32 | 34 | $params = \array_merge($params, $payload); |
33 | 35 | } |
34 | 36 | |
35 | 37 | $this->invoker->invoke([$this, $this->getHandlerMethod()], $params); |
36 | - } catch (\Throwable $e) { |
|
38 | + } |
|
39 | + catch (\Throwable $e) |
|
40 | + { |
|
37 | 41 | $message = \sprintf('[%s] %s', static::class, $e->getMessage()); |
38 | 42 | throw new JobException($message, (int)$e->getCode(), $e); |
39 | 43 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | { |
23 | 23 | public function __construct( |
24 | 24 | private readonly QueueInterface $connection, |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | string $action, |
35 | 35 | array $parameters = ['options' => null, 'payload' => []], |
36 | 36 | ): string { |
37 | - if ($parameters['options'] === null) { |
|
37 | + if ($parameters['options'] === null){ |
|
38 | 38 | $parameters['options'] = new Options(); |
39 | 39 | } |
40 | 40 | |
41 | 41 | $tracer = $this->getTracer(); |
42 | 42 | |
43 | - if (\method_exists($parameters['options'], 'withHeader')) { |
|
44 | - foreach ($tracer->getContext() as $key => $data) { |
|
43 | + if (\method_exists($parameters['options'], 'withHeader')){ |
|
44 | + foreach ($tracer->getContext() as $key => $data){ |
|
45 | 45 | $parameters['options'] = $parameters['options']->withHeader($key, $data); |
46 | 46 | } |
47 | 47 | } |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | |
71 | 71 | private function getTracer(): TracerInterface |
72 | 72 | { |
73 | - try { |
|
73 | + try{ |
|
74 | 74 | return ContainerScope::getContainer()->get(TracerInterface::class); |
75 | - } catch (\Throwable) { |
|
75 | + }catch (\Throwable){ |
|
76 | 76 | return new NullTracer(); |
77 | 77 | } |
78 | 78 | } |
@@ -34,14 +34,17 @@ discard block |
||
34 | 34 | string $action, |
35 | 35 | array $parameters = ['options' => null, 'payload' => []], |
36 | 36 | ): string { |
37 | - if ($parameters['options'] === null) { |
|
37 | + if ($parameters['options'] === null) |
|
38 | + { |
|
38 | 39 | $parameters['options'] = new Options(); |
39 | 40 | } |
40 | 41 | |
41 | 42 | $tracer = $this->getTracer(); |
42 | 43 | |
43 | - if (\method_exists($parameters['options'], 'withHeader')) { |
|
44 | - foreach ($tracer->getContext() as $key => $data) { |
|
44 | + if (\method_exists($parameters['options'], 'withHeader')) |
|
45 | + { |
|
46 | + foreach ($tracer->getContext() as $key => $data) |
|
47 | + { |
|
45 | 48 | $parameters['options'] = $parameters['options']->withHeader($key, $data); |
46 | 49 | } |
47 | 50 | } |
@@ -70,9 +73,12 @@ discard block |
||
70 | 73 | |
71 | 74 | private function getTracer(): TracerInterface |
72 | 75 | { |
73 | - try { |
|
76 | + try |
|
77 | + { |
|
74 | 78 | return ContainerScope::getContainer()->get(TracerInterface::class); |
75 | - } catch (\Throwable) { |
|
79 | + } |
|
80 | + catch (\Throwable) |
|
81 | + { |
|
76 | 82 | return new NullTracer(); |
77 | 83 | } |
78 | 84 | } |
@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | |
42 | 42 | public function testHandleWithHandleMethod(): void |
43 | 43 | { |
44 | - $object = new class($this) { |
|
44 | + $object = new class($this) |
|
45 | + { |
|
45 | 46 | public function __construct(private $testCase) |
46 | 47 | { |
47 | 48 | } |
@@ -61,7 +62,8 @@ discard block |
||
61 | 62 | |
62 | 63 | public function testHandleWithInvokeMethod(): void |
63 | 64 | { |
64 | - $object = new class($this) { |
|
65 | + $object = new class($this) |
|
66 | + { |
|
65 | 67 | public function __construct(private $testCase) |
66 | 68 | { |
67 | 69 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function __construct( |
39 | 39 | protected ResolverInterface $resolver |
40 | - ) { |
|
40 | + ){ |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -48,20 +48,20 @@ discard block |
||
48 | 48 | $parameters = \compact('actor', 'permission', 'context') + $context; |
49 | 49 | |
50 | 50 | //Mounting aliases |
51 | - foreach (static::ALIASES as $target => $alias) { |
|
51 | + foreach (static::ALIASES as $target => $alias){ |
|
52 | 52 | $parameters[$target] = $parameters[$alias]; |
53 | 53 | } |
54 | 54 | |
55 | - try { |
|
55 | + try{ |
|
56 | 56 | $method = new \ReflectionMethod($this, static::CHECK_METHOD); |
57 | - } catch (\ReflectionException $e) { |
|
57 | + }catch (\ReflectionException $e){ |
|
58 | 58 | throw new RuleException($e->getMessage(), $e->getCode(), $e); |
59 | 59 | } |
60 | 60 | |
61 | - try { |
|
61 | + try{ |
|
62 | 62 | return $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); |
63 | - } catch (\Throwable $e) { |
|
64 | - throw new RuleException(\sprintf('[%s] %s', static::class, $e->getMessage()), (int) $e->getCode(), $e); |
|
63 | + }catch (\Throwable $e){ |
|
64 | + throw new RuleException(\sprintf('[%s] %s', static::class, $e->getMessage()), (int)$e->getCode(), $e); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | } |
@@ -48,19 +48,26 @@ |
||
48 | 48 | $parameters = \compact('actor', 'permission', 'context') + $context; |
49 | 49 | |
50 | 50 | //Mounting aliases |
51 | - foreach (static::ALIASES as $target => $alias) { |
|
51 | + foreach (static::ALIASES as $target => $alias) |
|
52 | + { |
|
52 | 53 | $parameters[$target] = $parameters[$alias]; |
53 | 54 | } |
54 | 55 | |
55 | - try { |
|
56 | + try |
|
57 | + { |
|
56 | 58 | $method = new \ReflectionMethod($this, static::CHECK_METHOD); |
57 | - } catch (\ReflectionException $e) { |
|
59 | + } |
|
60 | + catch (\ReflectionException $e) |
|
61 | + { |
|
58 | 62 | throw new RuleException($e->getMessage(), $e->getCode(), $e); |
59 | 63 | } |
60 | 64 | |
61 | - try { |
|
65 | + try |
|
66 | + { |
|
62 | 67 | return $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); |
63 | - } catch (\Throwable $e) { |
|
68 | + } |
|
69 | + catch (\Throwable $e) |
|
70 | + { |
|
64 | 71 | throw new RuleException(\sprintf('[%s] %s', static::class, $e->getMessage()), (int) $e->getCode(), $e); |
65 | 72 | } |
66 | 73 | } |
@@ -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 |