Skip to content

Commit

Permalink
Merge pull request #1207: Apply Spiral Code Style
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 24, 2025
1 parent 594a395 commit 0c7a830
Show file tree
Hide file tree
Showing 80 changed files with 504 additions and 583 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"require": {
"php": ">=8.1",
"ext-json": "*",
"spiral/core": "^3.14.10",
"spiral/hmvc": "^3.14.10",
"spiral/serializer": "^3.14.10",
"spiral/snapshots": "^3.14.10",
"spiral/telemetry": "^3.14.10",
"spiral/tokenizer": "^3.14.10",
"spiral/core": "^3.15",
"spiral/hmvc": "^3.15",
"spiral/serializer": "^3.15",
"spiral/snapshots": "^3.15",
"spiral/telemetry": "^3.15",
"spiral/tokenizer": "^3.15",
"spiral/attributes": "^2.8|^3.0",
"doctrine/inflector": "^1.4|^2.0",
"ramsey/uuid": "^4.2.3",
Expand All @@ -59,7 +59,7 @@
"require-dev": {
"phpunit/phpunit": "^10.1",
"mockery/mockery": "^1.5",
"spiral/boot": "^3.14.10",
"spiral/boot": "^3.15",
"vimeo/psalm": "^5.9"
},
"extra": {
Expand Down
5 changes: 2 additions & 3 deletions src/Attribute/JobHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
class JobHandler
{
public function __construct(
public readonly string $type
) {
}
public readonly string $type,
) {}
}
4 changes: 1 addition & 3 deletions src/Attribute/Queueable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
final class Queueable
{
public function __construct(public ?string $queue = null)
{
}
public function __construct(public ?string $queue = null) {}
}
9 changes: 4 additions & 5 deletions src/Attribute/RetryPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,21 @@
class RetryPolicy
{
/**
* @param 0|positive-int $maxAttempts
* @param int<0, max> $maxAttempts
* @param positive-int $delay in seconds.
*/
public function __construct(
protected readonly int $maxAttempts = 3,
protected readonly int $delay = 1,
protected readonly float $multiplier = 1
) {
}
protected readonly float $multiplier = 1,
) {}

public function getRetryPolicy(): RetryPolicyInterface
{
return new Policy(
maxAttempts: $this->maxAttempts,
delay: $this->delay,
multiplier: $this->multiplier
multiplier: $this->multiplier,
);
}
}
5 changes: 2 additions & 3 deletions src/Attribute/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
class Serializer
{
public function __construct(
public readonly string $serializer
) {
}
public readonly string $serializer,
) {}
}
8 changes: 3 additions & 5 deletions src/Bootloader/QueueBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\Patch\Append;
use Spiral\Core\{BinderInterface, CompatiblePipelineBuilder, FactoryInterface, InterceptableCore, InterceptorPipeline};
use Spiral\Core\{BinderInterface, CompatiblePipelineBuilder, FactoryInterface};
use Spiral\Core\Container\Autowire;
use Spiral\Core\CoreInterceptorInterface;
use Spiral\Queue\JobHandlerLocatorListener;
Expand Down Expand Up @@ -42,7 +42,6 @@ final class QueueBootloader extends Bootloader
TokenizerListenerBootloader::class,
TelemetryBootloader::class,
];

protected const SINGLETONS = [
HandlerRegistryInterface::class => QueueRegistry::class,
SerializerRegistryInterface::class => QueueRegistry::class,
Expand All @@ -55,8 +54,7 @@ final class QueueBootloader extends Bootloader

public function __construct(
private readonly ConfiguratorInterface $config,
) {
}
) {}

public function init(
ContainerInterface $container,
Expand Down Expand Up @@ -86,7 +84,7 @@ public function init(
public function boot(
TokenizerListenerRegistryInterface $listenerRegistry,
JobHandlerLocatorListener $jobHandlerLocator,
SerializerLocatorListener $serializerLocator
SerializerLocatorListener $serializerLocator,
): void {
$listenerRegistry->addListener($jobHandlerLocator);
$listenerRegistry->addListener($serializerLocator);
Expand Down
16 changes: 8 additions & 8 deletions src/Config/QueueConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getAliases(): array
*/
public function getConsumeInterceptors(): array
{
return (array)($this->config['interceptors']['consume'] ?? []);
return (array) ($this->config['interceptors']['consume'] ?? []);
}

/**
Expand All @@ -61,7 +61,7 @@ public function getConsumeInterceptors(): array
*/
public function getPushInterceptors(): array
{
return (array)($this->config['interceptors']['push'] ?? []);
return (array) ($this->config['interceptors']['push'] ?? []);
}

/**
Expand All @@ -82,7 +82,7 @@ public function getDefaultDriver(): string
*/
public function getDriverAliases(): array
{
return (array)($this->config['driverAliases'] ?? []);
return (array) ($this->config['driverAliases'] ?? []);
}

/**
Expand All @@ -101,7 +101,7 @@ public function getConnections(?string $driver = null): array
if (isset($driverAliases[$driver])) {
if (!\is_string($this->config['driverAliases'][$driver])) {
throw new InvalidArgumentException(
\sprintf('Driver alias for `%s` value must be a string', $driver)
\sprintf('Driver alias for `%s` value must be a string', $driver),
);
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public function getConnection(string $name): array

if (!\is_string($driver)) {
throw new InvalidArgumentException(
\sprintf('Driver for queue connection `%s` value must be a string', $name)
\sprintf('Driver for queue connection `%s` value must be a string', $name),
);
}

Expand All @@ -150,7 +150,7 @@ public function getConnection(string $name): array

if (!\is_string($connection['driver'])) {
throw new InvalidArgumentException(
\sprintf('Driver alias for queue connection `%s` value must be a string', $name)
\sprintf('Driver alias for queue connection `%s` value must be a string', $name),
);
}

Expand All @@ -162,12 +162,12 @@ public function getConnection(string $name): array
*/
public function getRegistryHandlers(): array
{
return (array)($this->config['registry']['handlers'] ?? []);
return (array) ($this->config['registry']['handlers'] ?? []);
}

public function getRegistrySerializers(): array
{
return (array)($this->config['registry']['serializers'] ?? []);
return (array) ($this->config['registry']['serializers'] ?? []);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ContainerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ContainerRegistry implements HandlerRegistryInterface
private readonly Inflector $inflector;

public function __construct(
private readonly ContainerInterface $container
private readonly ContainerInterface $container,
) {
$this->inflector = (new InflectorFactory())->build();
}
Expand All @@ -38,7 +38,7 @@ public function getHandler(string $jobType): HandlerInterface
private function className(string $jobType): string
{
$names = \explode('.', $jobType);
$names = \array_map(fn (string $value) => $this->inflector->classify($value), $names);
$names = \array_map(fn(string $value): string => $this->inflector->classify($value), $names);

return \implode('\\', $names);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Core/QueueInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Spiral\Queue\Core;

use ReflectionClass;
use Spiral\Core\Container\InjectorInterface;
use Spiral\Core\Exception\Container\ContainerException;
use Spiral\Queue\Exception\InvalidArgumentException;
Expand All @@ -17,11 +16,10 @@
final class QueueInjector implements InjectorInterface
{
public function __construct(
private readonly QueueConnectionProviderInterface $queueManager
) {
}
private readonly QueueConnectionProviderInterface $queueManager,
) {}

public function createInjection(ReflectionClass $class, ?string $context = null): QueueInterface
public function createInjection(\ReflectionClass $class, ?string $context = null): QueueInterface
{
try {
if ($context === null) {
Expand Down
8 changes: 3 additions & 5 deletions src/Driver/SyncDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ final class SyncDriver implements QueueInterface
use QueueTrait;

public function __construct(
private readonly Handler $coreHandler
) {
}
private readonly Handler $coreHandler,
) {}

/** @inheritdoc */
public function push(string $name, mixed $payload = [], ?OptionsInterface $options = null): string
{
if ($options !== null && $options->getDelay()) {
\sleep($options->getDelay());
}

$id = (string)Uuid::uuid4();
$id = (string) Uuid::uuid4();

$this->coreHandler->handle(
name: $name,
Expand Down
5 changes: 2 additions & 3 deletions src/Event/JobProcessed.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public function __construct(
public readonly string $queue,
public readonly string $id,
public readonly mixed $payload,
public readonly array $headers = []
) {
}
public readonly array $headers = [],
) {}
}
5 changes: 2 additions & 3 deletions src/Event/JobProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public function __construct(
public readonly string $queue,
public readonly string $id,
public readonly mixed $payload,
public readonly array $headers = []
) {
}
public readonly array $headers = [],
) {}
}
4 changes: 1 addition & 3 deletions src/Exception/FailException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\Queue\Exception;

final class FailException extends StateException
{
}
final class FailException extends StateException {}
4 changes: 1 addition & 3 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\Queue\Exception;

class InvalidArgumentException extends QueueException
{
}
class InvalidArgumentException extends QueueException {}
4 changes: 1 addition & 3 deletions src/Exception/JobException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\Queue\Exception;

class JobException extends \RuntimeException
{
}
class JobException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions src/Exception/NotSupportedDriverException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\Queue\Exception;

class NotSupportedDriverException extends \RuntimeException
{
}
class NotSupportedDriverException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions src/Exception/QueueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\Queue\Exception;

class QueueException extends \Exception
{
}
class QueueException extends \Exception {}
2 changes: 1 addition & 1 deletion src/Exception/RetryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class RetryException extends StateException
{
public function __construct(
string $reason = '',
private readonly ?OptionsInterface $options = null
private readonly ?OptionsInterface $options = null,
) {
parent::__construct($reason);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/SerializationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\Queue\Exception;

class SerializationException extends \RuntimeException
{
}
class SerializationException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions src/Exception/StateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\Queue\Exception;

class StateException extends QueueException
{
}
class StateException extends QueueException {}
5 changes: 2 additions & 3 deletions src/Failed/LogFailedJobHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
final class LogFailedJobHandler implements FailedJobHandlerInterface
{
public function __construct(
private readonly ExceptionReporterInterface $reporter
) {
}
private readonly ExceptionReporterInterface $reporter,
) {}

public function handle(string $driver, string $queue, string $job, mixed $payload, \Throwable $e): void
{
Expand Down
7 changes: 3 additions & 4 deletions src/Interceptor/Consume/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ final class Core implements CoreInterface, HandlerInterface
{
public function __construct(
private readonly HandlerRegistryInterface $registry,
private readonly ?EventDispatcherInterface $dispatcher = null
) {
}
private readonly ?EventDispatcherInterface $dispatcher = null,
) {}

/**
* @param-assert TParameters $parameters
Expand Down Expand Up @@ -73,7 +72,7 @@ private function dispatchEvent(string $event, string $name, array $parameters):
queue: $parameters['queue'],
id: $parameters['id'],
payload: $parameters['payload'],
headers: $parameters['headers'] ?? []
headers: $parameters['headers'] ?? [],
));
}
}
11 changes: 6 additions & 5 deletions src/Interceptor/Consume/ErrorHandlerInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
final class ErrorHandlerInterceptor implements LegacyInterceptor, InterceptorInterface
{
public function __construct(
private readonly FailedJobHandlerInterface $handler
) {
}
private readonly FailedJobHandlerInterface $handler,
) {}

/** @psalm-suppress ParamNameMismatch */
/**
* @psalm-suppress ParamNameMismatch
*/
public function process(string $name, string $action, array $parameters, CoreInterface $core): mixed
{
try {
Expand All @@ -31,7 +32,7 @@ public function process(string $name, string $action, array $parameters, CoreInt
$parameters['queue'],
$name,
$parameters['payload'],
$e
$e,
);
}

Expand Down
Loading

0 comments on commit 0c7a830

Please sign in to comment.