Skip to content

Commit 5a13e3e

Browse files
authored
Rename "Channel Name" to "Channel" (#233)
1 parent 55c42db commit 5a13e3e

23 files changed

+51
-51
lines changed

config/params.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'yiisoft/queue' => [
2525
'handlers' => [],
2626
'channels' => [
27-
QueueInterface::DEFAULT_CHANNEL_NAME => AdapterInterface::class,
27+
QueueInterface::DEFAULT_CHANNEL => AdapterInterface::class,
2828
],
2929
'middlewares-push' => [],
3030
'middlewares-consume' => [],

src/Adapter/AdapterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ public function subscribe(callable $handlerCallback): void;
4343

4444
public function withChannel(string|BackedEnum $channel): self;
4545

46-
public function getChannelName(): string;
46+
public function getChannel(): string;
4747
}

src/Adapter/SynchronousAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class SynchronousAdapter implements AdapterInterface
2222
public function __construct(
2323
private WorkerInterface $worker,
2424
private QueueInterface $queue,
25-
string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL_NAME,
25+
string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL,
2626
) {
2727
$this->channel = ChannelNormalizer::normalize($channel);
2828
}
@@ -93,7 +93,7 @@ public function withChannel(string|BackedEnum $channel): self
9393
return $new;
9494
}
9595

96-
public function getChannelName(): string
96+
public function getChannel(): string
9797
{
9898
return $this->channel;
9999
}

src/Command/ListenCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function configure(): void
2828
'channel',
2929
InputArgument::OPTIONAL,
3030
'Queue channel name to connect to',
31-
QueueInterface::DEFAULT_CHANNEL_NAME,
31+
QueueInterface::DEFAULT_CHANNEL,
3232
);
3333
}
3434

src/Debug/QueueCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function collectWorkerProcessing(MessageInterface $message, QueueInterfac
7373
if (!$this->isActive()) {
7474
return;
7575
}
76-
$this->processingMessages[$queue->getChannelName() ?? 'null'][] = $message;
76+
$this->processingMessages[$queue->getChannel() ?? 'null'][] = $message;
7777
}
7878

7979
private function reset(): void

src/Debug/QueueDecorator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function push(
3131
string|array|callable|MiddlewarePushInterface ...$middlewareDefinitions
3232
): MessageInterface {
3333
$message = $this->queue->push($message, ...$middlewareDefinitions);
34-
$this->collector->collectPush($this->queue->getChannelName(), $message, ...$middlewareDefinitions);
34+
$this->collector->collectPush($this->queue->getChannel(), $message, ...$middlewareDefinitions);
3535
return $message;
3636
}
3737

@@ -50,8 +50,8 @@ public function withAdapter(AdapterInterface $adapter): QueueInterface
5050
return new self($this->queue->withAdapter($adapter), $this->collector);
5151
}
5252

53-
public function getChannelName(): ?string
53+
public function getChannel(): ?string
5454
{
55-
return $this->queue->getChannelName();
55+
return $this->queue->getChannel();
5656
}
5757
}

src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ public function dispatch(
3737
FailureHandlingRequest $request,
3838
MessageFailureHandlerInterface $finishHandler
3939
): FailureHandlingRequest {
40-
/** @var string $channelName It is always string in this context */
41-
$channelName = $request->getQueue()->getChannelName();
42-
if (!isset($this->middlewareDefinitions[$channelName]) || $this->middlewareDefinitions[$channelName] === []) {
43-
$channelName = self::DEFAULT_PIPELINE;
40+
/** @var string $channel It is always string in this context */
41+
$channel = $request->getQueue()->getChannel();
42+
if (!isset($this->middlewareDefinitions[$channel]) || $this->middlewareDefinitions[$channel] === []) {
43+
$channel = self::DEFAULT_PIPELINE;
4444
}
45-
$definitions = array_reverse($this->middlewareDefinitions[$channelName]);
45+
$definitions = array_reverse($this->middlewareDefinitions[$channel]);
4646

47-
if (!isset($this->stack[$channelName])) {
48-
$this->stack[$channelName] = new MiddlewareFailureStack($this->buildMiddlewares(...$definitions), $finishHandler);
47+
if (!isset($this->stack[$channel])) {
48+
$this->stack[$channel] = new MiddlewareFailureStack($this->buildMiddlewares(...$definitions), $finishHandler);
4949
}
5050

51-
return $this->stack[$channelName]->handleFailure($request);
51+
return $this->stack[$channel]->handleFailure($request);
5252
}
5353

5454
/**

src/Queue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public function __construct(
3838
$this->adapterPushHandler = new AdapterPushHandler();
3939
}
4040

41-
public function getChannelName(): ?string
41+
public function getChannel(): ?string
4242
{
43-
return $this->adapter?->getChannelName();
43+
return $this->adapter?->getChannel();
4444
}
4545

4646
public function push(

src/QueueInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
interface QueueInterface
1414
{
1515
/** @psalm-suppress MissingClassConstType */
16-
public const DEFAULT_CHANNEL_NAME = 'yii-queue';
16+
public const DEFAULT_CHANNEL = 'yii-queue';
1717

1818
/**
1919
* Pushes a message into the queue.
@@ -46,5 +46,5 @@ public function status(string|int $id): JobStatus;
4646

4747
public function withAdapter(AdapterInterface $adapter): self;
4848

49-
public function getChannelName(): ?string;
49+
public function getChannel(): ?string;
5050
}

stubs/StubAdapter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
*/
1717
final class StubAdapter implements AdapterInterface
1818
{
19-
private string $channelName;
19+
private string $channel;
2020

2121
public function __construct(
22-
string|BackedEnum $channelName = QueueInterface::DEFAULT_CHANNEL_NAME
22+
string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL
2323
) {
24-
$this->channelName = ChannelNormalizer::normalize($channelName);
24+
$this->channel = ChannelNormalizer::normalize($channel);
2525
}
2626

2727
public function runExisting(callable $handlerCallback): void
@@ -45,12 +45,12 @@ public function subscribe(callable $handlerCallback): void
4545
public function withChannel(string|BackedEnum $channel): AdapterInterface
4646
{
4747
$new = clone $this;
48-
$new->channelName = ChannelNormalizer::normalize($channel);
48+
$new->channel = ChannelNormalizer::normalize($channel);
4949
return $new;
5050
}
5151

52-
public function getChannelName(): string
52+
public function getChannel(): string
5353
{
54-
return $this->channelName;
54+
return $this->channel;
5555
}
5656
}

stubs/StubQueue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public function withAdapter(AdapterInterface $adapter): QueueInterface
5353
return $new;
5454
}
5555

56-
public function getChannelName(): ?string
56+
public function getChannel(): ?string
5757
{
58-
return $this->adapter?->getChannelName();
58+
return $this->adapter?->getChannel();
5959
}
6060
}

tests/App/DummyQueue.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class DummyQueue implements QueueInterface
1515
{
16-
public function __construct(private string $channelName)
16+
public function __construct(private string $channel)
1717
{
1818
}
1919

@@ -43,8 +43,8 @@ public function withAdapter(AdapterInterface $adapter): QueueInterface
4343
throw new Exception('`withAdapter()` method is not implemented yet.');
4444
}
4545

46-
public function getChannelName(): string
46+
public function getChannel(): string
4747
{
48-
return $this->channelName;
48+
return $this->channel;
4949
}
5050
}

tests/App/FakeAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function withChannel(string|BackedEnum $channel): AdapterInterface
4545
return $instance;
4646
}
4747

48-
public function getChannelName(): string
48+
public function getChannel(): string
4949
{
5050
return $this->channel;
5151
}

tests/Benchmark/Support/VoidAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function withChannel(string|BackedEnum $channel): AdapterInterface
5151
throw new RuntimeException('Method is not implemented');
5252
}
5353

54-
public function getChannelName(): string
54+
public function getChannel(): string
5555
{
5656
throw new RuntimeException('Method is not implemented');
5757
}

tests/Integration/MiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function testFullStackFailure(): void
136136
$callableFactory = new CallableFactory($container);
137137

138138
$queue->expects(self::exactly(7))->method('push')->willReturnCallback($queueCallback);
139-
$queue->method('getChannelName')->willReturn('simple');
139+
$queue->method('getChannel')->willReturn('simple');
140140

141141
$middlewares = [
142142
'simple' => [

tests/Unit/Adapter/SynchronousAdapterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testIdSetting(): void
5757
public function testWithSameChannel(): void
5858
{
5959
$adapter = $this->getAdapter();
60-
self::assertEquals($adapter, $adapter->withChannel(QueueInterface::DEFAULT_CHANNEL_NAME));
60+
self::assertEquals($adapter, $adapter->withChannel(QueueInterface::DEFAULT_CHANNEL));
6161
}
6262

6363
public function testWithAnotherChannel(): void
@@ -111,14 +111,14 @@ public function testWithChannel(string $expected, mixed $channel): void
111111
{
112112
$adapter = (new SynchronousAdapter(new StubWorker(), new StubQueue()))->withChannel($channel);
113113

114-
$this->assertSame($expected, $adapter->getChannelName());
114+
$this->assertSame($expected, $adapter->getChannel());
115115
}
116116

117117
#[DataProvider('dataChannels')]
118118
public function testChannelInConstructor(string $expected, mixed $channel): void
119119
{
120120
$adapter = new SynchronousAdapter(new StubWorker(), new StubQueue(), $channel);
121121

122-
$this->assertSame($expected, $adapter->getChannelName());
122+
$this->assertSame($expected, $adapter->getChannel());
123123
}
124124
}

tests/Unit/Debug/QueueDecoratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ public function testListen(): void
8686
$decorator->listen();
8787
}
8888

89-
public function testGetChannelName(): void
89+
public function testGetChannel(): void
9090
{
9191
$queue = $this->createMock(QueueInterface::class);
92-
$queue->expects($this->once())->method('getChannelName')->willReturn('getChannelName');
92+
$queue->expects($this->once())->method('getChannel')->willReturn('hello');
9393
$collector = new QueueCollector();
9494
$decorator = new QueueDecorator(
9595
$queue,
9696
$collector,
9797
);
9898

99-
$this->assertEquals('getChannelName', $decorator->getChannelName());
99+
$this->assertEquals('hello', $decorator->getChannel());
100100
}
101101

102102
public function testImmutable(): void

tests/Unit/Provider/AdapterFactoryQueueProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testBase(): void
3030
$queue = $provider->get('channel1');
3131

3232
$this->assertInstanceOf(StubQueue::class, $queue);
33-
$this->assertSame('channel1', $queue->getChannelName());
33+
$this->assertSame('channel1', $queue->getChannel());
3434
$this->assertInstanceOf(StubAdapter::class, $queue->getAdapter());
3535
$this->assertTrue($provider->has('channel1'));
3636
$this->assertFalse($provider->has('not-exist-channel'));
@@ -113,7 +113,7 @@ public function testGetHasByStringEnum(): void
113113

114114
$queue = $provider->get(StringEnum::RED);
115115

116-
$this->assertSame('red', $queue->getChannelName());
116+
$this->assertSame('red', $queue->getChannel());
117117
$this->assertTrue($provider->has(StringEnum::RED));
118118
$this->assertFalse($provider->has(StringEnum::GREEN));
119119
}

tests/Unit/Provider/ChannelNotFoundExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public static function dataBase(): iterable
1818
}
1919

2020
#[DataProvider('dataBase')]
21-
public function testBase(string $expectedChannelName, mixed $channel): void
21+
public function testBase(string $expectedChannel, mixed $channel): void
2222
{
2323
$exception = new ChannelNotFoundException($channel);
2424

2525
$this->assertSame(
26-
'Channel "' . $expectedChannelName . '" not found.',
26+
'Channel "' . $expectedChannel . '" not found.',
2727
$exception->getMessage(),
2828
);
2929
}

tests/Unit/Provider/CompositeQueueProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testBase(): void
3131
$this->assertTrue($provider->has('channel2'));
3232
$this->assertFalse($provider->has('channel3'));
3333

34-
$this->assertSame('channel1', $provider->get('channel1')->getChannelName());
35-
$this->assertSame('channel2', $provider->get('channel2')->getChannelName());
34+
$this->assertSame('channel1', $provider->get('channel1')->getChannel());
35+
$this->assertSame('channel2', $provider->get('channel2')->getChannel());
3636
}
3737

3838
public function testNotFound(): void

tests/Unit/Provider/PrototypeQueueProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testBase(): void
2121
$queue = $provider->get('test-channel');
2222

2323
$this->assertInstanceOf(StubQueue::class, $queue);
24-
$this->assertSame('test-channel', $queue->getChannelName());
24+
$this->assertSame('test-channel', $queue->getChannel());
2525
$this->assertTrue($provider->has('test-channel'));
2626
$this->assertTrue($provider->has('yet-another-channel'));
2727
}

tests/Unit/Stubs/StubAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public function testWithChannel(string $expected, mixed $channel): void
3737
{
3838
$adapter = (new StubAdapter())->withChannel($channel);
3939

40-
$this->assertSame($expected, $adapter->getChannelName());
40+
$this->assertSame($expected, $adapter->getChannel());
4141
}
4242

4343
#[DataProvider('dataChannels')]
4444
public function testChannelInConstructor(string $expected, mixed $channel): void
4545
{
4646
$adapter = new StubAdapter($channel);
4747

48-
$this->assertSame($expected, $adapter->getChannelName());
48+
$this->assertSame($expected, $adapter->getChannel());
4949
}
5050
}

tests/Unit/Stubs/StubQueueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testBase(): void
1919
$this->assertSame($message, $queue->push($message));
2020
$this->assertSame(0, $queue->run());
2121
$this->assertTrue($queue->status('test')->isDone());
22-
$this->assertNull($queue->getChannelName());
22+
$this->assertNull($queue->getChannel());
2323
$this->assertNull($queue->getAdapter());
2424
$queue->listen();
2525
}

0 commit comments

Comments
 (0)