@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use Spiral\Core\ContainerScope; |
10 | 10 | use Spiral\Core\Exception\ScopeException; |
11 | 11 | |
12 | -if (!function_exists('spiral')) { |
|
12 | +if (!function_exists('spiral')){ |
|
13 | 13 | /** |
14 | 14 | * Resolve given alias in current IoC scope. |
15 | 15 | * |
@@ -22,19 +22,19 @@ discard block |
||
22 | 22 | */ |
23 | 23 | function spiral(string $alias): mixed |
24 | 24 | { |
25 | - if (!ContainerScope::getContainer() instanceof \Psr\Container\ContainerInterface) { |
|
25 | + if (!ContainerScope::getContainer() instanceof \Psr\Container\ContainerInterface){ |
|
26 | 26 | throw new ScopeException('Container scope was not set.'); |
27 | 27 | } |
28 | 28 | |
29 | - try { |
|
29 | + try{ |
|
30 | 30 | return ContainerScope::getContainer()->get($alias); |
31 | - } catch (ContainerExceptionInterface $e) { |
|
31 | + }catch (ContainerExceptionInterface $e){ |
|
32 | 32 | throw new ScopeException($e->getMessage(), $e->getCode(), $e); |
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | -if (!function_exists('directory')) { |
|
37 | +if (!function_exists('directory')){ |
|
38 | 38 | /** |
39 | 39 | * Get directory alias value. Uses application core from the current global scope. |
40 | 40 | * |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | -if (!function_exists('env')) { |
|
52 | +if (!function_exists('env')){ |
|
53 | 53 | /** |
54 | 54 | * Gets the value of an environment variable. Uses application core from the current global scope. |
55 | 55 | * |
@@ -9,7 +9,8 @@ discard block |
||
9 | 9 | use Spiral\Core\ContainerScope; |
10 | 10 | use Spiral\Core\Exception\ScopeException; |
11 | 11 | |
12 | -if (!function_exists('spiral')) { |
|
12 | +if (!function_exists('spiral')) |
|
13 | +{ |
|
13 | 14 | /** |
14 | 15 | * Resolve given alias in current IoC scope. |
15 | 16 | * |
@@ -22,19 +23,24 @@ discard block |
||
22 | 23 | */ |
23 | 24 | function spiral(string $alias): mixed |
24 | 25 | { |
25 | - if (!ContainerScope::getContainer() instanceof \Psr\Container\ContainerInterface) { |
|
26 | + if (!ContainerScope::getContainer() instanceof \Psr\Container\ContainerInterface) |
|
27 | + { |
|
26 | 28 | throw new ScopeException('Container scope was not set.'); |
27 | 29 | } |
28 | 30 | |
29 | - try { |
|
31 | + try |
|
32 | + { |
|
30 | 33 | return ContainerScope::getContainer()->get($alias); |
31 | - } catch (ContainerExceptionInterface $e) { |
|
34 | + } |
|
35 | + catch (ContainerExceptionInterface $e) |
|
36 | + { |
|
32 | 37 | throw new ScopeException($e->getMessage(), $e->getCode(), $e); |
33 | 38 | } |
34 | 39 | } |
35 | 40 | } |
36 | 41 | |
37 | -if (!function_exists('directory')) { |
|
42 | +if (!function_exists('directory')) |
|
43 | +{ |
|
38 | 44 | /** |
39 | 45 | * Get directory alias value. Uses application core from the current global scope. |
40 | 46 | * |
@@ -49,7 +55,8 @@ discard block |
||
49 | 55 | } |
50 | 56 | } |
51 | 57 | |
52 | -if (!function_exists('env')) { |
|
58 | +if (!function_exists('env')) |
|
59 | +{ |
|
53 | 60 | /** |
54 | 61 | * Gets the value of an environment variable. Uses application core from the current global scope. |
55 | 62 | * |
@@ -87,7 +87,7 @@ |
||
87 | 87 | $factory->shouldReceive('make')->andReturnUsing(function (string $name): QueueInterface { |
88 | 88 | $result = ['sync' => $this->defaultQueue, 'test' => $this->testQueue][$name] ?? null; |
89 | 89 | |
90 | - if (!$result instanceof \Spiral\Queue\QueueInterface) { |
|
90 | + if (!$result instanceof \Spiral\Queue\QueueInterface){ |
|
91 | 91 | throw new NotFoundException(); |
92 | 92 | } |
93 | 93 | return $result; |
@@ -87,7 +87,8 @@ |
||
87 | 87 | $factory->shouldReceive('make')->andReturnUsing(function (string $name): QueueInterface { |
88 | 88 | $result = ['sync' => $this->defaultQueue, 'test' => $this->testQueue][$name] ?? null; |
89 | 89 | |
90 | - if (!$result instanceof \Spiral\Queue\QueueInterface) { |
|
90 | + if (!$result instanceof \Spiral\Queue\QueueInterface) |
|
91 | + { |
|
91 | 92 | throw new NotFoundException(); |
92 | 93 | } |
93 | 94 | return $result; |
@@ -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 instanceof \Spiral\Queue\OptionsInterface); |
109 | 109 |
@@ -20,13 +20,13 @@ |
||
20 | 20 | |
21 | 21 | public function __construct( |
22 | 22 | private readonly Handler $coreHandler |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** @inheritdoc */ |
27 | 27 | public function push(string $name, mixed $payload = [], ?OptionsInterface $options = null): string |
28 | 28 | { |
29 | - if ($options instanceof \Spiral\Queue\OptionsInterface && $options->getDelay()) { |
|
29 | + if ($options instanceof \Spiral\Queue\OptionsInterface && $options->getDelay()){ |
|
30 | 30 | \sleep($options->getDelay()); |
31 | 31 | } |
32 | 32 |
@@ -26,7 +26,8 @@ |
||
26 | 26 | /** @inheritdoc */ |
27 | 27 | public function push(string $name, mixed $payload = [], ?OptionsInterface $options = null): string |
28 | 28 | { |
29 | - if ($options instanceof \Spiral\Queue\OptionsInterface && $options->getDelay()) { |
|
29 | + if ($options instanceof \Spiral\Queue\OptionsInterface && $options->getDelay()) |
|
30 | + { |
|
30 | 31 | \sleep($options->getDelay()); |
31 | 32 | } |
32 | 33 |
@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function __construct(int $maxAttempts, int $delay, float $multiplier = 1) |
29 | 29 | { |
30 | - if ($maxAttempts < 0) { |
|
30 | + if ($maxAttempts < 0){ |
|
31 | 31 | throw new InvalidArgumentException( |
32 | 32 | \sprintf('Maximum attempts must be greater than or equal to zero: `%s` given.', $maxAttempts) |
33 | 33 | ); |
34 | 34 | } |
35 | 35 | $this->maxAttempts = $maxAttempts; |
36 | 36 | |
37 | - if ($delay < 0) { |
|
37 | + if ($delay < 0){ |
|
38 | 38 | throw new InvalidArgumentException( |
39 | 39 | \sprintf('Delay must be greater than or equal to zero: `%s` given.', $delay) |
40 | 40 | ); |
41 | 41 | } |
42 | 42 | $this->delay = $delay; |
43 | 43 | |
44 | - if ($multiplier < 1) { |
|
44 | + if ($multiplier < 1){ |
|
45 | 45 | throw new InvalidArgumentException( |
46 | 46 | \sprintf('Multiplier must be greater than zero: `%s` given.', $multiplier) |
47 | 47 | ); |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getDelay(int $attempts = 0): int |
58 | 58 | { |
59 | - return (int) \ceil($this->delay * $this->multiplier ** $attempts); |
|
59 | + return (int)\ceil($this->delay * $this->multiplier ** $attempts); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function isRetryable(\Throwable $exception, int $attempts = 0): bool |
66 | 66 | { |
67 | - if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable) { |
|
67 | + if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable){ |
|
68 | 68 | $exception = $exception->getPrevious(); |
69 | 69 | } |
70 | 70 | |
71 | - if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0) { |
|
71 | + if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0){ |
|
72 | 72 | return false; |
73 | 73 | } |
74 | 74 |
@@ -27,21 +27,24 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function __construct(int $maxAttempts, int $delay, float $multiplier = 1) |
29 | 29 | { |
30 | - if ($maxAttempts < 0) { |
|
30 | + if ($maxAttempts < 0) |
|
31 | + { |
|
31 | 32 | throw new InvalidArgumentException( |
32 | 33 | \sprintf('Maximum attempts must be greater than or equal to zero: `%s` given.', $maxAttempts) |
33 | 34 | ); |
34 | 35 | } |
35 | 36 | $this->maxAttempts = $maxAttempts; |
36 | 37 | |
37 | - if ($delay < 0) { |
|
38 | + if ($delay < 0) |
|
39 | + { |
|
38 | 40 | throw new InvalidArgumentException( |
39 | 41 | \sprintf('Delay must be greater than or equal to zero: `%s` given.', $delay) |
40 | 42 | ); |
41 | 43 | } |
42 | 44 | $this->delay = $delay; |
43 | 45 | |
44 | - if ($multiplier < 1) { |
|
46 | + if ($multiplier < 1) |
|
47 | + { |
|
45 | 48 | throw new InvalidArgumentException( |
46 | 49 | \sprintf('Multiplier must be greater than zero: `%s` given.', $multiplier) |
47 | 50 | ); |
@@ -64,11 +67,13 @@ discard block |
||
64 | 67 | */ |
65 | 68 | public function isRetryable(\Throwable $exception, int $attempts = 0): bool |
66 | 69 | { |
67 | - if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable) { |
|
70 | + if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable) |
|
71 | + { |
|
68 | 72 | $exception = $exception->getPrevious(); |
69 | 73 | } |
70 | 74 | |
71 | - if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0) { |
|
75 | + if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0) |
|
76 | + { |
|
72 | 77 | return false; |
73 | 78 | } |
74 | 79 |
@@ -20,28 +20,28 @@ discard block |
||
20 | 20 | public function __construct( |
21 | 21 | private readonly ReaderInterface $reader, |
22 | 22 | private readonly HandlerRegistryInterface $registry, |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
27 | 27 | { |
28 | - try { |
|
28 | + try{ |
|
29 | 29 | return $core->callAction($controller, $action, $parameters); |
30 | - } catch (\Throwable $e) { |
|
31 | - if (!\class_exists($controller)) { |
|
30 | + }catch (\Throwable $e){ |
|
31 | + if (!\class_exists($controller)){ |
|
32 | 32 | $controller = $this->registry->getHandler($controller)::class; |
33 | 33 | } |
34 | 34 | |
35 | 35 | $policy = $this->getRetryPolicy($e, new \ReflectionClass($controller)); |
36 | 36 | |
37 | - if (!$policy instanceof \Spiral\Queue\RetryPolicyInterface) { |
|
37 | + if (!$policy instanceof \Spiral\Queue\RetryPolicyInterface){ |
|
38 | 38 | throw $e; |
39 | 39 | } |
40 | 40 | |
41 | 41 | $headers = $parameters['headers'] ?? []; |
42 | 42 | $attempts = (int)($headers['attempts'][0] ?? 0); |
43 | 43 | |
44 | - if ($policy->isRetryable($e, $attempts) === false) { |
|
44 | + if ($policy->isRetryable($e, $attempts) === false){ |
|
45 | 45 | throw $e; |
46 | 46 | } |
47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | $attribute = $this->reader->firstClassMetadata($handler, Attribute::class); |
60 | 60 | |
61 | - if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable) { |
|
61 | + if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable){ |
|
62 | 62 | $exception = $exception->getPrevious(); |
63 | 63 | } |
64 | 64 |
@@ -25,23 +25,29 @@ discard block |
||
25 | 25 | |
26 | 26 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
27 | 27 | { |
28 | - try { |
|
28 | + try |
|
29 | + { |
|
29 | 30 | return $core->callAction($controller, $action, $parameters); |
30 | - } catch (\Throwable $e) { |
|
31 | - if (!\class_exists($controller)) { |
|
31 | + } |
|
32 | + catch (\Throwable $e) |
|
33 | + { |
|
34 | + if (!\class_exists($controller)) |
|
35 | + { |
|
32 | 36 | $controller = $this->registry->getHandler($controller)::class; |
33 | 37 | } |
34 | 38 | |
35 | 39 | $policy = $this->getRetryPolicy($e, new \ReflectionClass($controller)); |
36 | 40 | |
37 | - if (!$policy instanceof \Spiral\Queue\RetryPolicyInterface) { |
|
41 | + if (!$policy instanceof \Spiral\Queue\RetryPolicyInterface) |
|
42 | + { |
|
38 | 43 | throw $e; |
39 | 44 | } |
40 | 45 | |
41 | 46 | $headers = $parameters['headers'] ?? []; |
42 | 47 | $attempts = (int)($headers['attempts'][0] ?? 0); |
43 | 48 | |
44 | - if ($policy->isRetryable($e, $attempts) === false) { |
|
49 | + if ($policy->isRetryable($e, $attempts) === false) |
|
50 | + { |
|
45 | 51 | throw $e; |
46 | 52 | } |
47 | 53 | |
@@ -58,7 +64,8 @@ discard block |
||
58 | 64 | { |
59 | 65 | $attribute = $this->reader->firstClassMetadata($handler, Attribute::class); |
60 | 66 | |
61 | - if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable) { |
|
67 | + if ($exception instanceof JobException && $exception->getPrevious() instanceof \Throwable) |
|
68 | + { |
|
62 | 69 | $exception = $exception->getPrevious(); |
63 | 70 | } |
64 | 71 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | { |
20 | 20 | public function create(string $pathname, array $config = []): FileInterface |
21 | 21 | { |
22 | - if ($this instanceof ReadableInterface && !$this->exists($pathname)) { |
|
22 | + if ($this instanceof ReadableInterface && !$this->exists($pathname)){ |
|
23 | 23 | return $this->write($pathname, '', $config); |
24 | 24 | } |
25 | 25 | |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | $fs = $this->getOperator(); |
34 | 34 | |
35 | - try { |
|
36 | - switch (true) { |
|
35 | + try{ |
|
36 | + switch (true){ |
|
37 | 37 | case \is_object($content): |
38 | 38 | case \is_string($content): |
39 | 39 | $fs->write($pathname, (string)$content, $config); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $message = 'Content must be a resource stream or stringable type, but %s passed'; |
48 | 48 | throw new \InvalidArgumentException(\sprintf($message, \get_debug_type($content))); |
49 | 49 | } |
50 | - } catch (FilesystemException $e) { |
|
50 | + }catch (FilesystemException $e){ |
|
51 | 51 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
52 | 52 | } |
53 | 53 | |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | ): FileInterface { |
62 | 62 | $fs = $this->getOperator(); |
63 | 63 | |
64 | - try { |
|
64 | + try{ |
|
65 | 65 | $fs->setVisibility($pathname, $this->toFlysystemVisibility($visibility)); |
66 | - } catch (FilesystemException $e) { |
|
66 | + }catch (FilesystemException $e){ |
|
67 | 67 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
68 | 68 | } |
69 | 69 | |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | ): FileInterface { |
79 | 79 | $fs = $this->getOperator(); |
80 | 80 | |
81 | - if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this) { |
|
82 | - try { |
|
81 | + if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this){ |
|
82 | + try{ |
|
83 | 83 | $fs->copy($source, $destination, $config); |
84 | - } catch (FilesystemException $e) { |
|
84 | + }catch (FilesystemException $e){ |
|
85 | 85 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
86 | 86 | } |
87 | 87 | |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | ): FileInterface { |
100 | 100 | $fs = $this->getOperator(); |
101 | 101 | |
102 | - if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this) { |
|
103 | - try { |
|
102 | + if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this){ |
|
103 | + try{ |
|
104 | 104 | $fs->move($source, $destination, $config); |
105 | - } catch (FilesystemException $e) { |
|
105 | + }catch (FilesystemException $e){ |
|
106 | 106 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
107 | 107 | } |
108 | 108 | |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | { |
121 | 121 | $fs = $this->getOperator(); |
122 | 122 | |
123 | - try { |
|
123 | + try{ |
|
124 | 124 | $fs->delete($pathname); |
125 | 125 | |
126 | - if ($clean) { |
|
126 | + if ($clean){ |
|
127 | 127 | /** @psalm-suppress InternalMethod */ |
128 | 128 | $this->deleteEmptyDirectories($this->getParentDirectory($pathname)); |
129 | 129 | } |
130 | - } catch (FilesystemException $e) { |
|
130 | + }catch (FilesystemException $e){ |
|
131 | 131 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
132 | 132 | } |
133 | 133 | } |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function deleteEmptyDirectories(string $directory): void |
184 | 184 | { |
185 | - if (!$this->hasParentDirectory($directory)) { |
|
185 | + if (!$this->hasParentDirectory($directory)){ |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | 189 | $fs = $this->getOperator(); |
190 | 190 | |
191 | - try { |
|
192 | - if (!$this->hasFiles($directory)) { |
|
191 | + try{ |
|
192 | + if (!$this->hasFiles($directory)){ |
|
193 | 193 | $fs->deleteDirectory($directory); |
194 | 194 | $this->deleteEmptyDirectories($this->getParentDirectory($directory)); |
195 | 195 | } |
196 | - } catch (FilesystemException $e) { |
|
196 | + }catch (FilesystemException $e){ |
|
197 | 197 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
198 | 198 | } |
199 | 199 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | { |
215 | 215 | $fs = $this->getOperator(); |
216 | 216 | |
217 | - foreach ($fs->listContents($directory) as $_) { |
|
217 | + foreach ($fs->listContents($directory) as $_){ |
|
218 | 218 | return true; |
219 | 219 | } |
220 | 220 |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | { |
20 | 20 | public function create(string $pathname, array $config = []): FileInterface |
21 | 21 | { |
22 | - if ($this instanceof ReadableInterface && !$this->exists($pathname)) { |
|
22 | + if ($this instanceof ReadableInterface && !$this->exists($pathname)) |
|
23 | + { |
|
23 | 24 | return $this->write($pathname, '', $config); |
24 | 25 | } |
25 | 26 | |
@@ -32,8 +33,10 @@ discard block |
||
32 | 33 | |
33 | 34 | $fs = $this->getOperator(); |
34 | 35 | |
35 | - try { |
|
36 | - switch (true) { |
|
36 | + try |
|
37 | + { |
|
38 | + switch (true) |
|
39 | + { |
|
37 | 40 | case \is_object($content): |
38 | 41 | case \is_string($content): |
39 | 42 | $fs->write($pathname, (string)$content, $config); |
@@ -47,7 +50,9 @@ discard block |
||
47 | 50 | $message = 'Content must be a resource stream or stringable type, but %s passed'; |
48 | 51 | throw new \InvalidArgumentException(\sprintf($message, \get_debug_type($content))); |
49 | 52 | } |
50 | - } catch (FilesystemException $e) { |
|
53 | + } |
|
54 | + catch (FilesystemException $e) |
|
55 | + { |
|
51 | 56 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
52 | 57 | } |
53 | 58 | |
@@ -61,9 +66,12 @@ discard block |
||
61 | 66 | ): FileInterface { |
62 | 67 | $fs = $this->getOperator(); |
63 | 68 | |
64 | - try { |
|
69 | + try |
|
70 | + { |
|
65 | 71 | $fs->setVisibility($pathname, $this->toFlysystemVisibility($visibility)); |
66 | - } catch (FilesystemException $e) { |
|
72 | + } |
|
73 | + catch (FilesystemException $e) |
|
74 | + { |
|
67 | 75 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
68 | 76 | } |
69 | 77 | |
@@ -78,10 +86,14 @@ discard block |
||
78 | 86 | ): FileInterface { |
79 | 87 | $fs = $this->getOperator(); |
80 | 88 | |
81 | - if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this) { |
|
82 | - try { |
|
89 | + if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this) |
|
90 | + { |
|
91 | + try |
|
92 | + { |
|
83 | 93 | $fs->copy($source, $destination, $config); |
84 | - } catch (FilesystemException $e) { |
|
94 | + } |
|
95 | + catch (FilesystemException $e) |
|
96 | + { |
|
85 | 97 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
86 | 98 | } |
87 | 99 | |
@@ -99,10 +111,14 @@ discard block |
||
99 | 111 | ): FileInterface { |
100 | 112 | $fs = $this->getOperator(); |
101 | 113 | |
102 | - if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this) { |
|
103 | - try { |
|
114 | + if (!$storage instanceof \Spiral\Storage\BucketInterface || $storage === $this) |
|
115 | + { |
|
116 | + try |
|
117 | + { |
|
104 | 118 | $fs->move($source, $destination, $config); |
105 | - } catch (FilesystemException $e) { |
|
119 | + } |
|
120 | + catch (FilesystemException $e) |
|
121 | + { |
|
106 | 122 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
107 | 123 | } |
108 | 124 | |
@@ -120,14 +136,18 @@ discard block |
||
120 | 136 | { |
121 | 137 | $fs = $this->getOperator(); |
122 | 138 | |
123 | - try { |
|
139 | + try |
|
140 | + { |
|
124 | 141 | $fs->delete($pathname); |
125 | 142 | |
126 | - if ($clean) { |
|
143 | + if ($clean) |
|
144 | + { |
|
127 | 145 | /** @psalm-suppress InternalMethod */ |
128 | 146 | $this->deleteEmptyDirectories($this->getParentDirectory($pathname)); |
129 | 147 | } |
130 | - } catch (FilesystemException $e) { |
|
148 | + } |
|
149 | + catch (FilesystemException $e) |
|
150 | + { |
|
131 | 151 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
132 | 152 | } |
133 | 153 | } |
@@ -182,18 +202,23 @@ discard block |
||
182 | 202 | */ |
183 | 203 | private function deleteEmptyDirectories(string $directory): void |
184 | 204 | { |
185 | - if (!$this->hasParentDirectory($directory)) { |
|
205 | + if (!$this->hasParentDirectory($directory)) |
|
206 | + { |
|
186 | 207 | return; |
187 | 208 | } |
188 | 209 | |
189 | 210 | $fs = $this->getOperator(); |
190 | 211 | |
191 | - try { |
|
192 | - if (!$this->hasFiles($directory)) { |
|
212 | + try |
|
213 | + { |
|
214 | + if (!$this->hasFiles($directory)) |
|
215 | + { |
|
193 | 216 | $fs->deleteDirectory($directory); |
194 | 217 | $this->deleteEmptyDirectories($this->getParentDirectory($directory)); |
195 | 218 | } |
196 | - } catch (FilesystemException $e) { |
|
219 | + } |
|
220 | + catch (FilesystemException $e) |
|
221 | + { |
|
197 | 222 | throw new FileOperationException($e->getMessage(), $e->getCode(), $e); |
198 | 223 | } |
199 | 224 | } |
@@ -214,7 +239,8 @@ discard block |
||
214 | 239 | { |
215 | 240 | $fs = $this->getOperator(); |
216 | 241 | |
217 | - foreach ($fs->listContents($directory) as $_) { |
|
242 | + foreach ($fs->listContents($directory) as $_) |
|
243 | + { |
|
218 | 244 | return true; |
219 | 245 | } |
220 | 246 |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | |
28 | 28 | public function __toString(): string |
29 | 29 | { |
30 | - try { |
|
30 | + try{ |
|
31 | 31 | return $this->getContents(); |
32 | - } catch (\Exception) { |
|
32 | + }catch (\Exception){ |
|
33 | 33 | return ''; |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | 37 | public function close(): void |
38 | 38 | { |
39 | - if ($this->stream instanceof \Generator) { |
|
39 | + if ($this->stream instanceof \Generator){ |
|
40 | 40 | $this->detach(); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function detach() |
45 | 45 | { |
46 | - if (!$this->stream instanceof \Generator) { |
|
46 | + if (!$this->stream instanceof \Generator){ |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | $this->stream = null; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | public function rewind(): void |
83 | 83 | { |
84 | - if ($this->stream instanceof \Generator) { |
|
84 | + if ($this->stream instanceof \Generator){ |
|
85 | 85 | $this->stream->rewind(); |
86 | 86 | } |
87 | 87 | $this->caret = 0; |
@@ -105,26 +105,26 @@ discard block |
||
105 | 105 | |
106 | 106 | public function read($length): string |
107 | 107 | { |
108 | - if (!$this->readable) { |
|
108 | + if (!$this->readable){ |
|
109 | 109 | throw new RuntimeException('Cannot read from non-readable stream.'); |
110 | 110 | } |
111 | - if (!$this->stream instanceof \Generator) { |
|
111 | + if (!$this->stream instanceof \Generator){ |
|
112 | 112 | throw new RuntimeException('Cannot read from detached stream.'); |
113 | 113 | } |
114 | - do { |
|
115 | - if ($this->started) { |
|
114 | + do{ |
|
115 | + if ($this->started){ |
|
116 | 116 | $read = (string)$this->stream->send(null); |
117 | - } else { |
|
117 | + }else{ |
|
118 | 118 | $this->started = true; |
119 | 119 | $read = (string)$this->stream->current(); |
120 | 120 | } |
121 | - if (!$this->stream->valid()) { |
|
121 | + if (!$this->stream->valid()){ |
|
122 | 122 | $read .= $this->stream->getReturn(); |
123 | 123 | break; |
124 | 124 | } |
125 | - } while ($read === ''); |
|
125 | + }while ($read === ''); |
|
126 | 126 | $this->caret += \strlen($read); |
127 | - if (!$this->stream->valid()) { |
|
127 | + if (!$this->stream->valid()){ |
|
128 | 128 | $this->size = $this->caret; |
129 | 129 | } |
130 | 130 | return $read; |
@@ -132,19 +132,19 @@ discard block |
||
132 | 132 | |
133 | 133 | public function getContents(): string |
134 | 134 | { |
135 | - if (!$this->stream instanceof \Generator) { |
|
135 | + if (!$this->stream instanceof \Generator){ |
|
136 | 136 | throw new RuntimeException('Unable to read stream contents.'); |
137 | 137 | } |
138 | 138 | $content = ''; |
139 | - do { |
|
139 | + do{ |
|
140 | 140 | $content .= $this->read(PHP_INT_MAX); |
141 | - } while ($this->stream->valid()); |
|
141 | + }while ($this->stream->valid()); |
|
142 | 142 | return $content; |
143 | 143 | } |
144 | 144 | |
145 | 145 | public function getMetadata($key = null) |
146 | 146 | { |
147 | - if (!$this->stream instanceof \Generator) { |
|
147 | + if (!$this->stream instanceof \Generator){ |
|
148 | 148 | return $key ? null : []; |
149 | 149 | } |
150 | 150 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | 'eof' => $this->eof(), |
154 | 154 | ]; |
155 | 155 | |
156 | - if (null === $key) { |
|
156 | + if (null === $key){ |
|
157 | 157 | return $meta; |
158 | 158 | } |
159 | 159 |
@@ -27,23 +27,28 @@ discard block |
||
27 | 27 | |
28 | 28 | public function __toString(): string |
29 | 29 | { |
30 | - try { |
|
30 | + try |
|
31 | + { |
|
31 | 32 | return $this->getContents(); |
32 | - } catch (\Exception) { |
|
33 | + } |
|
34 | + catch (\Exception) |
|
35 | + { |
|
33 | 36 | return ''; |
34 | 37 | } |
35 | 38 | } |
36 | 39 | |
37 | 40 | public function close(): void |
38 | 41 | { |
39 | - if ($this->stream instanceof \Generator) { |
|
42 | + if ($this->stream instanceof \Generator) |
|
43 | + { |
|
40 | 44 | $this->detach(); |
41 | 45 | } |
42 | 46 | } |
43 | 47 | |
44 | 48 | public function detach() |
45 | 49 | { |
46 | - if (!$this->stream instanceof \Generator) { |
|
50 | + if (!$this->stream instanceof \Generator) |
|
51 | + { |
|
47 | 52 | return null; |
48 | 53 | } |
49 | 54 | $this->stream = null; |
@@ -81,7 +86,8 @@ discard block |
||
81 | 86 | |
82 | 87 | public function rewind(): void |
83 | 88 | { |
84 | - if ($this->stream instanceof \Generator) { |
|
89 | + if ($this->stream instanceof \Generator) |
|
90 | + { |
|
85 | 91 | $this->stream->rewind(); |
86 | 92 | } |
87 | 93 | $this->caret = 0; |
@@ -105,26 +111,34 @@ discard block |
||
105 | 111 | |
106 | 112 | public function read($length): string |
107 | 113 | { |
108 | - if (!$this->readable) { |
|
114 | + if (!$this->readable) |
|
115 | + { |
|
109 | 116 | throw new RuntimeException('Cannot read from non-readable stream.'); |
110 | 117 | } |
111 | - if (!$this->stream instanceof \Generator) { |
|
118 | + if (!$this->stream instanceof \Generator) |
|
119 | + { |
|
112 | 120 | throw new RuntimeException('Cannot read from detached stream.'); |
113 | 121 | } |
114 | - do { |
|
115 | - if ($this->started) { |
|
122 | + do |
|
123 | + { |
|
124 | + if ($this->started) |
|
125 | + { |
|
116 | 126 | $read = (string)$this->stream->send(null); |
117 | - } else { |
|
127 | + } |
|
128 | + else |
|
129 | + { |
|
118 | 130 | $this->started = true; |
119 | 131 | $read = (string)$this->stream->current(); |
120 | 132 | } |
121 | - if (!$this->stream->valid()) { |
|
133 | + if (!$this->stream->valid()) |
|
134 | + { |
|
122 | 135 | $read .= $this->stream->getReturn(); |
123 | 136 | break; |
124 | 137 | } |
125 | 138 | } while ($read === ''); |
126 | 139 | $this->caret += \strlen($read); |
127 | - if (!$this->stream->valid()) { |
|
140 | + if (!$this->stream->valid()) |
|
141 | + { |
|
128 | 142 | $this->size = $this->caret; |
129 | 143 | } |
130 | 144 | return $read; |
@@ -132,11 +146,13 @@ discard block |
||
132 | 146 | |
133 | 147 | public function getContents(): string |
134 | 148 | { |
135 | - if (!$this->stream instanceof \Generator) { |
|
149 | + if (!$this->stream instanceof \Generator) |
|
150 | + { |
|
136 | 151 | throw new RuntimeException('Unable to read stream contents.'); |
137 | 152 | } |
138 | 153 | $content = ''; |
139 | - do { |
|
154 | + do |
|
155 | + { |
|
140 | 156 | $content .= $this->read(PHP_INT_MAX); |
141 | 157 | } while ($this->stream->valid()); |
142 | 158 | return $content; |
@@ -144,7 +160,8 @@ discard block |
||
144 | 160 | |
145 | 161 | public function getMetadata($key = null) |
146 | 162 | { |
147 | - if (!$this->stream instanceof \Generator) { |
|
163 | + if (!$this->stream instanceof \Generator) |
|
164 | + { |
|
148 | 165 | return $key ? null : []; |
149 | 166 | } |
150 | 167 | |
@@ -153,7 +170,8 @@ discard block |
||
153 | 170 | 'eof' => $this->eof(), |
154 | 171 | ]; |
155 | 172 | |
156 | - if (null === $key) { |
|
173 | + if (null === $key) |
|
174 | + { |
|
157 | 175 | return $meta; |
158 | 176 | } |
159 | 177 |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | { |
26 | 26 | private ?RequestHandlerInterface $handler = null; |
27 | 27 | private readonly TracerFactoryInterface $tracerFactory; |
28 | - private readonly Pipeline|LazyPipeline $pipeline; |
|
28 | + private readonly Pipeline | LazyPipeline $pipeline; |
|
29 | 29 | |
30 | 30 | public function __construct( |
31 | 31 | private readonly HttpConfig $config, |
32 | - Pipeline|LazyPipeline $pipeline, |
|
32 | + Pipeline | LazyPipeline $pipeline, |
|
33 | 33 | private readonly ResponseFactoryInterface $responseFactory, |
34 | 34 | private readonly ContainerInterface $container, |
35 | 35 | ?TracerFactoryInterface $tracerFactory = null, |
36 | 36 | private readonly ?EventDispatcherInterface $dispatcher = null, |
37 | - ) { |
|
38 | - if ($pipeline instanceof Pipeline) { |
|
39 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
37 | + ){ |
|
38 | + if ($pipeline instanceof Pipeline){ |
|
39 | + foreach ($this->config->getMiddleware() as $middleware){ |
|
40 | 40 | $pipeline->pushMiddleware($this->container->get($middleware)); |
41 | 41 | } |
42 | - } else { |
|
42 | + }else{ |
|
43 | 43 | $pipeline = $pipeline->withAddedMiddleware( |
44 | 44 | ...$this->config->getMiddleware() |
45 | 45 | ); |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @internal |
55 | 55 | */ |
56 | - public function getPipeline(): Pipeline|LazyPipeline |
|
56 | + public function getPipeline(): Pipeline | LazyPipeline |
|
57 | 57 | { |
58 | 58 | return $this->pipeline; |
59 | 59 | } |
60 | 60 | |
61 | - public function setHandler(callable|RequestHandlerInterface $handler): self |
|
61 | + public function setHandler(callable | RequestHandlerInterface $handler): self |
|
62 | 62 | { |
63 | 63 | $this->handler = $handler instanceof RequestHandlerInterface |
64 | 64 | ? $handler |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
79 | 79 | |
80 | - if (!$this->handler instanceof \Psr\Http\Server\RequestHandlerInterface) { |
|
80 | + if (!$this->handler instanceof \Psr\Http\Server\RequestHandlerInterface){ |
|
81 | 81 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
82 | 82 | } |
83 | 83 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | callback: $callback, |
108 | 108 | attributes: [ |
109 | 109 | 'http.method' => $request->getMethod(), |
110 | - 'http.url' => (string) $request->getUri(), |
|
110 | + 'http.url' => (string)$request->getUri(), |
|
111 | 111 | 'http.headers' => \array_map( |
112 | 112 | static fn (array $values): string => \implode(',', $values), |
113 | 113 | $request->getHeaders(), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | traceKind: TraceKind::SERVER, |
118 | 118 | ); |
119 | 119 | |
120 | - foreach ($tracer->getContext() as $key => $value) { |
|
120 | + foreach ($tracer->getContext() as $key => $value){ |
|
121 | 121 | $response = $response->withHeader($key, $value); |
122 | 122 | } |
123 | 123 |
@@ -35,11 +35,15 @@ discard block |
||
35 | 35 | ?TracerFactoryInterface $tracerFactory = null, |
36 | 36 | private readonly ?EventDispatcherInterface $dispatcher = null, |
37 | 37 | ) { |
38 | - if ($pipeline instanceof Pipeline) { |
|
39 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
38 | + if ($pipeline instanceof Pipeline) |
|
39 | + { |
|
40 | + foreach ($this->config->getMiddleware() as $middleware) |
|
41 | + { |
|
40 | 42 | $pipeline->pushMiddleware($this->container->get($middleware)); |
41 | 43 | } |
42 | - } else { |
|
44 | + } |
|
45 | + else |
|
46 | + { |
|
43 | 47 | $pipeline = $pipeline->withAddedMiddleware( |
44 | 48 | ...$this->config->getMiddleware() |
45 | 49 | ); |
@@ -77,7 +81,8 @@ discard block |
||
77 | 81 | |
78 | 82 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
79 | 83 | |
80 | - if (!$this->handler instanceof \Psr\Http\Server\RequestHandlerInterface) { |
|
84 | + if (!$this->handler instanceof \Psr\Http\Server\RequestHandlerInterface) |
|
85 | + { |
|
81 | 86 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
82 | 87 | } |
83 | 88 | |
@@ -117,7 +122,8 @@ discard block |
||
117 | 122 | traceKind: TraceKind::SERVER, |
118 | 123 | ); |
119 | 124 | |
120 | - foreach ($tracer->getContext() as $key => $value) { |
|
125 | + foreach ($tracer->getContext() as $key => $value) |
|
126 | + { |
|
121 | 127 | $response = $response->withHeader($key, $value); |
122 | 128 | } |
123 | 129 |