Passed
Push — master ( a2ae4c...9be3ef )
by Mike
02:07
created

ConsumeCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
ccs 0
cts 8
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Xervice\RabbitMQ\Communication\Console\Command;
5
6
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Xervice\Console\Business\Model\Command\AbstractCommand;
12
use Xervice\Core\Business\Exception\XerviceException;
13
14
/**
15
 * @method \Xervice\RabbitMQ\Business\RabbitMQFacade getFacade()
16
 */
17
class ConsumeCommand extends AbstractCommand
18
{
19
    /**
20
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
21
     */
22
    protected function configure(): void
23
    {
24
        $this
25
            ->setName('queue:listener:run')
26
            ->addArgument('listener', InputArgument::REQUIRED, 'Listener classname');
27
    }
28
29
    /**
30
     * @param \Symfony\Component\Console\Input\InputInterface $input
31
     * @param \Symfony\Component\Console\Output\OutputInterface $output
32
     *
33
     * @return int|void
34
     * @throws \Xervice\Core\Business\Exception\XerviceException
35
     */
36
    public function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $listenerClass = $input->getArgument('listener');
39
40
        if (!class_exists($listenerClass)) {
0 ignored issues
show
Bug introduced by
It seems like $listenerClass can also be of type string[]; however, parameter $class_name of class_exists() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        if (!class_exists(/** @scrutinizer ignore-type */ $listenerClass)) {
Loading history...
41
            throw new XerviceException('Listener not found ' . $listenerClass);
0 ignored issues
show
Bug introduced by
Are you sure $listenerClass of type null|string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
            throw new XerviceException('Listener not found ' . /** @scrutinizer ignore-type */ $listenerClass);
Loading history...
42
        }
43
44
        $listener = new $listenerClass();
45
        $this->getFacade()->consumeQueries($listener);
46
    }
47
}