diff --git a/config/params.php b/config/params.php index fc87d078..086f8f70 100644 --- a/config/params.php +++ b/config/params.php @@ -24,7 +24,7 @@ 'yiisoft/queue' => [ 'handlers' => [], 'channels' => [ - QueueInterface::DEFAULT_CHANNEL_NAME => AdapterInterface::class, + QueueInterface::DEFAULT_CHANNEL => AdapterInterface::class, ], 'middlewares-push' => [], 'middlewares-consume' => [], diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index fd6ca02a..7825bd9f 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -43,5 +43,5 @@ public function subscribe(callable $handlerCallback): void; public function withChannel(string|BackedEnum $channel): self; - public function getChannelName(): string; + public function getChannel(): string; } diff --git a/src/Adapter/SynchronousAdapter.php b/src/Adapter/SynchronousAdapter.php index 82ebde2a..367c2a4a 100644 --- a/src/Adapter/SynchronousAdapter.php +++ b/src/Adapter/SynchronousAdapter.php @@ -22,7 +22,7 @@ final class SynchronousAdapter implements AdapterInterface public function __construct( private WorkerInterface $worker, private QueueInterface $queue, - string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL_NAME, + string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL, ) { $this->channel = ChannelNormalizer::normalize($channel); } @@ -93,7 +93,7 @@ public function withChannel(string|BackedEnum $channel): self return $new; } - public function getChannelName(): string + public function getChannel(): string { return $this->channel; } diff --git a/src/Command/ListenCommand.php b/src/Command/ListenCommand.php index ecafb837..cfdbb329 100644 --- a/src/Command/ListenCommand.php +++ b/src/Command/ListenCommand.php @@ -28,7 +28,7 @@ public function configure(): void 'channel', InputArgument::OPTIONAL, 'Queue channel name to connect to', - QueueInterface::DEFAULT_CHANNEL_NAME, + QueueInterface::DEFAULT_CHANNEL, ); } diff --git a/src/Debug/QueueCollector.php b/src/Debug/QueueCollector.php index 055cbde0..c0029fc1 100644 --- a/src/Debug/QueueCollector.php +++ b/src/Debug/QueueCollector.php @@ -73,7 +73,7 @@ public function collectWorkerProcessing(MessageInterface $message, QueueInterfac if (!$this->isActive()) { return; } - $this->processingMessages[$queue->getChannelName() ?? 'null'][] = $message; + $this->processingMessages[$queue->getChannel() ?? 'null'][] = $message; } private function reset(): void diff --git a/src/Debug/QueueDecorator.php b/src/Debug/QueueDecorator.php index e6b83f8e..5b4614f8 100644 --- a/src/Debug/QueueDecorator.php +++ b/src/Debug/QueueDecorator.php @@ -31,7 +31,7 @@ public function push( string|array|callable|MiddlewarePushInterface ...$middlewareDefinitions ): MessageInterface { $message = $this->queue->push($message, ...$middlewareDefinitions); - $this->collector->collectPush($this->queue->getChannelName(), $message, ...$middlewareDefinitions); + $this->collector->collectPush($this->queue->getChannel(), $message, ...$middlewareDefinitions); return $message; } @@ -50,8 +50,8 @@ public function withAdapter(AdapterInterface $adapter): QueueInterface return new self($this->queue->withAdapter($adapter), $this->collector); } - public function getChannelName(): ?string + public function getChannel(): ?string { - return $this->queue->getChannelName(); + return $this->queue->getChannel(); } } diff --git a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php index bbc4e38b..841e53c8 100644 --- a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php +++ b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php @@ -37,18 +37,18 @@ public function dispatch( FailureHandlingRequest $request, MessageFailureHandlerInterface $finishHandler ): FailureHandlingRequest { - /** @var string $channelName It is always string in this context */ - $channelName = $request->getQueue()->getChannelName(); - if (!isset($this->middlewareDefinitions[$channelName]) || $this->middlewareDefinitions[$channelName] === []) { - $channelName = self::DEFAULT_PIPELINE; + /** @var string $channel It is always string in this context */ + $channel = $request->getQueue()->getChannel(); + if (!isset($this->middlewareDefinitions[$channel]) || $this->middlewareDefinitions[$channel] === []) { + $channel = self::DEFAULT_PIPELINE; } - $definitions = array_reverse($this->middlewareDefinitions[$channelName]); + $definitions = array_reverse($this->middlewareDefinitions[$channel]); - if (!isset($this->stack[$channelName])) { - $this->stack[$channelName] = new MiddlewareFailureStack($this->buildMiddlewares(...$definitions), $finishHandler); + if (!isset($this->stack[$channel])) { + $this->stack[$channel] = new MiddlewareFailureStack($this->buildMiddlewares(...$definitions), $finishHandler); } - return $this->stack[$channelName]->handleFailure($request); + return $this->stack[$channel]->handleFailure($request); } /** diff --git a/src/Queue.php b/src/Queue.php index e8691f78..b8462688 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -38,9 +38,9 @@ public function __construct( $this->adapterPushHandler = new AdapterPushHandler(); } - public function getChannelName(): ?string + public function getChannel(): ?string { - return $this->adapter?->getChannelName(); + return $this->adapter?->getChannel(); } public function push( diff --git a/src/QueueInterface.php b/src/QueueInterface.php index 0f8b8172..93878540 100644 --- a/src/QueueInterface.php +++ b/src/QueueInterface.php @@ -13,7 +13,7 @@ interface QueueInterface { /** @psalm-suppress MissingClassConstType */ - public const DEFAULT_CHANNEL_NAME = 'yii-queue'; + public const DEFAULT_CHANNEL = 'yii-queue'; /** * Pushes a message into the queue. @@ -46,5 +46,5 @@ public function status(string|int $id): JobStatus; public function withAdapter(AdapterInterface $adapter): self; - public function getChannelName(): ?string; + public function getChannel(): ?string; } diff --git a/stubs/StubAdapter.php b/stubs/StubAdapter.php index 1142f173..a5f63172 100644 --- a/stubs/StubAdapter.php +++ b/stubs/StubAdapter.php @@ -16,12 +16,12 @@ */ final class StubAdapter implements AdapterInterface { - private string $channelName; + private string $channel; public function __construct( - string|BackedEnum $channelName = QueueInterface::DEFAULT_CHANNEL_NAME + string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL ) { - $this->channelName = ChannelNormalizer::normalize($channelName); + $this->channel = ChannelNormalizer::normalize($channel); } public function runExisting(callable $handlerCallback): void @@ -45,12 +45,12 @@ public function subscribe(callable $handlerCallback): void public function withChannel(string|BackedEnum $channel): AdapterInterface { $new = clone $this; - $new->channelName = ChannelNormalizer::normalize($channel); + $new->channel = ChannelNormalizer::normalize($channel); return $new; } - public function getChannelName(): string + public function getChannel(): string { - return $this->channelName; + return $this->channel; } } diff --git a/stubs/StubQueue.php b/stubs/StubQueue.php index e4b8708b..53587e70 100644 --- a/stubs/StubQueue.php +++ b/stubs/StubQueue.php @@ -53,8 +53,8 @@ public function withAdapter(AdapterInterface $adapter): QueueInterface return $new; } - public function getChannelName(): ?string + public function getChannel(): ?string { - return $this->adapter?->getChannelName(); + return $this->adapter?->getChannel(); } } diff --git a/tests/App/DummyQueue.php b/tests/App/DummyQueue.php index 05dd1801..75e8ff8d 100644 --- a/tests/App/DummyQueue.php +++ b/tests/App/DummyQueue.php @@ -13,7 +13,7 @@ final class DummyQueue implements QueueInterface { - public function __construct(private string $channelName) + public function __construct(private string $channel) { } @@ -43,8 +43,8 @@ public function withAdapter(AdapterInterface $adapter): QueueInterface throw new Exception('`withAdapter()` method is not implemented yet.'); } - public function getChannelName(): string + public function getChannel(): string { - return $this->channelName; + return $this->channel; } } diff --git a/tests/App/FakeAdapter.php b/tests/App/FakeAdapter.php index 237fef6d..69f1e0ea 100644 --- a/tests/App/FakeAdapter.php +++ b/tests/App/FakeAdapter.php @@ -45,7 +45,7 @@ public function withChannel(string|BackedEnum $channel): AdapterInterface return $instance; } - public function getChannelName(): string + public function getChannel(): string { return $this->channel; } diff --git a/tests/Benchmark/Support/VoidAdapter.php b/tests/Benchmark/Support/VoidAdapter.php index 6d074811..a6d4beb9 100644 --- a/tests/Benchmark/Support/VoidAdapter.php +++ b/tests/Benchmark/Support/VoidAdapter.php @@ -51,7 +51,7 @@ public function withChannel(string|BackedEnum $channel): AdapterInterface throw new RuntimeException('Method is not implemented'); } - public function getChannelName(): string + public function getChannel(): string { throw new RuntimeException('Method is not implemented'); } diff --git a/tests/Integration/MiddlewareTest.php b/tests/Integration/MiddlewareTest.php index ed8f6ad3..d3752ec1 100644 --- a/tests/Integration/MiddlewareTest.php +++ b/tests/Integration/MiddlewareTest.php @@ -136,7 +136,7 @@ public function testFullStackFailure(): void $callableFactory = new CallableFactory($container); $queue->expects(self::exactly(7))->method('push')->willReturnCallback($queueCallback); - $queue->method('getChannelName')->willReturn('simple'); + $queue->method('getChannel')->willReturn('simple'); $middlewares = [ 'simple' => [ diff --git a/tests/Unit/Adapter/SynchronousAdapterTest.php b/tests/Unit/Adapter/SynchronousAdapterTest.php index 35e0f0a5..56dafcc3 100644 --- a/tests/Unit/Adapter/SynchronousAdapterTest.php +++ b/tests/Unit/Adapter/SynchronousAdapterTest.php @@ -57,7 +57,7 @@ public function testIdSetting(): void public function testWithSameChannel(): void { $adapter = $this->getAdapter(); - self::assertEquals($adapter, $adapter->withChannel(QueueInterface::DEFAULT_CHANNEL_NAME)); + self::assertEquals($adapter, $adapter->withChannel(QueueInterface::DEFAULT_CHANNEL)); } public function testWithAnotherChannel(): void @@ -111,7 +111,7 @@ public function testWithChannel(string $expected, mixed $channel): void { $adapter = (new SynchronousAdapter(new StubWorker(), new StubQueue()))->withChannel($channel); - $this->assertSame($expected, $adapter->getChannelName()); + $this->assertSame($expected, $adapter->getChannel()); } #[DataProvider('dataChannels')] @@ -119,6 +119,6 @@ public function testChannelInConstructor(string $expected, mixed $channel): void { $adapter = new SynchronousAdapter(new StubWorker(), new StubQueue(), $channel); - $this->assertSame($expected, $adapter->getChannelName()); + $this->assertSame($expected, $adapter->getChannel()); } } diff --git a/tests/Unit/Debug/QueueDecoratorTest.php b/tests/Unit/Debug/QueueDecoratorTest.php index 37e47112..f206c5ca 100644 --- a/tests/Unit/Debug/QueueDecoratorTest.php +++ b/tests/Unit/Debug/QueueDecoratorTest.php @@ -86,17 +86,17 @@ public function testListen(): void $decorator->listen(); } - public function testGetChannelName(): void + public function testGetChannel(): void { $queue = $this->createMock(QueueInterface::class); - $queue->expects($this->once())->method('getChannelName')->willReturn('getChannelName'); + $queue->expects($this->once())->method('getChannel')->willReturn('hello'); $collector = new QueueCollector(); $decorator = new QueueDecorator( $queue, $collector, ); - $this->assertEquals('getChannelName', $decorator->getChannelName()); + $this->assertEquals('hello', $decorator->getChannel()); } public function testImmutable(): void diff --git a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php b/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php index 94900a66..4a52ac6f 100644 --- a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php +++ b/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php @@ -30,7 +30,7 @@ public function testBase(): void $queue = $provider->get('channel1'); $this->assertInstanceOf(StubQueue::class, $queue); - $this->assertSame('channel1', $queue->getChannelName()); + $this->assertSame('channel1', $queue->getChannel()); $this->assertInstanceOf(StubAdapter::class, $queue->getAdapter()); $this->assertTrue($provider->has('channel1')); $this->assertFalse($provider->has('not-exist-channel')); @@ -113,7 +113,7 @@ public function testGetHasByStringEnum(): void $queue = $provider->get(StringEnum::RED); - $this->assertSame('red', $queue->getChannelName()); + $this->assertSame('red', $queue->getChannel()); $this->assertTrue($provider->has(StringEnum::RED)); $this->assertFalse($provider->has(StringEnum::GREEN)); } diff --git a/tests/Unit/Provider/ChannelNotFoundExceptionTest.php b/tests/Unit/Provider/ChannelNotFoundExceptionTest.php index 699a94b2..6e967133 100644 --- a/tests/Unit/Provider/ChannelNotFoundExceptionTest.php +++ b/tests/Unit/Provider/ChannelNotFoundExceptionTest.php @@ -18,12 +18,12 @@ public static function dataBase(): iterable } #[DataProvider('dataBase')] - public function testBase(string $expectedChannelName, mixed $channel): void + public function testBase(string $expectedChannel, mixed $channel): void { $exception = new ChannelNotFoundException($channel); $this->assertSame( - 'Channel "' . $expectedChannelName . '" not found.', + 'Channel "' . $expectedChannel . '" not found.', $exception->getMessage(), ); } diff --git a/tests/Unit/Provider/CompositeQueueProviderTest.php b/tests/Unit/Provider/CompositeQueueProviderTest.php index 7c33de2b..d55fd600 100644 --- a/tests/Unit/Provider/CompositeQueueProviderTest.php +++ b/tests/Unit/Provider/CompositeQueueProviderTest.php @@ -31,8 +31,8 @@ public function testBase(): void $this->assertTrue($provider->has('channel2')); $this->assertFalse($provider->has('channel3')); - $this->assertSame('channel1', $provider->get('channel1')->getChannelName()); - $this->assertSame('channel2', $provider->get('channel2')->getChannelName()); + $this->assertSame('channel1', $provider->get('channel1')->getChannel()); + $this->assertSame('channel2', $provider->get('channel2')->getChannel()); } public function testNotFound(): void diff --git a/tests/Unit/Provider/PrototypeQueueProviderTest.php b/tests/Unit/Provider/PrototypeQueueProviderTest.php index f8fa4c42..3429ee19 100644 --- a/tests/Unit/Provider/PrototypeQueueProviderTest.php +++ b/tests/Unit/Provider/PrototypeQueueProviderTest.php @@ -21,7 +21,7 @@ public function testBase(): void $queue = $provider->get('test-channel'); $this->assertInstanceOf(StubQueue::class, $queue); - $this->assertSame('test-channel', $queue->getChannelName()); + $this->assertSame('test-channel', $queue->getChannel()); $this->assertTrue($provider->has('test-channel')); $this->assertTrue($provider->has('yet-another-channel')); } diff --git a/tests/Unit/Stubs/StubAdapterTest.php b/tests/Unit/Stubs/StubAdapterTest.php index aad5c799..520b9224 100644 --- a/tests/Unit/Stubs/StubAdapterTest.php +++ b/tests/Unit/Stubs/StubAdapterTest.php @@ -37,7 +37,7 @@ public function testWithChannel(string $expected, mixed $channel): void { $adapter = (new StubAdapter())->withChannel($channel); - $this->assertSame($expected, $adapter->getChannelName()); + $this->assertSame($expected, $adapter->getChannel()); } #[DataProvider('dataChannels')] @@ -45,6 +45,6 @@ public function testChannelInConstructor(string $expected, mixed $channel): void { $adapter = new StubAdapter($channel); - $this->assertSame($expected, $adapter->getChannelName()); + $this->assertSame($expected, $adapter->getChannel()); } } diff --git a/tests/Unit/Stubs/StubQueueTest.php b/tests/Unit/Stubs/StubQueueTest.php index 548705ab..fbf5a291 100644 --- a/tests/Unit/Stubs/StubQueueTest.php +++ b/tests/Unit/Stubs/StubQueueTest.php @@ -19,7 +19,7 @@ public function testBase(): void $this->assertSame($message, $queue->push($message)); $this->assertSame(0, $queue->run()); $this->assertTrue($queue->status('test')->isDone()); - $this->assertNull($queue->getChannelName()); + $this->assertNull($queue->getChannel()); $this->assertNull($queue->getAdapter()); $queue->listen(); }