Skip to content

Commit

Permalink
chore: fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Jan 17, 2025
1 parent d4fff03 commit 7032509
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 89 deletions.
14 changes: 1 addition & 13 deletions lib/Adapter/Serializer/MessengerSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,12 @@

class MessengerSerializer implements MessengerSerializerInterface
{
private SerializerInterface $serializer;
private string $format;

/**
* @var array<string, mixed> $context
* @phpstan-var array{groups?: string[], object_to_populate?: object} $context
*/
private array $context;

/**
* @param array<string, mixed> $context
* @phpstan-param array{groups?: string[], object_to_populate?: object} $context
*/
public function __construct(SerializerInterface $serializer, string $format = 'json', array $context = [])
public function __construct(private SerializerInterface $serializer, private string $format = 'json', private array $context = [])
{
$this->serializer = $serializer;
$this->format = $format;
$this->context = $context;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/DependencyInjection/Compiler/CheckDependencyPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function process(ContainerBuilder $container): void

try {
$urlParams = parse_url($url);
} catch (UrlException $e) {
} catch (UrlException) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function process(ContainerBuilder $container): void

try {
$urlParams = parse_url($url);
} catch (UrlException $e) {
} catch (UrlException) {
continue;
}

Expand Down
17 changes: 1 addition & 16 deletions lib/Middleware/DoctrineClearIdentityMapMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,14 @@
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Middleware\StackInterface;
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
use TypeError;

use function get_class;
use function gettype;
use function is_object;
use function Safe\sprintf;

/**
* Middleware that clears the doctrine ORM identity map after processing a message.
*/
class DoctrineClearIdentityMapMiddleware implements MiddlewareInterface
{
/** @var ManagerRegistryV2|ManagerRegistryV3|null */
private $doctrine;

/** @param ManagerRegistryV2|ManagerRegistryV3|null $doctrine */
public function __construct($doctrine)
public function __construct(private ManagerRegistryV2|ManagerRegistryV3|null $doctrine = null)
{
if ($doctrine !== null && ! $doctrine instanceof ManagerRegistryV2 && ! $doctrine instanceof ManagerRegistryV3) {
throw new TypeError(sprintf('Argument 1 passed to %s must be an instance of Doctrine\Persistence\ManagerRegistry, Doctrine\Common\Persistence\ManagerRegistry or null, %s given', __METHOD__, is_object($doctrine) ? 'instance of ' . get_class($doctrine) : gettype($doctrine)));
}

$this->doctrine = $doctrine;
}

public function handle(Envelope $envelope, StackInterface $stack): Envelope
Expand Down
25 changes: 12 additions & 13 deletions lib/Transport/Dbal/DbalReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use function bin2hex;
use function class_exists;
use function is_resource;
use function is_string;
use function json_decode;
use function microtime;
use function Safe\hex2bin;
Expand All @@ -40,18 +41,17 @@
class DbalReceiver implements ReceiverInterface, MessageCountAwareInterface, ListableReceiverInterface
{
private SerializerInterface $serializer;
private string $tableName;
private Connection $connection;
private float $redeliverMessagesLastExecutedAt;
private float $removeExpiredMessagesLastExecutedAt;
private QueryBuilder $select;
private QueryBuilder $update;
private int $retryingSafetyCounter = 0;

public function __construct(Connection $connection, string $tableName, ?SerializerInterface $serializer = null)
{
$this->connection = $connection;
$this->tableName = $tableName;
public function __construct(
private readonly Connection $connection,
private readonly string $tableName,
SerializerInterface|null $serializer = null,
) {
$this->serializer = $serializer ?? Serializer::create();

$this->select = $this->connection->createQueryBuilder()
Expand Down Expand Up @@ -115,7 +115,7 @@ public function reject(Envelope $envelope): void
/**
* {@inheritDoc}
*/
public function all(?int $limit = null): iterable
public function all(int|null $limit = null): iterable
{
$result = $this->connection->createQueryBuilder()
->select('body', 'headers', 'id')
Expand All @@ -139,7 +139,7 @@ public function all(?int $limit = null): iterable
*
* @param mixed $id
*/
public function find($id): ?Envelope
public function find($id): Envelope|null
{
if (preg_match('/^[0-9a-f]+$/i', $id)) {
$id = hex2bin($id);
Expand Down Expand Up @@ -180,17 +180,16 @@ private function hydrate(array $row): Envelope
'headers' => json_decode($row['headers'], true, 512, JSON_THROW_ON_ERROR),
]);

if (is_resource($row['id'])) {
$row['id'] = stream_get_contents($row['id']);
}
$id = is_resource($row['id']) ? stream_get_contents($row['id']) : $row['id'];
assert(is_string($id));

return $envelope->with(new TransportMessageIdStamp(bin2hex($row['id'])));
return $envelope->with(new TransportMessageIdStamp(bin2hex($id)));
}

/**
* Fetches a message if it is any.
*/
private function fetchMessage(): ?Envelope
private function fetchMessage(): Envelope|null
{
$deliveryId = class_exists(SymfonyUuid::class) ? SymfonyUuid::v4()->toRfc4122() : Uuid::uuid4()->toString();
$result = $this->select
Expand Down
6 changes: 1 addition & 5 deletions lib/Transport/Dbal/DbalSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@
class DbalSender implements SenderInterface
{
private SerializerInterface $serializer;
private string $tableName;
private Connection $connection;

public function __construct(Connection $connection, string $tableName, ?SerializerInterface $serializer = null)
public function __construct(private Connection $connection, private string $tableName, SerializerInterface|null $serializer = null)
{
$this->connection = $connection;
$this->tableName = $tableName;
$this->serializer = $serializer ?? Serializer::create();
}

Expand Down
14 changes: 3 additions & 11 deletions lib/Transport/Dbal/DbalTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@
*/
class DbalTransport implements TransportInterface, ListableReceiverInterface, MessageCountAwareInterface, SetupableTransportInterface
{
private Connection $connection;
private ?SerializerInterface $serializer;
private DbalReceiver $receiver;
private DbalSender $sender;

/** @var array<string, mixed> $options */
private array $options;

/** @param array<string, mixed> $options */
public function __construct(Connection $connection, ?SerializerInterface $serializer = null, array $options = [])
public function __construct(private Connection $connection, private SerializerInterface|null $serializer = null, private array $options = [])
{
$this->connection = $connection;
$this->serializer = $serializer;
$this->options = $options;
}

/**
Expand Down Expand Up @@ -94,7 +86,7 @@ public function reject(Envelope $envelope): void
*
* @return iterable<Envelope>
*/
public function all(?int $limit = null): iterable
public function all(int|null $limit = null): iterable
{
yield from ($this->receiver ?? $this->getReceiver())->all($limit);
}
Expand All @@ -104,7 +96,7 @@ public function all(?int $limit = null): iterable
*
* @param mixed $id
*/
public function find($id): ?Envelope
public function find($id): Envelope|null
{
return ($this->receiver ?? $this->getReceiver())->find($id);
}
Expand Down
16 changes: 1 addition & 15 deletions lib/Transport/Dbal/DbalTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
use TypeError;

use function array_merge;
use function assert;
use function explode;
use function get_class;
use function gettype;
use function in_array;
use function is_array;
use function is_file;
use function is_object;
use function is_string;
use function parse_str;
use function pathinfo;
use function Safe\parse_url;
use function Safe\preg_replace;
use function sprintf;
use function strpos;
use function strrev;
use function substr;
Expand All @@ -55,17 +50,8 @@ class DbalTransportFactory implements TransportFactoryInterface
'sqlite3',
];

/** @var ManagerRegistryV2|ManagerRegistryV3|null */
private $managerRegistry;

/** @param ManagerRegistryV2|ManagerRegistryV3|null $managerRegistry */
public function __construct($managerRegistry = null)
public function __construct(private ManagerRegistryV2|ManagerRegistryV3|null $managerRegistry = null)
{
if ($managerRegistry !== null && ! $managerRegistry instanceof ManagerRegistryV2 && ! $managerRegistry instanceof ManagerRegistryV3) {
throw new TypeError(sprintf('Argument 1 passed to %s must be an instance of Doctrine\Persistence\ManagerRegistry, Doctrine\Common\Persistence\ManagerRegistry or null, %s given', __METHOD__, is_object($managerRegistry) ? 'instance of ' . get_class($managerRegistry) : gettype($managerRegistry)));
}

$this->managerRegistry = $managerRegistry;
}

/** @param array<string, mixed> $options */
Expand Down
10 changes: 4 additions & 6 deletions lib/Transport/Mongo/MongoReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
class MongoReceiver implements ReceiverInterface, ListableReceiverInterface, MessageCountAwareInterface
{
private SerializerInterface $serializer;
private Collection $collection;
private float $removeExpiredMessagesLastExecutedAt;
private int $retryingSafetyCounter = 0;

public function __construct(Collection $collection, ?SerializerInterface $serializer = null)
public function __construct(private Collection $collection, SerializerInterface|null $serializer = null)
{
$this->collection = $collection;
$this->serializer = $serializer ?? Serializer::create();
}

Expand Down Expand Up @@ -81,7 +79,7 @@ public function reject(Envelope $envelope): void
/**
* {@inheritDoc}
*/
public function all(?int $limit = null): iterable
public function all(int|null $limit = null): iterable
{
$options = [];
if ($options !== null) {
Expand All @@ -99,7 +97,7 @@ public function all(?int $limit = null): iterable
*
* @param mixed $id
*/
public function find($id): ?Envelope
public function find($id): Envelope|null
{
$id = $id instanceof ObjectId ? $id : new ObjectId($id);

Expand Down Expand Up @@ -131,7 +129,7 @@ private function hydrate(array $row): Envelope
/**
* Fetches a message if it is any.
*/
private function fetchMessage(): ?Envelope
private function fetchMessage(): Envelope|null
{
$deliveryId = class_exists(SymfonyUuid::class) ? SymfonyUuid::v4()->toRfc4122() : Uuid::uuid4()->toString();
$now = time();
Expand Down
4 changes: 1 addition & 3 deletions lib/Transport/Mongo/MongoSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@
*/
class MongoSender implements SenderInterface
{
private Collection $collection;
private SerializerInterface $serializer;

public function __construct(Collection $collection, ?SerializerInterface $serializer = null)
public function __construct(private Collection $collection, SerializerInterface|null $serializer = null)
{
$this->collection = $collection;
$this->serializer = $serializer ?? Serializer::create();
}

Expand Down
8 changes: 3 additions & 5 deletions lib/Transport/Mongo/MongoTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
class MongoTransport implements TransportInterface, ListableReceiverInterface, MessageCountAwareInterface
{
private Collection $collection;
private ?SerializerInterface $serializer;
private MongoReceiver $receiver;
private MongoSender $sender;

/** @param array<string, mixed> $options */
public function __construct(Client $client, ?SerializerInterface $serializer = null, array $options = [])
public function __construct(Client $client, private SerializerInterface|null $serializer = null, array $options = [])
{
$this->collection = $client->{$options['database_name']}->{$options['collection_name']};
$this->serializer = $serializer;
}

/**
Expand All @@ -50,7 +48,7 @@ public function reject(Envelope $envelope): void
/**
* {@inheritDoc}
*/
public function all(?int $limit = null): iterable
public function all(int|null $limit = null): iterable
{
yield from ($this->receiver ?? $this->getReceiver())->all($limit);
}
Expand All @@ -60,7 +58,7 @@ public function all(?int $limit = null): iterable
*
* @param mixed $id
*/
public function find($id): ?Envelope
public function find($id): Envelope|null
{
return ($this->receiver ?? $this->getReceiver())->find($id);
}
Expand Down

0 comments on commit 7032509

Please sign in to comment.