From 8ad16466f6242a83caab4fc1b4ec8b67401e673e Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 13:10:22 +0300 Subject: [PATCH 1/8] Issue #72: Replaced deprecated method Signed-off-by: bota --- src/Swoole/Delegators/TCPServerDelegator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index 5bcbf84..e1b0e7d 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -63,7 +63,7 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $commandClass = $commandMap[$commandName]; $application = new Application(); $commandInstance = $container->get($commandClass); - $application->add($commandInstance); + $application->addCommand($commandInstance); $parsedOptions = []; foreach ($args as $arg) { From 2f24bc43699aeade660fd7eff99d151573784062 Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 13:19:42 +0300 Subject: [PATCH 2/8] handle symfony/console compatibility for add/addCommand methods Signed-off-by: bota --- src/Swoole/Delegators/TCPServerDelegator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index e1b0e7d..e7183db 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -23,6 +23,7 @@ use function array_shift; use function explode; use function ltrim; +use function method_exists; use function str_starts_with; use function trim; @@ -63,7 +64,11 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $commandClass = $commandMap[$commandName]; $application = new Application(); $commandInstance = $container->get($commandClass); - $application->addCommand($commandInstance); + if (method_exists($application, 'addCommand')) { + $application->addCommand($commandInstance); + } else { + $application->add($commandInstance); + } $parsedOptions = []; foreach ($args as $arg) { From 99a09590fe1bfe6260910293a7e0ec0bb432e29d Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 13:23:13 +0300 Subject: [PATCH 3/8] Fix PHPStan warning for method_exists check Signed-off-by: bota --- src/Swoole/Delegators/TCPServerDelegator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index e7183db..d2f3f1b 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -64,6 +64,7 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $commandClass = $commandMap[$commandName]; $application = new Application(); $commandInstance = $container->get($commandClass); + /** @phpstan-ignore function.alreadyNarrowedType */ if (method_exists($application, 'addCommand')) { $application->addCommand($commandInstance); } else { From 58ed01d7dba9fb4d7e057c215406e69e72f03077 Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 13:26:03 +0300 Subject: [PATCH 4/8] Fix remaining PHPStan warning for add() method Signed-off-by: bota --- src/Swoole/Delegators/TCPServerDelegator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index d2f3f1b..089f4c4 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -68,6 +68,7 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal if (method_exists($application, 'addCommand')) { $application->addCommand($commandInstance); } else { + /** @phpstan-ignore method.notFound */ $application->add($commandInstance); } From d0b7a4daa9a73ed8848ef06c58045272dfa37e39 Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 13:30:23 +0300 Subject: [PATCH 5/8] Allow unmatched PHPStan ignores for cross-version compatibility Signed-off-by: bota --- phpstan.neon | 1 + src/Swoole/Delegators/TCPServerDelegator.php | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 9da6dbc..b74010c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,3 +9,4 @@ parameters: - src - test treatPhpDocTypesAsCertain: false + reportUnmatchedIgnoredErrors: false diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index 089f4c4..3da3af0 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -64,11 +64,10 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $commandClass = $commandMap[$commandName]; $application = new Application(); $commandInstance = $container->get($commandClass); - /** @phpstan-ignore function.alreadyNarrowedType */ + /** @phpstan-ignore function.alreadyNarrowedType, method.notFound */ if (method_exists($application, 'addCommand')) { $application->addCommand($commandInstance); } else { - /** @phpstan-ignore method.notFound */ $application->add($commandInstance); } From 997372465b7bca8974b713d15486dd4261d8a1d0 Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 13:33:09 +0300 Subject: [PATCH 6/8] Fix PHPStan errors for add/addCommand Signed-off-by: bota --- src/Swoole/Delegators/TCPServerDelegator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index 3da3af0..089f4c4 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -64,10 +64,11 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $commandClass = $commandMap[$commandName]; $application = new Application(); $commandInstance = $container->get($commandClass); - /** @phpstan-ignore function.alreadyNarrowedType, method.notFound */ + /** @phpstan-ignore function.alreadyNarrowedType */ if (method_exists($application, 'addCommand')) { $application->addCommand($commandInstance); } else { + /** @phpstan-ignore method.notFound */ $application->add($commandInstance); } From 9e652b4b7e6068469bdb0e0ab3d6c6dd5e2b5017 Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 13:37:32 +0300 Subject: [PATCH 7/8] ignore codecov for version compatibility line Signed-off-by: bota --- src/Swoole/Delegators/TCPServerDelegator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index 089f4c4..a7a27f8 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -69,7 +69,7 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $application->addCommand($commandInstance); } else { /** @phpstan-ignore method.notFound */ - $application->add($commandInstance); + $application->add($commandInstance); // @codeCoverageIgnore } $parsedOptions = []; From 679dad6eb873b69599ee6c8fe5450e2215ae9980 Mon Sep 17 00:00:00 2001 From: bota Date: Tue, 26 May 2026 14:49:10 +0300 Subject: [PATCH 8/8] Use elseif for symfony/console add/addCommand compatibility Signed-off-by: bota --- phpstan.neon | 1 - src/Swoole/Delegators/TCPServerDelegator.php | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index b74010c..9da6dbc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,4 +9,3 @@ parameters: - src - test treatPhpDocTypesAsCertain: false - reportUnmatchedIgnoredErrors: false diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index a7a27f8..58d948f 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -11,6 +11,7 @@ use Queue\Swoole\Command\GetFailedMessagesCommand; use Queue\Swoole\Command\GetProcessedMessagesCommand; use Queue\Swoole\Command\GetQueuedMessagesCommand; +use Queue\Swoole\Exception\RuntimeException; use Swoole\Server as TCPSwooleServer; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArrayInput; @@ -24,6 +25,7 @@ use function explode; use function ltrim; use function method_exists; +use function sprintf; use function str_starts_with; use function trim; @@ -64,12 +66,14 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $commandClass = $commandMap[$commandName]; $application = new Application(); $commandInstance = $container->get($commandClass); - /** @phpstan-ignore function.alreadyNarrowedType */ if (method_exists($application, 'addCommand')) { $application->addCommand($commandInstance); + } elseif (method_exists($application, 'add')) { + $application->add($commandInstance); } else { - /** @phpstan-ignore method.notFound */ - $application->add($commandInstance); // @codeCoverageIgnore + throw new RuntimeException( + sprintf('%s contains no "add" or "addCommand" method.', $application::class) + ); } $parsedOptions = [];