Skip to content

Commit

Permalink
Rename "Channel Name" to "Channel"
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Dec 18, 2024
1 parent 55c42db commit 8217200
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'yiisoft/queue' => [
'handlers' => [],
'channels' => [
QueueInterface::DEFAULT_CHANNEL_NAME => AdapterInterface::class,
QueueInterface::DEFAULT_CHANNEL => AdapterInterface::class,
],
'middlewares-push' => [],
'middlewares-consume' => [],
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Adapter/SynchronousAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function withChannel(string|BackedEnum $channel): self
return $new;
}

public function getChannelName(): string
public function getChannel(): string
{
return $this->channel;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function configure(): void
'channel',
InputArgument::OPTIONAL,
'Queue channel name to connect to',
QueueInterface::DEFAULT_CHANNEL_NAME,
QueueInterface::DEFAULT_CHANNEL,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Debug/QueueCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/QueueDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
}
}
16 changes: 8 additions & 8 deletions src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
12 changes: 6 additions & 6 deletions stubs/StubAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions stubs/StubQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 3 additions & 3 deletions tests/App/DummyQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

final class DummyQueue implements QueueInterface
{
public function __construct(private string $channelName)
public function __construct(private string $channel)
{
}

Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion tests/App/FakeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function withChannel(string|BackedEnum $channel): AdapterInterface
return $instance;
}

public function getChannelName(): string
public function getChannel(): string
{
return $this->channel;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Benchmark/Support/VoidAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Adapter/SynchronousAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,14 +111,14 @@ 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')]
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());
}
}
6 changes: 3 additions & 3 deletions tests/Unit/Debug/QueueDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Provider/AdapterFactoryQueueProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Provider/ChannelNotFoundExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Provider/CompositeQueueProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Provider/PrototypeQueueProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Stubs/StubAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ 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')]
public function testChannelInConstructor(string $expected, mixed $channel): void
{
$adapter = new StubAdapter($channel);

$this->assertSame($expected, $adapter->getChannelName());
$this->assertSame($expected, $adapter->getChannel());
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Stubs/StubQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 8217200

Please # to comment.