Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"symfony/doctrine-messenger": "^6.0.19 || ^6.2.10",
"contributte/console": "^0.10.0",
"contributte/event-dispatcher": "^0.9.0",
"contributte/qa": "^0.4.0",
"contributte/qa": "^0.3.2",
"contributte/tester": "^0.3.0",
"contributte/phpstan": "^0.1.0",
"tracy/tracy": "^2.10.2"
Expand Down
18 changes: 0 additions & 18 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,7 @@ parameters:
count: 1
path: src/DI/Pass/HandlerPass.php

-
message: """
#^Fetching class constant class of deprecated class Symfony\\\\Component\\\\Messenger\\\\Handler\\\\MessageHandlerInterface\\:
since Symfony 6\\.2, use the \\{@see AsMessageHandler\\} attribute instead$#
"""
count: 1
path: src/DI/Pass/HandlerPass.php

-
message: "#^Class ReflectionIntersectionType not found\\.$#"
count: 1
path: src/DI/Utils/Reflector.php

-
message: "#^Dead catch \\- ReflectionException is never thrown in the try block\\.$#"
count: 1
path: src/DI/Utils/Reflector.php

-
message: "#^PHPDoc tag @var for variable \\$type contains unknown class ReflectionIntersectionType\\.$#"
count: 1
path: src/DI/Utils/Reflector.php
7 changes: 4 additions & 3 deletions src/DI/MessengerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
use Contributte\Messenger\DI\Pass\TransportFactoryPass;
use Contributte\Messenger\DI\Pass\TransportPass;
use Nette\DI\Definitions\Statement;
use Nette\DI\CompilerExtension;

Check failure on line 17 in src/DI/MessengerExtension.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Use statements should be sorted alphabetically. The first wrong one is Nette\DI\CompilerExtension.
use Nette\PhpGenerator\ClassType;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nette\Utils\ArrayHash;
use stdClass;
use Symfony\Component\Messenger\MessageBusInterface;
use function is_string;

/**
* @property-write stdClass $config
Expand Down Expand Up @@ -61,9 +62,9 @@

public function getConfigSchema(): Schema
{
$expectClass = Expect::string()->required()->assert(fn ($input) => class_exists($input) || interface_exists($input));
$expectClass = Expect::string()->required()->assert(fn ($input): bool => is_string($input) && (class_exists($input) || interface_exists($input)));
$expectService = Expect::anyOf(
Expect::string()->required()->assert(fn ($input) => str_starts_with($input, '@') || class_exists($input) || interface_exists($input)),
Expect::string()->required()->assert(fn ($input): bool => is_string($input) && (str_starts_with($input, '@') || class_exists($input) || interface_exists($input))),
Expect::type(Statement::class)->required(),
);
$expectLoosyService = Expect::anyOf(
Expand All @@ -82,7 +83,7 @@
'allowNoHandlers' => Expect::bool(false),
'allowNoSenders' => Expect::bool(true),
'autowired' => Expect::bool(),
'class' => (clone $expectClass)->required(false)->assert(fn ($input) => is_subclass_of($input, MessageBusInterface::class), 'Specified bus class must implements "MessageBusInterface"'),
'class' => (clone $expectClass)->required(false)->assert(fn ($input): bool => is_string($input) && is_subclass_of($input, MessageBusInterface::class), 'Specified bus class must implements "MessageBusInterface"'),
'wrapper' => (clone $expectClass)->required(false),
]),
Expect::string()->required(),
Expand Down
13 changes: 7 additions & 6 deletions src/DI/Pass/EventPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
use Symfony\Component\Messenger\EventListener\DispatchPcntlSignalListener;
use Symfony\Component\Messenger\EventListener\SendFailedMessageForRetryListener;
use Symfony\Component\Messenger\EventListener\SendFailedMessageToFailureTransportListener;
use Symfony\Component\Messenger\EventListener\StopWorkerOnSignalsListener;
use Symfony\Component\Messenger\EventListener\StopWorkerOnSigtermSignalListener;

class EventPass extends AbstractPass
{

private const STOP_WORKER_ON_SIGNALS_LISTENER = 'Symfony\\Component\\Messenger\\EventListener\\StopWorkerOnSignalsListener';
private const STOP_WORKER_ON_SIGTERM_SIGNAL_LISTENER = 'Symfony\\Component\\Messenger\\EventListener\\StopWorkerOnSigtermSignalListener';

/**
* Register services
*/
Expand Down Expand Up @@ -97,13 +98,13 @@ public function beforePassCompile(): void
]);

// Stop on signal
if (class_exists(StopWorkerOnSignalsListener::class)) {
if (class_exists(self::STOP_WORKER_ON_SIGNALS_LISTENER)) {
$dispatcher->addSetup('addSubscriber', [
new Statement(StopWorkerOnSignalsListener::class, [null, $this->prefix('@logger.logger')]),
new Statement(self::STOP_WORKER_ON_SIGNALS_LISTENER, [null, $this->prefix('@logger.logger')]),
]);
} elseif (class_exists(StopWorkerOnSigtermSignalListener::class)) {
} elseif (class_exists(self::STOP_WORKER_ON_SIGTERM_SIGNAL_LISTENER)) {
$dispatcher->addSetup('addSubscriber', [
new Statement(StopWorkerOnSigtermSignalListener::class, [$this->prefix('@logger.logger')]), // @phpstan-ignore-line
new Statement(self::STOP_WORKER_ON_SIGTERM_SIGNAL_LISTENER, [$this->prefix('@logger.logger')]),
]);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/DI/Pass/HandlerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Nette\DI\Definitions\ServiceDefinition;
use ReflectionClass;
use ReflectionException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use function array_merge;
use function interface_exists;
use function is_numeric;
use function is_string;

Expand All @@ -19,6 +19,7 @@ class HandlerPass extends AbstractPass

private const DEFAULT_METHOD_NAME = '__invoke';
private const DEFAULT_PRIORITY = 0;
private const MESSAGE_HANDLER_INTERFACE = 'Symfony\\Component\\Messenger\\Handler\\MessageHandlerInterface';

/**
* Register services
Expand Down Expand Up @@ -97,7 +98,10 @@ private function getMessageHandlers(): array
// Find all handlers
$serviceHandlers = [];
$serviceHandlers = array_merge($serviceHandlers, array_keys($builder->findByTag(MessengerExtension::HANDLER_TAG)));
$serviceHandlers = array_merge($serviceHandlers, array_keys($builder->findByType(MessageHandlerInterface::class)));

if (interface_exists(self::MESSAGE_HANDLER_INTERFACE)) {
$serviceHandlers = array_merge($serviceHandlers, array_keys($builder->findByType(self::MESSAGE_HANDLER_INTERFACE)));
}

foreach ($builder->getDefinitions() as $definition) {
/** @var class-string $class */
Expand Down
14 changes: 10 additions & 4 deletions src/DI/Utils/Reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
use ReflectionAttribute;
use ReflectionClass;
use ReflectionException;
use ReflectionIntersectionType;
use ReflectionNamedType;
use ReflectionType;
use ReflectionUnionType;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Handler\Acknowledger;
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
use function array_map;
use function array_merge;
use function class_exists;
use function is_a;

final class Reflector
{
Expand Down Expand Up @@ -66,16 +68,16 @@
throw new LogicalException(sprintf('Handler must have "%s::%s()" method.', $class, $options['method']));
}

if ($rcMethod->getNumberOfParameters() !== 1 && !$rc->implementsInterface( BatchHandlerInterface::class)) {

Check failure on line 71 in src/DI/Utils/Reflector.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Space after opening parenthesis of function call prohibited
throw new LogicalException(sprintf('Only one parameter is allowed in "%s::%s()."', $class, $options['method']));
}

if ($rc->implementsInterface( BatchHandlerInterface::class)) {

Check failure on line 75 in src/DI/Utils/Reflector.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Space after opening parenthesis of function call prohibited
if ($rcMethod->getNumberOfParameters() !== 2) {
throw new LogicalException(sprintf('Exactly two parameters are required in "%s::%s()."', $class, $options['method']));
}

/** @var ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null $type */
/** @var ReflectionType|null $type */
$type = $rcMethod->getParameters()[1]->getType();

if (!$type instanceof ReflectionNamedType) {
Expand All @@ -87,7 +89,7 @@
}
}

/** @var ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null $type */
/** @var ReflectionType|null $type */
$type = $rcMethod->getParameters()[0]->getType();

if ($type === null) {
Expand All @@ -98,10 +100,14 @@
throw new LogicalException(sprintf('Union parameter type for "%s::%s() is not supported."', $class, $options['method']));
}

if ($type instanceof ReflectionIntersectionType) {
if (class_exists('ReflectionIntersectionType') && is_a($type, 'ReflectionIntersectionType')) {
throw new LogicalException(sprintf('Intersection parameter type for "%s::%s() is not supported."', $class, $options['method']));
}

if (!$type instanceof ReflectionNamedType) {
throw new LogicalException(sprintf('Parameter type for "%s::%s() is not supported."', $class, $options['method']));
}

return $type->getName();
}

Expand Down
Loading