SetupFabricCommand::execute()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

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