@@ -58,10 +58,10 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | public function getChunkSize(): ?int |
| 60 | 60 | { |
| 61 | - if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] < 0) { |
|
| 61 | + if (\is_null($this->config['chunkSize']) || (int)$this->config['chunkSize'] < 0){ |
|
| 62 | 62 | return null; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - return (int) $this->config['chunkSize']; |
|
| 65 | + return (int)$this->config['chunkSize']; |
|
| 66 | 66 | } |
| 67 | 67 | } |
@@ -58,7 +58,8 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | public function getChunkSize(): ?int |
| 60 | 60 | { |
| 61 | - if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] < 0) { |
|
| 61 | + if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] < 0) |
|
| 62 | + { |
|
| 62 | 63 | return null; |
| 63 | 64 | } |
| 64 | 65 | |
@@ -43,15 +43,15 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | public function getHandler(): ?Autowire |
| 45 | 45 | { |
| 46 | - if (empty($this->config['handler'])) { |
|
| 46 | + if (empty($this->config['handler'])){ |
|
| 47 | 47 | return null; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if ($this->config['handler'] instanceof Autowire) { |
|
| 50 | + if ($this->config['handler'] instanceof Autowire){ |
|
| 51 | 51 | return $this->config['handler']; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if (\class_exists($this->config['handler'])) { |
|
| 54 | + if (\class_exists($this->config['handler'])){ |
|
| 55 | 55 | return new Autowire($this->config['handler']); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -43,15 +43,18 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | public function getHandler(): ?Autowire |
| 45 | 45 | { |
| 46 | - if (empty($this->config['handler'])) { |
|
| 46 | + if (empty($this->config['handler'])) |
|
| 47 | + { |
|
| 47 | 48 | return null; |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - if ($this->config['handler'] instanceof Autowire) { |
|
| 51 | + if ($this->config['handler'] instanceof Autowire) |
|
| 52 | + { |
|
| 51 | 53 | return $this->config['handler']; |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | - if (\class_exists($this->config['handler'])) { |
|
| 56 | + if (\class_exists($this->config['handler'])) |
|
| 57 | + { |
|
| 55 | 58 | return new Autowire($this->config['handler']); |
| 56 | 59 | } |
| 57 | 60 | |
@@ -10,33 +10,33 @@ |
||
| 10 | 10 | |
| 11 | 11 | final class PhpSerializer implements SerializerInterface |
| 12 | 12 | { |
| 13 | - public function serialize(mixed $payload): string|\Stringable |
|
| 13 | + public function serialize(mixed $payload): string | \Stringable |
|
| 14 | 14 | { |
| 15 | 15 | return \serialize($payload); |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
|
| 18 | + public function unserialize(\Stringable | string $payload, object | string | null $type = null): mixed |
|
| 19 | 19 | { |
| 20 | - if (\is_object($type)) { |
|
| 20 | + if (\is_object($type)){ |
|
| 21 | 21 | $type = $type::class; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)) { |
|
| 24 | + if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)){ |
|
| 25 | 25 | throw new InvalidArgumentException(\sprintf('Class or interface `%s` doesn\'t exist.', $type)); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | return $this->runUnserialize($payload, $type); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - private function runUnserialize(\Stringable|string $payload, ?string $type = null): mixed |
|
| 31 | + private function runUnserialize(\Stringable | string $payload, ?string $type = null): mixed |
|
| 32 | 32 | { |
| 33 | - $result = \unserialize((string) $payload, $type ? [] : ['allowed_classes' => false]); |
|
| 33 | + $result = \unserialize((string)$payload, $type ? [] : ['allowed_classes' => false]); |
|
| 34 | 34 | |
| 35 | - if ($result === false) { |
|
| 35 | + if ($result === false){ |
|
| 36 | 36 | throw new UnserializeException('Failed to unserialize data.'); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if ($type !== null && !$result instanceof $type) { |
|
| 39 | + if ($type !== null && !$result instanceof $type){ |
|
| 40 | 40 | throw new InvalidArgumentException(\sprintf( |
| 41 | 41 | 'Data received after unserializing must be of type: `%s`, received `%s`', |
| 42 | 42 | $type, |
@@ -17,11 +17,13 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
| 19 | 19 | { |
| 20 | - if (\is_object($type)) { |
|
| 20 | + if (\is_object($type)) |
|
| 21 | + { |
|
| 21 | 22 | $type = $type::class; |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | - if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)) { |
|
| 25 | + if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)) |
|
| 26 | + { |
|
| 25 | 27 | throw new InvalidArgumentException(\sprintf('Class or interface `%s` doesn\'t exist.', $type)); |
| 26 | 28 | } |
| 27 | 29 | |
@@ -32,11 +34,13 @@ discard block |
||
| 32 | 34 | { |
| 33 | 35 | $result = \unserialize((string) $payload, $type ? [] : ['allowed_classes' => false]); |
| 34 | 36 | |
| 35 | - if ($result === false) { |
|
| 37 | + if ($result === false) |
|
| 38 | + { |
|
| 36 | 39 | throw new UnserializeException('Failed to unserialize data.'); |
| 37 | 40 | } |
| 38 | 41 | |
| 39 | - if ($type !== null && !$result instanceof $type) { |
|
| 42 | + if ($type !== null && !$result instanceof $type) |
|
| 43 | + { |
|
| 40 | 44 | throw new InvalidArgumentException(\sprintf( |
| 41 | 45 | 'Data received after unserializing must be of type: `%s`, received `%s`', |
| 42 | 46 | $type, |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | return ($this->serializeCallback)($payload); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function unserialize(string|\Stringable $payload, string|object|null $type = null): mixed |
|
| 28 | + public function unserialize(string | \Stringable $payload, string | object | null $type = null): mixed |
|
| 29 | 29 | { |
| 30 | 30 | return ($this->unserializeCallback)($payload, $type); |
| 31 | 31 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | interface SerializerInterface |
| 8 | 8 | { |
| 9 | - public function serialize(mixed $payload): string|\Stringable; |
|
| 9 | + public function serialize(mixed $payload): string | \Stringable; |
|
| 10 | 10 | |
| 11 | - public function unserialize(string|\Stringable $payload, string|object|null $type = null): mixed; |
|
| 11 | + public function unserialize(string | \Stringable $payload, string | object | null $type = null): mixed; |
|
| 12 | 12 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function __construct(array $serializers = []) |
| 15 | 15 | { |
| 16 | - foreach ($serializers as $name => $serializer) { |
|
| 16 | + foreach ($serializers as $name => $serializer){ |
|
| 17 | 17 | $this->register($name, $serializer); |
| 18 | 18 | } |
| 19 | 19 | } |
@@ -13,7 +13,8 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function __construct(array $serializers = []) |
| 15 | 15 | { |
| 16 | - foreach ($serializers as $name => $serializer) { |
|
| 16 | + foreach ($serializers as $name => $serializer) |
|
| 17 | + { |
|
| 17 | 18 | $this->register($name, $serializer); |
| 18 | 19 | } |
| 19 | 20 | } |
@@ -1,3 +1,3 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -return ; |
|
| 3 | +return; |
|
@@ -23,9 +23,11 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function has(string $section): bool |
| 25 | 25 | { |
| 26 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 26 | + foreach ($this->loaderExtensions() as $extension) |
|
| 27 | + { |
|
| 27 | 28 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 28 | - if (\file_exists($filename)) { |
|
| 29 | + if (\file_exists($filename)) |
|
| 30 | + { |
|
| 29 | 31 | return true; |
| 30 | 32 | } |
| 31 | 33 | } |
@@ -35,15 +37,20 @@ discard block |
||
| 35 | 37 | |
| 36 | 38 | public function load(string $section): array |
| 37 | 39 | { |
| 38 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 40 | + foreach ($this->loaderExtensions() as $extension) |
|
| 41 | + { |
|
| 39 | 42 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 40 | - if (!\file_exists($filename)) { |
|
| 43 | + if (!\file_exists($filename)) |
|
| 44 | + { |
|
| 41 | 45 | continue; |
| 42 | 46 | } |
| 43 | 47 | |
| 44 | - try { |
|
| 48 | + try |
|
| 49 | + { |
|
| 45 | 50 | return $this->getLoader($extension)->loadFile($section, $filename); |
| 46 | - } catch (LoaderException $e) { |
|
| 51 | + } |
|
| 52 | + catch (LoaderException $e) |
|
| 53 | + { |
|
| 47 | 54 | throw new LoaderException("Unable to load config `{$section}`: {$e->getMessage()}", $e->getCode(), $e); |
| 48 | 55 | } |
| 49 | 56 | } |
@@ -17,15 +17,15 @@ discard block |
||
| 17 | 17 | public function __construct( |
| 18 | 18 | string $directory, |
| 19 | 19 | private readonly array $loaders = [], |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | $this->directory = \rtrim($directory, '/'); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function has(string $section): bool |
| 25 | 25 | { |
| 26 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 26 | + foreach ($this->loaderExtensions() as $extension){ |
|
| 27 | 27 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 28 | - if (\file_exists($filename)) { |
|
| 28 | + if (\file_exists($filename)){ |
|
| 29 | 29 | return true; |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function load(string $section): array |
| 37 | 37 | { |
| 38 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 38 | + foreach ($this->loaderExtensions() as $extension){ |
|
| 39 | 39 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 40 | - if (!\file_exists($filename)) { |
|
| 40 | + if (!\file_exists($filename)){ |
|
| 41 | 41 | continue; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - try { |
|
| 44 | + try{ |
|
| 45 | 45 | return $this->getLoader($extension)->loadFile($section, $filename); |
| 46 | - } catch (LoaderException $e) { |
|
| 46 | + }catch (LoaderException $e){ |
|
| 47 | 47 | throw new LoaderException("Unable to load config `{$section}`: {$e->getMessage()}", $e->getCode(), $e); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | $content = \file_get_contents($filename); |
| 14 | 14 | $data = \json_decode($content, true); |
| 15 | 15 | |
| 16 | - if (\is_null($data)) { |
|
| 16 | + if (\is_null($data)){ |
|
| 17 | 17 | throw new LoaderException(\json_last_error_msg(), \json_last_error()); |
| 18 | 18 | } |
| 19 | 19 | |
@@ -13,7 +13,8 @@ |
||
| 13 | 13 | $content = \file_get_contents($filename); |
| 14 | 14 | $data = \json_decode($content, true); |
| 15 | 15 | |
| 16 | - if (\is_null($data)) { |
|
| 16 | + if (\is_null($data)) |
|
| 17 | + { |
|
| 17 | 18 | throw new LoaderException(\json_last_error_msg(), \json_last_error()); |
| 18 | 19 | } |
| 19 | 20 | |