Passed
Pull Request — master (#739)
by
unknown
15:57
created

SetupFabricCommand::execute()   B

Complexity

Conditions 9
Paths 16

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 9
eloc 15
c 3
b 0
f 1
nc 16
nop 2
dl 0
loc 29
rs 8.0555
ccs 0
cts 10
cp 0
crap 90
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Command;
4
5
use OldSound\RabbitMqBundle\RabbitMq\AnonConsumer;
6
use OldSound\RabbitMqBundle\RabbitMq\DynamicConsumer;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class SetupFabricCommand extends BaseRabbitMqCommand
12
{
13
    protected function configure(): void
14
    {
15
        $this
16
            ->setName('rabbitmq:setup-fabric')
17
            ->setDescription('Sets up the Rabbit MQ fabric')
18
            ->addOption('debug', 'd', InputOption::VALUE_NONE, 'Enable Debugging')
19
            ->addOption('skip-anon-consumers', null, InputOption::VALUE_NONE, 'Do not run the fabric-setup for anonymous consumers')
20
        ;
21
    }
22
23
    protected function execute(InputInterface $input, OutputInterface $output): int
24
    {
25
        if (defined('AMQP_DEBUG') === false) {
26
            define('AMQP_DEBUG', (bool) $input->getOption('debug'));
27
        }
28
29
        $skipAnonConsumers = (bool) $input->getOption('skip-anon-consumers');
30
31
        $output->writeln('Setting up the Rabbit MQ fabric');
32
33
        if ($skipAnonConsumers && $output->isVeryVerbose()) {
34
            $output->writeln('Skipping fabric-setup for anonymous consumers');
35
        }
36
37
        $partsHolder = $this->getContainer()->get('old_sound_rabbit_mq.parts_holder');
38
39
        foreach (['base_amqp', 'binding'] as $key) {
40
            foreach ($partsHolder->getParts('old_sound_rabbit_mq.' . $key) as $baseAmqp) {
41
                if (
42
                    $baseAmqp instanceof DynamicConsumer
43
                    || ($skipAnonConsumers && $baseAmqp instanceof AnonConsumer)
44
                ) {
45
                    continue;
46
                }
47
                $baseAmqp->setupFabric();
48
            }
49
        }
50
51
        return 0;
52
    }
53
}
54