ListenCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 27
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A configure() 0 7 1
A execute() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\Command;
6
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Yiisoft\Queue\QueueFactory;
12
use Yiisoft\Queue\QueueFactoryInterface;
13
14
final class ListenCommand extends Command
15
{
16
    protected static $defaultName = 'queue:listen';
17
    protected static $defaultDescription = 'Listens the queue and executes messages as they come. Needs to be stopped manually.';
18
19 2
    public function __construct(private QueueFactoryInterface $queueFactory)
20
    {
21 2
        parent::__construct();
22
    }
23
24 2
    public function configure(): void
25
    {
26 2
        $this->addArgument(
27 2
            'channel',
28 2
            InputArgument::OPTIONAL,
29 2
            'Queue channel name to connect to',
30 2
            QueueFactory::DEFAULT_CHANNEL_NAME
31 2
        );
32
    }
33
34 1
    protected function execute(InputInterface $input, OutputInterface $output): int
35
    {
36 1
        $this->queueFactory
37 1
            ->get($input->getArgument('channel'))
38 1
            ->listen();
39
40 1
        return 0;
41
    }
42
}
43