From eb720823f7a4651a5fd89ef06c52c7b7105f077e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 03:07:28 +0000 Subject: [PATCH 1/5] Initial plan From 5b773ff4fb2e21505650aab947d1264d601e6aa1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 03:19:27 +0000 Subject: [PATCH 2/5] Add AMQP and Kafka type tests for dispatch function Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com> --- types/Support/Support.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/types/Support/Support.php b/types/Support/Support.php index fa9c1b160..6f50a0384 100644 --- a/types/Support/Support.php +++ b/types/Support/Support.php @@ -84,3 +84,13 @@ public function setMaxAttempts(int $maxAttempts): static })); assertType('FriendsOfHyperf\Support\Bus\PendingAsyncQueueDispatch', dispatch(fn () => null)); + +assertType('FriendsOfHyperf\Support\Bus\PendingAmqpProducerMessageDispatch', dispatch(new class () extends Hyperf\Amqp\Message\ProducerMessage { + public function __construct() + { + $this->exchange = 'test.exchange'; + $this->routingKey = 'test.routing.key'; + } +})); + +assertType('FriendsOfHyperf\Support\Bus\PendingKafkaProducerMessageDispatch', dispatch(new longlang\phpkafka\Producer\ProduceMessage('test-topic', 'test-value'))); From d37d05248991d68e479fa904b04549909f876048 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 03:30:45 +0000 Subject: [PATCH 3/5] Fix code style - remove empty parentheses from anonymous class Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com> --- types/Support/Support.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/Support/Support.php b/types/Support/Support.php index 6f50a0384..f77230021 100644 --- a/types/Support/Support.php +++ b/types/Support/Support.php @@ -85,7 +85,7 @@ public function setMaxAttempts(int $maxAttempts): static assertType('FriendsOfHyperf\Support\Bus\PendingAsyncQueueDispatch', dispatch(fn () => null)); -assertType('FriendsOfHyperf\Support\Bus\PendingAmqpProducerMessageDispatch', dispatch(new class () extends Hyperf\Amqp\Message\ProducerMessage { +assertType('FriendsOfHyperf\Support\Bus\PendingAmqpProducerMessageDispatch', dispatch(new class extends Hyperf\Amqp\Message\ProducerMessage { public function __construct() { $this->exchange = 'test.exchange'; From a9877fa6ccaa623fb285e2f0230a7db640900dca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 03:35:28 +0000 Subject: [PATCH 4/5] Fix code style - break long lines for readability Co-authored-by: huangdijia <8337659+huangdijia@users.noreply.github.com> --- types/Support/Support.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/types/Support/Support.php b/types/Support/Support.php index f77230021..fb5641d8e 100644 --- a/types/Support/Support.php +++ b/types/Support/Support.php @@ -85,12 +85,18 @@ public function setMaxAttempts(int $maxAttempts): static assertType('FriendsOfHyperf\Support\Bus\PendingAsyncQueueDispatch', dispatch(fn () => null)); -assertType('FriendsOfHyperf\Support\Bus\PendingAmqpProducerMessageDispatch', dispatch(new class extends Hyperf\Amqp\Message\ProducerMessage { - public function __construct() - { - $this->exchange = 'test.exchange'; - $this->routingKey = 'test.routing.key'; - } -})); - -assertType('FriendsOfHyperf\Support\Bus\PendingKafkaProducerMessageDispatch', dispatch(new longlang\phpkafka\Producer\ProduceMessage('test-topic', 'test-value'))); +assertType( + 'FriendsOfHyperf\Support\Bus\PendingAmqpProducerMessageDispatch', + dispatch(new class extends Hyperf\Amqp\Message\ProducerMessage { + public function __construct() + { + $this->exchange = 'test.exchange'; + $this->routingKey = 'test.routing.key'; + } + }) +); + +assertType( + 'FriendsOfHyperf\Support\Bus\PendingKafkaProducerMessageDispatch', + dispatch(new longlang\phpkafka\Producer\ProduceMessage('test-topic', 'test-value')) +); From 5aca025c780b602780b7b646a5ca255ea9550bd0 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Sat, 15 Nov 2025 12:57:26 +0800 Subject: [PATCH 5/5] fix: update return type annotation for dispatch function and improve type assertions in tests --- src/support/src/Functions.php | 2 +- types/Support/Support.php | 44 ++++++++++++++--------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/support/src/Functions.php b/src/support/src/Functions.php index 1648cf257..340108f3c 100644 --- a/src/support/src/Functions.php +++ b/src/support/src/Functions.php @@ -27,7 +27,7 @@ * Do not assign a value to the return value of this function unless you are very clear about the consequences of doing so. * @param Closure|JobInterface|ProduceMessage|ProducerMessageInterface|mixed $job * @param-closure-this ($job is Closure ? CallQueuedClosure : mixed) $job - * @return ($job is Closure ? PendingAsyncQueueDispatch : ($job is JobInterface ? PendingAsyncQueueDispatch : ($job is ProducerMessageInterface ? PendingAmqpProducerMessageDispatch : PendingKafkaProducerMessageDispatch))) + * @return ($job is Closure ? PendingAsyncQueueDispatch : ( $job is JobInterface ? PendingAsyncQueueDispatch : ( $job is ProducerMessageInterface ? PendingAmqpProducerMessageDispatch : ( $job is ProduceMessage ? PendingKafkaProducerMessageDispatch : never )))) * @throws InvalidArgumentException */ function dispatch($job) diff --git a/types/Support/Support.php b/types/Support/Support.php index fb5641d8e..ba09176aa 100644 --- a/types/Support/Support.php +++ b/types/Support/Support.php @@ -63,40 +63,30 @@ $command = new RedisCommand('SET', ['key', 'value']); assertType('string', (string) $command); -assertType('FriendsOfHyperf\Support\Bus\PendingAsyncQueueDispatch', dispatch(new class implements Hyperf\AsyncQueue\JobInterface { - public function handle(): void - { - } - - public function fail(Throwable $e): void - { - } - - public function getMaxAttempts(): int - { - return 0; - } +assertType( + 'FriendsOfHyperf\Support\Bus\PendingAsyncQueueDispatch', + dispatch(new class implements Hyperf\AsyncQueue\JobInterface { + public function handle(): void + { + } - public function setMaxAttempts(int $maxAttempts): static - { - return $this; - } -})); + public function fail(Throwable $e): void + { + } -assertType('FriendsOfHyperf\Support\Bus\PendingAsyncQueueDispatch', dispatch(fn () => null)); + public function getMaxAttempts(): int + { + return 0; + } -assertType( - 'FriendsOfHyperf\Support\Bus\PendingAmqpProducerMessageDispatch', - dispatch(new class extends Hyperf\Amqp\Message\ProducerMessage { - public function __construct() + public function setMaxAttempts(int $maxAttempts): static { - $this->exchange = 'test.exchange'; - $this->routingKey = 'test.routing.key'; + return $this; } }) ); assertType( - 'FriendsOfHyperf\Support\Bus\PendingKafkaProducerMessageDispatch', - dispatch(new longlang\phpkafka\Producer\ProduceMessage('test-topic', 'test-value')) + 'FriendsOfHyperf\Support\Bus\PendingAsyncQueueDispatch', + dispatch(fn () => null) );