ListenCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
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