@@ -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,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 | ) { |
@@ -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 { |
@@ -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, |