@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | private readonly Verbosity $verbosity, |
20 | 20 | private readonly ExceptionRendererInterface $renderer, |
21 | 21 | private readonly FilesInterface $files |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function create(\Throwable $e): SnapshotInterface |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | { |
52 | 52 | $finder = new Finder(); |
53 | 53 | $finder->in($this->directory)->sort( |
54 | - static fn (SplFileInfo $a, SplFileInfo $b): int|float => $b->getMTime() - $a->getMTime() |
|
54 | + static fn (SplFileInfo $a, SplFileInfo $b): int | float => $b->getMTime() - $a->getMTime() |
|
55 | 55 | ); |
56 | 56 | |
57 | 57 | $count = 0; |
58 | - foreach ($finder as $file) { |
|
58 | + foreach ($finder as $file){ |
|
59 | 59 | $count++; |
60 | - if ($count > $this->maxFiles) { |
|
61 | - try { |
|
60 | + if ($count > $this->maxFiles){ |
|
61 | + try{ |
|
62 | 62 | $this->files->delete($file->getRealPath()); |
63 | - } catch (FilesException) { |
|
63 | + }catch (FilesException){ |
|
64 | 64 | // ignore |
65 | 65 | } |
66 | 66 | } |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | $queue = m::mock(QueueInterface::class) |
25 | 25 | ); |
26 | 26 | |
27 | - if (!\is_array($payload)) { |
|
27 | + if (!\is_array($payload)){ |
|
28 | 28 | $this->markTestIncomplete('QueueInterface does not support non-array payloads'); |
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $queue->shouldReceive('push')->once() |
33 | - ->withArgs(fn(string $name, mixed $p = [], ?OptionsInterface $options = null): bool => $name === 'foo' |
|
33 | + ->withArgs(fn(string $name, mixed $p = [], ?OptionsInterface $options = null) : bool => $name === 'foo' |
|
34 | 34 | && $payload === $p |
35 | 35 | && $options instanceof Options, |
36 | 36 | ); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $queue = m::mock(QueueInterface::class) |
50 | 50 | ); |
51 | 51 | |
52 | - if (!\is_array($payload)) { |
|
52 | + if (!\is_array($payload)){ |
|
53 | 53 | $this->markTestIncomplete('QueueInterface does not support non-array payloads'); |
54 | 54 | return; |
55 | 55 | } |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | $tracer->shouldReceive('trace')->once()->andReturnUsing(fn($name, $callback) => $callback()); |
81 | 81 | |
82 | 82 | $queue->shouldReceive('push')->once() |
83 | - ->withArgs(fn(string $name, array $payload = [], ?OptionsInterface $options = null): bool => $name === 'foo' |
|
83 | + ->withArgs(fn(string $name, array $payload = [], ?OptionsInterface $options = null) : bool => $name === 'foo' |
|
84 | 84 | && $payload === ['baz' => 'baf'] |
85 | 85 | && $options->getHeader('foo') === ['bar']); |
86 | 86 | |
87 | - ContainerScope::runScope($container, function() use($core): void { |
|
87 | + ContainerScope::runScope($container, function () use($core): void { |
|
88 | 88 | $core->callAction('foo', 'bar', [ |
89 | 89 | 'id' => 'job-id', |
90 | 90 | 'payload' => ['baz' => 'baf'], |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | $tracer->shouldNotReceive('getContext'); |
104 | 104 | |
105 | 105 | $queue->shouldReceive('push')->once() |
106 | - ->withArgs(fn(string $name, array $payload = [], ?OptionsInterface $options = null): bool => $name === 'foo' |
|
106 | + ->withArgs(fn(string $name, array $payload = [], ?OptionsInterface $options = null) : bool => $name === 'foo' |
|
107 | 107 | && $payload === ['baz' => 'baf'] |
108 | 108 | && $options !== null); |
109 | 109 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct( |
26 | 26 | private readonly CookiesConfig $config, |
27 | 27 | private readonly EncryptionInterface $encryption |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function process(Request $request, RequestHandlerInterface $handler): Response |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | { |
51 | 51 | $cookies = $request->getCookieParams(); |
52 | 52 | |
53 | - foreach ($cookies as $name => $cookie) { |
|
54 | - if (!$this->isProtected($name)) { |
|
53 | + foreach ($cookies as $name => $cookie){ |
|
54 | + if (!$this->isProtected($name)){ |
|
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | protected function isProtected(string $cookie): bool |
68 | 68 | { |
69 | - if (\in_array($cookie, $this->config->getExcludedCookies(), true)) { |
|
69 | + if (\in_array($cookie, $this->config->getExcludedCookies(), true)){ |
|
70 | 70 | //Excluded |
71 | 71 | return false; |
72 | 72 | } |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function packCookies(Response $response, CookieQueue $queue): Response |
83 | 83 | { |
84 | - if (empty($queue->getScheduled())) { |
|
84 | + if (empty($queue->getScheduled())){ |
|
85 | 85 | return $response; |
86 | 86 | } |
87 | 87 | |
88 | 88 | $cookies = $response->getHeader('Set-Cookie'); |
89 | 89 | |
90 | - foreach ($queue->getScheduled() as $cookie) { |
|
91 | - if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) { |
|
90 | + foreach ($queue->getScheduled() as $cookie){ |
|
91 | + if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())){ |
|
92 | 92 | $cookies[] = $cookie->createHeader(); |
93 | 93 | continue; |
94 | 94 | } |
@@ -99,28 +99,28 @@ discard block |
||
99 | 99 | return $response->withHeader('Set-Cookie', $cookies); |
100 | 100 | } |
101 | 101 | |
102 | - private function decodeCookie(array|string $cookie): mixed |
|
102 | + private function decodeCookie(array | string $cookie): mixed |
|
103 | 103 | { |
104 | - try { |
|
105 | - if (\is_array($cookie)) { |
|
106 | - return \array_map(fn (array|string $cookie): mixed => $this->decodeCookie($cookie), $cookie); |
|
104 | + try{ |
|
105 | + if (\is_array($cookie)){ |
|
106 | + return \array_map(fn (array | string $cookie): mixed => $this->decodeCookie($cookie), $cookie); |
|
107 | 107 | } |
108 | - } catch (DecryptException) { |
|
108 | + }catch (DecryptException){ |
|
109 | 109 | return null; |
110 | 110 | } |
111 | 111 | |
112 | - switch ($this->config->getProtectionMethod()) { |
|
112 | + switch ($this->config->getProtectionMethod()){ |
|
113 | 113 | case CookiesConfig::COOKIE_ENCRYPT: |
114 | - try { |
|
114 | + try{ |
|
115 | 115 | return $this->encryption->getEncrypter()->decrypt($cookie); |
116 | - } catch (DecryptException) { |
|
116 | + }catch (DecryptException){ |
|
117 | 117 | } |
118 | 118 | return null; |
119 | 119 | case CookiesConfig::COOKIE_HMAC: |
120 | 120 | $hmac = \substr($cookie, -1 * CookiesConfig::MAC_LENGTH); |
121 | 121 | $value = \substr($cookie, 0, \strlen($cookie) - \strlen($hmac)); |
122 | 122 | |
123 | - if (\hash_equals($this->hmacSign($value), $hmac)) { |
|
123 | + if (\hash_equals($this->hmacSign($value), $hmac)){ |
|
124 | 124 | return $value; |
125 | 125 | } |
126 | 126 | } |
@@ -143,13 +143,13 @@ discard block |
||
143 | 143 | private function encodeCookie(Cookie $cookie): Cookie |
144 | 144 | { |
145 | 145 | $value = $cookie->getValue() ?? ''; |
146 | - if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) { |
|
146 | + if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT){ |
|
147 | 147 | $encryptor = $this->encryption->getEncrypter(); |
148 | 148 | |
149 | 149 | return $cookie->withValue($encryptor->encrypt($value)); |
150 | 150 | } |
151 | 151 | |
152 | 152 | //VALUE.HMAC |
153 | - return $cookie->withValue($value . $this->hmacSign($value)); |
|
153 | + return $cookie->withValue($value.$this->hmacSign($value)); |
|
154 | 154 | } |
155 | 155 | } |
@@ -50,8 +50,10 @@ discard block |
||
50 | 50 | { |
51 | 51 | $cookies = $request->getCookieParams(); |
52 | 52 | |
53 | - foreach ($cookies as $name => $cookie) { |
|
54 | - if (!$this->isProtected($name)) { |
|
53 | + foreach ($cookies as $name => $cookie) |
|
54 | + { |
|
55 | + if (!$this->isProtected($name)) |
|
56 | + { |
|
55 | 57 | continue; |
56 | 58 | } |
57 | 59 | |
@@ -66,7 +68,8 @@ discard block |
||
66 | 68 | */ |
67 | 69 | protected function isProtected(string $cookie): bool |
68 | 70 | { |
69 | - if (\in_array($cookie, $this->config->getExcludedCookies(), true)) { |
|
71 | + if (\in_array($cookie, $this->config->getExcludedCookies(), true)) |
|
72 | + { |
|
70 | 73 | //Excluded |
71 | 74 | return false; |
72 | 75 | } |
@@ -81,14 +84,17 @@ discard block |
||
81 | 84 | */ |
82 | 85 | protected function packCookies(Response $response, CookieQueue $queue): Response |
83 | 86 | { |
84 | - if (empty($queue->getScheduled())) { |
|
87 | + if (empty($queue->getScheduled())) |
|
88 | + { |
|
85 | 89 | return $response; |
86 | 90 | } |
87 | 91 | |
88 | 92 | $cookies = $response->getHeader('Set-Cookie'); |
89 | 93 | |
90 | - foreach ($queue->getScheduled() as $cookie) { |
|
91 | - if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) { |
|
94 | + foreach ($queue->getScheduled() as $cookie) |
|
95 | + { |
|
96 | + if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) |
|
97 | + { |
|
92 | 98 | $cookies[] = $cookie->createHeader(); |
93 | 99 | continue; |
94 | 100 | } |
@@ -101,26 +107,35 @@ discard block |
||
101 | 107 | |
102 | 108 | private function decodeCookie(array|string $cookie): mixed |
103 | 109 | { |
104 | - try { |
|
105 | - if (\is_array($cookie)) { |
|
110 | + try |
|
111 | + { |
|
112 | + if (\is_array($cookie)) |
|
113 | + { |
|
106 | 114 | return \array_map(fn (array|string $cookie): mixed => $this->decodeCookie($cookie), $cookie); |
107 | 115 | } |
108 | - } catch (DecryptException) { |
|
116 | + } |
|
117 | + catch (DecryptException) |
|
118 | + { |
|
109 | 119 | return null; |
110 | 120 | } |
111 | 121 | |
112 | - switch ($this->config->getProtectionMethod()) { |
|
122 | + switch ($this->config->getProtectionMethod()) |
|
123 | + { |
|
113 | 124 | case CookiesConfig::COOKIE_ENCRYPT: |
114 | - try { |
|
125 | + try |
|
126 | + { |
|
115 | 127 | return $this->encryption->getEncrypter()->decrypt($cookie); |
116 | - } catch (DecryptException) { |
|
128 | + } |
|
129 | + catch (DecryptException) |
|
130 | + { |
|
117 | 131 | } |
118 | 132 | return null; |
119 | 133 | case CookiesConfig::COOKIE_HMAC: |
120 | 134 | $hmac = \substr($cookie, -1 * CookiesConfig::MAC_LENGTH); |
121 | 135 | $value = \substr($cookie, 0, \strlen($cookie) - \strlen($hmac)); |
122 | 136 | |
123 | - if (\hash_equals($this->hmacSign($value), $hmac)) { |
|
137 | + if (\hash_equals($this->hmacSign($value), $hmac)) |
|
138 | + { |
|
124 | 139 | return $value; |
125 | 140 | } |
126 | 141 | } |
@@ -143,7 +158,8 @@ discard block |
||
143 | 158 | private function encodeCookie(Cookie $cookie): Cookie |
144 | 159 | { |
145 | 160 | $value = $cookie->getValue() ?? ''; |
146 | - if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) { |
|
161 | + if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) |
|
162 | + { |
|
147 | 163 | $encryptor = $this->encryption->getEncrypter(); |
148 | 164 | |
149 | 165 | return $cookie->withValue($encryptor->encrypt($value)); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | // from the current `foo` scope |
50 | 50 | self::assertInstanceOf(KVLogger::class, $logger); |
51 | 51 | |
52 | - for ($i = 0; $i < 10; $i++) { |
|
52 | + for ($i = 0; $i < 10; $i++){ |
|
53 | 53 | // because of proxy |
54 | 54 | self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger()); |
55 | 55 | self::assertSame('kv', $carrier->logger->getName()); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | // from the current `foo` scope |
70 | 70 | self::assertInstanceOf(FileLogger::class, $logger); |
71 | 71 | |
72 | - for ($i = 0; $i < 10; $i++) { |
|
72 | + for ($i = 0; $i < 10; $i++){ |
|
73 | 73 | // because of proxy |
74 | 74 | self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger()); |
75 | 75 | self::assertSame('file', $carrier->logger->getName()); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | ->bind( |
138 | 138 | ContextInterface::class, |
139 | 139 | new \Spiral\Core\Config\Injectable( |
140 | - new class implements InjectorInterface { |
|
140 | + new class implements InjectorInterface{ |
|
141 | 141 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
142 | 142 | { |
143 | 143 | return new Context($context); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | ->bind( |
179 | 179 | ContextInterface::class, |
180 | 180 | new \Spiral\Core\Config\Injectable( |
181 | - new class implements InjectorInterface { |
|
181 | + new class implements InjectorInterface{ |
|
182 | 182 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
183 | 183 | { |
184 | 184 | return new Context($context); |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | |
190 | 190 | FiberHelper::runFiberSequence( |
191 | 191 | static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx): void { |
192 | - for ($i = 0; $i < 10; $i++) { |
|
192 | + for ($i = 0; $i < 10; $i++){ |
|
193 | 193 | self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected'); |
194 | 194 | self::assertSame('ctx', $ctx->getValue()->getName()); |
195 | 195 | \Fiber::suspend(); |
196 | 196 | } |
197 | 197 | }), |
198 | 198 | static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context): void { |
199 | - for ($i = 0; $i < 10; $i++) { |
|
199 | + for ($i = 0; $i < 10; $i++){ |
|
200 | 200 | self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected'); |
201 | 201 | self::assertSame('context', $context->getValue()->getName()); |
202 | 202 | \Fiber::suspend(); |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | { |
258 | 258 | $root = new Container(); |
259 | 259 | $context = (object)['destroyed' => false]; |
260 | - $class = new class($context) implements DestroyableInterface { |
|
260 | + $class = new class($context) implements DestroyableInterface{ |
|
261 | 261 | public function __construct( |
262 | 262 | private readonly \stdClass $context, |
263 | - ) { |
|
263 | + ){ |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | public function __destruct() |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | new Scope('http'), |
289 | 289 | static function () use ($root, $proxy): void { |
290 | 290 | self::assertSame('Foo', $proxy->getName()); |
291 | - $proxy->setName(new class implements \Stringable { |
|
291 | + $proxy->setName(new class implements \Stringable{ |
|
292 | 292 | public function __toString(): string |
293 | 293 | { |
294 | 294 | return 'Bar'; |
@@ -49,7 +49,8 @@ discard block |
||
49 | 49 | // from the current `foo` scope |
50 | 50 | self::assertInstanceOf(KVLogger::class, $logger); |
51 | 51 | |
52 | - for ($i = 0; $i < 10; $i++) { |
|
52 | + for ($i = 0; $i < 10; $i++) |
|
53 | + { |
|
53 | 54 | // because of proxy |
54 | 55 | self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger()); |
55 | 56 | self::assertSame('kv', $carrier->logger->getName()); |
@@ -69,7 +70,8 @@ discard block |
||
69 | 70 | // from the current `foo` scope |
70 | 71 | self::assertInstanceOf(FileLogger::class, $logger); |
71 | 72 | |
72 | - for ($i = 0; $i < 10; $i++) { |
|
73 | + for ($i = 0; $i < 10; $i++) |
|
74 | + { |
|
73 | 75 | // because of proxy |
74 | 76 | self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger()); |
75 | 77 | self::assertSame('file', $carrier->logger->getName()); |
@@ -137,7 +139,8 @@ discard block |
||
137 | 139 | ->bind( |
138 | 140 | ContextInterface::class, |
139 | 141 | new \Spiral\Core\Config\Injectable( |
140 | - new class implements InjectorInterface { |
|
142 | + new class implements InjectorInterface |
|
143 | + { |
|
141 | 144 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
142 | 145 | { |
143 | 146 | return new Context($context); |
@@ -178,7 +181,8 @@ discard block |
||
178 | 181 | ->bind( |
179 | 182 | ContextInterface::class, |
180 | 183 | new \Spiral\Core\Config\Injectable( |
181 | - new class implements InjectorInterface { |
|
184 | + new class implements InjectorInterface |
|
185 | + { |
|
182 | 186 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
183 | 187 | { |
184 | 188 | return new Context($context); |
@@ -189,14 +193,16 @@ discard block |
||
189 | 193 | |
190 | 194 | FiberHelper::runFiberSequence( |
191 | 195 | static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx): void { |
192 | - for ($i = 0; $i < 10; $i++) { |
|
196 | + for ($i = 0; $i < 10; $i++) |
|
197 | + { |
|
193 | 198 | self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected'); |
194 | 199 | self::assertSame('ctx', $ctx->getValue()->getName()); |
195 | 200 | \Fiber::suspend(); |
196 | 201 | } |
197 | 202 | }), |
198 | 203 | static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context): void { |
199 | - for ($i = 0; $i < 10; $i++) { |
|
204 | + for ($i = 0; $i < 10; $i++) |
|
205 | + { |
|
200 | 206 | self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected'); |
201 | 207 | self::assertSame('context', $context->getValue()->getName()); |
202 | 208 | \Fiber::suspend(); |
@@ -257,7 +263,8 @@ discard block |
||
257 | 263 | { |
258 | 264 | $root = new Container(); |
259 | 265 | $context = (object)['destroyed' => false]; |
260 | - $class = new class($context) implements DestroyableInterface { |
|
266 | + $class = new class($context) implements DestroyableInterface |
|
267 | + { |
|
261 | 268 | public function __construct( |
262 | 269 | private readonly \stdClass $context, |
263 | 270 | ) { |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
48 | 48 | |
49 | 49 | private Internal\State $state; |
50 | - private ResolverInterface|Internal\Resolver $resolver; |
|
51 | - private FactoryInterface|Internal\Factory $factory; |
|
52 | - private ContainerInterface|Internal\Container $container; |
|
53 | - private BinderInterface|Internal\Binder $binder; |
|
54 | - private InvokerInterface|Internal\Invoker $invoker; |
|
50 | + private ResolverInterface | Internal\Resolver $resolver; |
|
51 | + private FactoryInterface | Internal\Factory $factory; |
|
52 | + private ContainerInterface | Internal\Container $container; |
|
53 | + private BinderInterface | Internal\Binder $binder; |
|
54 | + private InvokerInterface | Internal\Invoker $invoker; |
|
55 | 55 | private Internal\Scope $scope; |
56 | 56 | |
57 | 57 | /** |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function __construct( |
61 | 61 | private Config $config = new Config(), |
62 | - string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
62 | + string | \BackedEnum | null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
63 | 63 | private Options $options = new Options(), |
64 | - ) { |
|
65 | - if (\is_object($scopeName)) { |
|
66 | - $scopeName = (string) $scopeName->value; |
|
64 | + ){ |
|
65 | + if (\is_object($scopeName)){ |
|
66 | + $scopeName = (string)$scopeName->value; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $this->initServices($this, $scopeName); |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | * @throws \Throwable |
118 | 118 | * @psalm-suppress TooManyArguments |
119 | 119 | */ |
120 | - public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
|
120 | + public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed |
|
121 | 121 | { |
122 | 122 | return ContainerScope::getContainer() === $this |
123 | 123 | ? $this->factory->make($alias, $parameters, $context) |
124 | - : ContainerScope::runScope($this, fn (): mixed => $this->factory->make($alias, $parameters, $context)); |
|
124 | + : ContainerScope::runScope($this, fn () : mixed => $this->factory->make($alias, $parameters, $context)); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @throws \Throwable |
144 | 144 | * @psalm-suppress TooManyArguments |
145 | 145 | */ |
146 | - public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
|
146 | + public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed |
|
147 | 147 | { |
148 | 148 | return ContainerScope::getContainer() === $this |
149 | 149 | ? $this->container->get($id, $context) |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * If {@see string}, the default binder for the given scope will be returned. Default bindings won't affect |
164 | 164 | * already created Container instances except the case with the root one. |
165 | 165 | */ |
166 | - public function getBinder(string|\BackedEnum|null $scope = null): BinderInterface |
|
166 | + public function getBinder(string | \BackedEnum | null $scope = null): BinderInterface |
|
167 | 167 | { |
168 | - $scope = \is_object($scope) ? (string) $scope->value : $scope; |
|
168 | + $scope = \is_object($scope) ? (string)$scope->value : $scope; |
|
169 | 169 | |
170 | 170 | return $scope === null |
171 | 171 | ? $this->binder |
@@ -175,25 +175,25 @@ discard block |
||
175 | 175 | /** |
176 | 176 | * @throws \Throwable |
177 | 177 | */ |
178 | - public function runScope(Scope|array $bindings, callable $scope): mixed |
|
178 | + public function runScope(Scope | array $bindings, callable $scope): mixed |
|
179 | 179 | { |
180 | - if (!\is_array($bindings)) { |
|
180 | + if (!\is_array($bindings)){ |
|
181 | 181 | return $this->runIsolatedScope($bindings, $scope); |
182 | 182 | } |
183 | 183 | |
184 | 184 | $binds = &$this->state->bindings; |
185 | 185 | $singletons = &$this->state->singletons; |
186 | 186 | $cleanup = $previous = $prevSin = []; |
187 | - foreach ($bindings as $alias => $resolver) { |
|
187 | + foreach ($bindings as $alias => $resolver){ |
|
188 | 188 | // Store previous bindings |
189 | - if (isset($binds[$alias])) { |
|
189 | + if (isset($binds[$alias])){ |
|
190 | 190 | $previous[$alias] = $binds[$alias]; |
191 | - } else { |
|
191 | + }else{ |
|
192 | 192 | // Store bindings to be removed |
193 | 193 | $cleanup[] = $alias; |
194 | 194 | } |
195 | 195 | // Store previous singletons |
196 | - if (isset($singletons[$alias])) { |
|
196 | + if (isset($singletons[$alias])){ |
|
197 | 197 | $prevSin[$alias] = $singletons[$alias]; |
198 | 198 | unset($singletons[$alias]); |
199 | 199 | } |
@@ -201,21 +201,21 @@ discard block |
||
201 | 201 | $this->binder->bind($alias, $resolver); |
202 | 202 | } |
203 | 203 | |
204 | - try { |
|
204 | + try{ |
|
205 | 205 | return ContainerScope::getContainer() !== $this |
206 | 206 | ? ContainerScope::runScope($this, $scope) |
207 | 207 | : $scope($this); |
208 | - } finally { |
|
208 | + }finally{ |
|
209 | 209 | // Remove new bindings |
210 | - foreach ($cleanup as $alias) { |
|
210 | + foreach ($cleanup as $alias){ |
|
211 | 211 | unset($binds[$alias], $singletons[$alias]); |
212 | 212 | } |
213 | 213 | // Restore previous bindings |
214 | - foreach ($previous as $alias => $resolver) { |
|
214 | + foreach ($previous as $alias => $resolver){ |
|
215 | 215 | $binds[$alias] = $resolver; |
216 | 216 | } |
217 | 217 | // Restore singletons |
218 | - foreach ($prevSin as $alias => $instance) { |
|
218 | + foreach ($prevSin as $alias => $instance){ |
|
219 | 219 | $singletons[$alias] = $instance; |
220 | 220 | } |
221 | 221 | } |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * @param bool $force If the value is false, an exception will be thrown when attempting |
262 | 262 | * to bind an already constructed singleton. |
263 | 263 | */ |
264 | - public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void |
|
264 | + public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void |
|
265 | 265 | { |
266 | - if ($force) { |
|
266 | + if ($force){ |
|
267 | 267 | $this->binder->removeBinding($alias); |
268 | 268 | } |
269 | 269 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | { |
291 | 291 | return ContainerScope::getContainer() === $this |
292 | 292 | ? $this->invoker->invoke($target, $parameters) |
293 | - : ContainerScope::runScope($this, fn (): mixed => $this->invoker->invoke($target, $parameters)); |
|
293 | + : ContainerScope::runScope($this, fn () : mixed => $this->invoker->invoke($target, $parameters)); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | ], $this->options); |
335 | 335 | |
336 | 336 | // Create container services |
337 | - foreach ($container->config as $property => $class) { |
|
338 | - if (\property_exists($container, $property)) { |
|
337 | + foreach ($container->config as $property => $class){ |
|
338 | + if (\property_exists($container, $property)){ |
|
339 | 339 | $container->$property = $constructor->get($property, $class); |
340 | 340 | } |
341 | 341 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | private function closeScope(): void |
350 | 350 | { |
351 | 351 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
352 | - if (!isset($this->scope)) { |
|
352 | + if (!isset($this->scope)){ |
|
353 | 353 | $this->destruct(); |
354 | 354 | return; |
355 | 355 | } |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | |
359 | 359 | // Run finalizers |
360 | 360 | $errors = []; |
361 | - foreach ($this->state->finalizers as $finalizer) { |
|
362 | - try { |
|
361 | + foreach ($this->state->finalizers as $finalizer){ |
|
362 | + try{ |
|
363 | 363 | $this->invoker->invoke($finalizer); |
364 | - } catch (\Throwable $e) { |
|
364 | + }catch (\Throwable $e){ |
|
365 | 365 | $errors[] = $e; |
366 | 366 | } |
367 | 367 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $this->destruct(); |
371 | 371 | |
372 | 372 | // Throw collected errors |
373 | - if ($errors !== []) { |
|
373 | + if ($errors !== []){ |
|
374 | 374 | throw new FinalizersException($scopeName, $errors); |
375 | 375 | } |
376 | 376 | } |
@@ -392,18 +392,18 @@ discard block |
||
392 | 392 | $container->scope->setParent($this, $this->scope, $this->factory); |
393 | 393 | |
394 | 394 | // Add specific bindings |
395 | - foreach ($config->bindings as $alias => $resolver) { |
|
395 | + foreach ($config->bindings as $alias => $resolver){ |
|
396 | 396 | $container->binder->bind($alias, $resolver); |
397 | 397 | } |
398 | 398 | |
399 | 399 | return ContainerScope::runScope( |
400 | 400 | $container, |
401 | 401 | static function (self $container) use ($config, $closure): mixed { |
402 | - try { |
|
402 | + try{ |
|
403 | 403 | return $config->autowire |
404 | 404 | ? $container->invoke($closure) |
405 | 405 | : $closure($container); |
406 | - } finally { |
|
406 | + }finally{ |
|
407 | 407 | $container->closeScope(); |
408 | 408 | } |
409 | 409 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | |
33 | 33 | $this->assertNull(ContainerScope::getContainer()); |
34 | 34 | |
35 | - try { |
|
35 | + try{ |
|
36 | 36 | $this->assertTrue(ContainerScope::runScope($container, static function (): never { |
37 | 37 | throw new RuntimeException('exception'); |
38 | 38 | })); |
39 | - } catch (\Throwable $e) { |
|
39 | + }catch (\Throwable $e){ |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | $this->assertInstanceOf(RuntimeException::class, $e); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $this->assertTrue($c->runScope([ |
55 | 55 | 'bucket' => new Bucket('b'), |
56 | 56 | 'other' => new SampleClass() |
57 | - ], function ($c) { |
|
57 | + ], function ($c){ |
|
58 | 58 | $this->assertSame('b', $c->get('bucket')->getName()); |
59 | 59 | $this->assertTrue($c->has('other')); |
60 | 60 | |
@@ -76,21 +76,21 @@ discard block |
||
76 | 76 | $this->assertTrue($c->runScope([ |
77 | 77 | 'bucket' => new Bucket('b'), |
78 | 78 | 'other' => new SampleClass() |
79 | - ], function ($c) { |
|
79 | + ], function ($c){ |
|
80 | 80 | $this->assertSame('b', $c->get('bucket')->getName()); |
81 | 81 | $this->assertTrue($c->has('other')); |
82 | 82 | |
83 | 83 | return $c->get('bucket')->getName() == 'b' && $c->has('other'); |
84 | 84 | })); |
85 | 85 | |
86 | - try { |
|
86 | + try{ |
|
87 | 87 | $this->assertTrue($c->runScope([ |
88 | 88 | 'bucket' => new Bucket('b'), |
89 | 89 | 'other' => new SampleClass() |
90 | 90 | ], function () use ($c): void { |
91 | 91 | throw new RuntimeException('exception'); |
92 | 92 | })); |
93 | - } catch (\Throwable) { |
|
93 | + }catch (\Throwable){ |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $this->assertSame('a', $c->get('bucket')->getName()); |
@@ -32,11 +32,14 @@ discard block |
||
32 | 32 | |
33 | 33 | $this->assertNull(ContainerScope::getContainer()); |
34 | 34 | |
35 | - try { |
|
35 | + try |
|
36 | + { |
|
36 | 37 | $this->assertTrue(ContainerScope::runScope($container, static function (): never { |
37 | 38 | throw new RuntimeException('exception'); |
38 | 39 | })); |
39 | - } catch (\Throwable $e) { |
|
40 | + } |
|
41 | + catch (\Throwable $e) |
|
42 | + { |
|
40 | 43 | } |
41 | 44 | |
42 | 45 | $this->assertInstanceOf(RuntimeException::class, $e); |
@@ -54,7 +57,8 @@ discard block |
||
54 | 57 | $this->assertTrue($c->runScope([ |
55 | 58 | 'bucket' => new Bucket('b'), |
56 | 59 | 'other' => new SampleClass() |
57 | - ], function ($c) { |
|
60 | + ], function ($c) |
|
61 | + { |
|
58 | 62 | $this->assertSame('b', $c->get('bucket')->getName()); |
59 | 63 | $this->assertTrue($c->has('other')); |
60 | 64 | |
@@ -76,21 +80,25 @@ discard block |
||
76 | 80 | $this->assertTrue($c->runScope([ |
77 | 81 | 'bucket' => new Bucket('b'), |
78 | 82 | 'other' => new SampleClass() |
79 | - ], function ($c) { |
|
83 | + ], function ($c) |
|
84 | + { |
|
80 | 85 | $this->assertSame('b', $c->get('bucket')->getName()); |
81 | 86 | $this->assertTrue($c->has('other')); |
82 | 87 | |
83 | 88 | return $c->get('bucket')->getName() == 'b' && $c->has('other'); |
84 | 89 | })); |
85 | 90 | |
86 | - try { |
|
91 | + try |
|
92 | + { |
|
87 | 93 | $this->assertTrue($c->runScope([ |
88 | 94 | 'bucket' => new Bucket('b'), |
89 | 95 | 'other' => new SampleClass() |
90 | 96 | ], function () use ($c): void { |
91 | 97 | throw new RuntimeException('exception'); |
92 | 98 | })); |
93 | - } catch (\Throwable) { |
|
99 | + } |
|
100 | + catch (\Throwable) |
|
101 | + { |
|
94 | 102 | } |
95 | 103 | |
96 | 104 | $this->assertSame('a', $c->get('bucket')->getName()); |
@@ -138,7 +146,9 @@ discard block |
||
138 | 146 | public function testHasInstanceAfterMakeWithoutAliasInScope(): void |
139 | 147 | { |
140 | 148 | $container = new Container(); |
141 | - $container->bindSingleton('test', new #[Singleton] class {}); |
|
149 | + $container->bindSingleton('test', new #[Singleton] class |
|
150 | + { |
|
151 | +}); |
|
142 | 152 | $container->make('test'); |
143 | 153 | |
144 | 154 | $container->runScoped(function (Container $container): void { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | |
62 | 62 | $logger = $root->runScope( |
63 | 63 | new Scope('test'), |
64 | - static fn(?ScopeIndicatorLogger $logger): ?ScopeIndicatorLogger => $logger, |
|
64 | + static fn(?ScopeIndicatorLogger $logger) : ?ScopeIndicatorLogger => $logger, |
|
65 | 65 | ); |
66 | 66 | |
67 | 67 | $this->assertNotNull($logger); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $logger = $root->runScope( |
79 | 79 | new Scope('test'), |
80 | - static fn(?ScopeIndicatorLogger $logger): ?ScopeIndicatorLogger => $logger, |
|
80 | + static fn(?ScopeIndicatorLogger $logger) : ?ScopeIndicatorLogger => $logger, |
|
81 | 81 | ); |
82 | 82 | |
83 | 83 | $this->assertNotNull($logger); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | public function testMiddlewareProcessingEventShouldBeDispatched(): void |
62 | 62 | { |
63 | - $middleware = new class implements MiddlewareInterface { |
|
63 | + $middleware = new class implements MiddlewareInterface{ |
|
64 | 64 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
65 | 65 | { |
66 | 66 | return (new ResponseFactory(new HttpConfig(['headers' => []])))->createResponse(200); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->container->getBinder('http') |
90 | 90 | ->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr): ?ServerRequestInterface => $cr->get()); |
91 | 91 | |
92 | - $middleware = new class implements MiddlewareInterface { |
|
92 | + $middleware = new class implements MiddlewareInterface{ |
|
93 | 93 | public function process( |
94 | 94 | ServerRequestInterface $request, |
95 | 95 | RequestHandlerInterface $handler, |
@@ -60,7 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | public function testMiddlewareProcessingEventShouldBeDispatched(): void |
62 | 62 | { |
63 | - $middleware = new class implements MiddlewareInterface { |
|
63 | + $middleware = new class implements MiddlewareInterface |
|
64 | + { |
|
64 | 65 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
65 | 66 | { |
66 | 67 | return (new ResponseFactory(new HttpConfig(['headers' => []])))->createResponse(200); |
@@ -89,7 +90,8 @@ discard block |
||
89 | 90 | $this->container->getBinder('http') |
90 | 91 | ->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr): ?ServerRequestInterface => $cr->get()); |
91 | 92 | |
92 | - $middleware = new class implements MiddlewareInterface { |
|
93 | + $middleware = new class implements MiddlewareInterface |
|
94 | + { |
|
93 | 95 | public function process( |
94 | 96 | ServerRequestInterface $request, |
95 | 97 | RequestHandlerInterface $handler, |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected function formatTopics(array $topics): array |
18 | 18 | { |
19 | - return \array_map(static fn (string|\Stringable $topic): string => (string) $topic, $topics); |
|
19 | + return \array_map(static fn (string | \Stringable $topic): string => (string)$topic, $topics); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @param iterable<T>|T $entries |
25 | 25 | * @return array<T> |
26 | 26 | */ |
27 | - protected function toArray(iterable|string|\Stringable $entries): array |
|
27 | + protected function toArray(iterable | string | \Stringable $entries): array |
|
28 | 28 | { |
29 | 29 | return match (true) { |
30 | 30 | \is_array($entries) => $entries, |