@@ -57,13 +57,16 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | $this->mailer->expects('send')->with($email)->andThrow(new TransportException('failed')); |
| 59 | 59 | |
| 60 | - try { |
|
| 60 | + try |
|
| 61 | + { |
|
| 61 | 62 | $this->getHandler()->handle( |
| 62 | 63 | MailQueue::JOB_NAME, |
| 63 | 64 | 'id', |
| 64 | 65 | json_encode(MessageSerializer::pack($this->getMail())) |
| 65 | 66 | ); |
| 66 | - } catch (TransportException) { |
|
| 67 | + } |
|
| 68 | + catch (TransportException) |
|
| 69 | + { |
|
| 67 | 70 | } |
| 68 | 71 | } |
| 69 | 72 | |
@@ -121,7 +124,8 @@ discard block |
||
| 121 | 124 | private function expectRenderer(Email $email): void |
| 122 | 125 | { |
| 123 | 126 | $this->renderer->expects('render')->withArgs( |
| 124 | - function (Message $message) { |
|
| 127 | + function (Message $message) |
|
| 128 | + { |
|
| 125 | 129 | $this->assertSame($message->getSubject(), 'test'); |
| 126 | 130 | return true; |
| 127 | 131 | } |
@@ -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 | |
@@ -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, function () use ($container): void { |
| 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,10 +146,13 @@ 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 | - $container->runScoped(function (Container $container) { |
|
| 154 | + $container->runScoped(function (Container $container) |
|
| 155 | + { |
|
| 145 | 156 | $this->assertTrue($container->hasInstance('test')); |
| 146 | 157 | }); |
| 147 | 158 | } |
@@ -152,7 +163,8 @@ discard block |
||
| 152 | 163 | $container->bindSingleton('test', SampleClass::class); |
| 153 | 164 | $container->make('test'); |
| 154 | 165 | |
| 155 | - $container->runScoped(function (Container $container) { |
|
| 166 | + $container->runScoped(function (Container $container) |
|
| 167 | + { |
|
| 156 | 168 | $this->assertTrue($container->hasInstance('test')); |
| 157 | 169 | }); |
| 158 | 170 | } |
@@ -167,7 +179,8 @@ discard block |
||
| 167 | 179 | $container->bindSingleton('bar', 'foo'); |
| 168 | 180 | $container->make('bar'); |
| 169 | 181 | |
| 170 | - $container->runScoped(function (Container $container) { |
|
| 182 | + $container->runScoped(function (Container $container) |
|
| 183 | + { |
|
| 171 | 184 | $this->assertTrue($container->hasInstance('bar')); |
| 172 | 185 | }); |
| 173 | 186 | } |
@@ -31,9 +31,12 @@ discard block |
||
| 31 | 31 | ) { |
| 32 | 32 | parent::__construct($config, $name, $comment, $namespace); |
| 33 | 33 | |
| 34 | - try { |
|
| 34 | + try |
|
| 35 | + { |
|
| 35 | 36 | $this->validationConfig = $container->get(ValidationConfig::class); |
| 36 | - } catch (\Throwable) { |
|
| 37 | + } |
|
| 38 | + catch (\Throwable) |
|
| 39 | + { |
|
| 37 | 40 | // Validation is not configured |
| 38 | 41 | $this->validationConfig = null; |
| 39 | 42 | } |
@@ -50,13 +53,15 @@ discard block |
||
| 50 | 53 | public function addFilterDefinition(): void |
| 51 | 54 | { |
| 52 | 55 | $validation = $this->validationConfig?->getDefaultValidator(); |
| 53 | - if ($validation === null) { |
|
| 56 | + if ($validation === null) |
|
| 57 | + { |
|
| 54 | 58 | throw new ValidationException( |
| 55 | 59 | 'Default Validator is not configured. Read more at https://spiral.dev/docs/validation-factory' |
| 56 | 60 | ); |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | - if (!\class_exists($validation)) { |
|
| 63 | + if (!\class_exists($validation)) |
|
| 64 | + { |
|
| 60 | 65 | throw new ValidationException( |
| 61 | 66 | \sprintf( |
| 62 | 67 | 'Default Validator "%s" is not class or does not exist.', |
@@ -90,7 +95,8 @@ discard block |
||
| 90 | 95 | $p = $this->class->addProperty($property->getName()) |
| 91 | 96 | ->setType($property->getType()); |
| 92 | 97 | |
| 93 | - foreach ($property->getAttributes() as $attribute) { |
|
| 98 | + foreach ($property->getAttributes() as $attribute) |
|
| 99 | + { |
|
| 94 | 100 | $p->addAttribute($attribute->getName(), $attribute->getArguments()); |
| 95 | 101 | } |
| 96 | 102 | } |
@@ -107,12 +113,16 @@ discard block |
||
| 107 | 113 | { |
| 108 | 114 | $declaredType = null; |
| 109 | 115 | |
| 110 | - if (\str_contains($property, ':')) { |
|
| 116 | + if (\str_contains($property, ':')) |
|
| 117 | + { |
|
| 111 | 118 | $segments = \explode(':', $property, 3); |
| 112 | 119 | |
| 113 | - if (\count($segments) === 3) { |
|
| 120 | + if (\count($segments) === 3) |
|
| 121 | + { |
|
| 114 | 122 | [$property, $source, $declaredType] = $segments; |
| 115 | - } else { |
|
| 123 | + } |
|
| 124 | + else |
|
| 125 | + { |
|
| 116 | 126 | [$property, $source] = $segments; |
| 117 | 127 | } |
| 118 | 128 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |