Test Failed
Pull Request — master (#39)
by Aleksandr
06:37
created

DeclareCommand::execute()   A

Complexity

Conditions 6
Paths 18

Size

Total Lines 36
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
c 0
b 0
f 0
nc 18
nop 2
dl 0
loc 36
rs 9.1111
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Command;
4
5
use OldSound\RabbitMqBundle\Declarations\DeclarationsRegistry;
6
use OldSound\RabbitMqBundle\Declarations\Declarator;
7
use OldSound\RabbitMqBundle\RabbitMq\DynamicConsumer;
0 ignored issues
show
Bug introduced by
The type OldSound\RabbitMqBundle\RabbitMq\DynamicConsumer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Exception\InvalidOptionException;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
15
16
class DeclareCommand extends Command
17
{
18
    use ContainerAwareTrait;
19
20
    public function __construct(
21
        DeclarationsRegistry $declarationsRegistry
22
    ) {
23
        parent::__construct();
24
        $this->declarationsRegistry = $declarationsRegistry;
0 ignored issues
show
Bug Best Practice introduced by
The property declarationsRegistry does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
    }
26
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('rabbitmq:declare')
31
            ->addArgument('connection', InputArgument::OPTIONAL, 'Rabbitmq connection name', 'default')
32
            ->setDescription('Sets up the Rabbit MQ fabric')
33
            ->addOption('debug', 'd', InputOption::VALUE_NONE, 'Enable Debugging')
34
        ;
35
    }
36
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        if (defined('AMQP_DEBUG') === false) {
40
            define('AMQP_DEBUG', (bool) $input->getOption('debug'));
41
        }
42
43
        $connection = $input->getArgument('connection');
44
        $channelAlias = sprintf('old_sound_rabbit_mq.channel.%s', $connection);
0 ignored issues
show
Bug introduced by
It seems like $connection can also be of type string[]; however, parameter $args of sprintf() 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

44
        $channelAlias = sprintf('old_sound_rabbit_mq.channel.%s', /** @scrutinizer ignore-type */ $connection);
Loading history...
45
        if(!$this->container->has($channelAlias)) {
46
            throw new InvalidOptionException('Connection is not exist');
47
        };
48
49
        $channel = $this->container->get($channelAlias);
50
51
        // TODO $output->writeln('Setting up the Rabbit MQ fabric');
52
53
        $producers = [];
54
        $consumers = [];
55
        $exchanges = [];
56
        foreach ($producers as $producer) {
57
            // TODO $exchanges[] = $producer->exchange;
58
        }
59
60
        foreach ($consumers as $consumer) {
61
            // TODO $exchanges[] = $producer->exchange;
62
            //$bindings[] = $producer->exchange;
63
            //$queues[] = $producer->exchange;
64
        }
65
66
        $declarator = new Declarator($channel);
0 ignored issues
show
Bug introduced by
It seems like $channel can also be of type null; however, parameter $channel of OldSound\RabbitMqBundle\...clarator::__construct() does only seem to accept PhpAmqpLib\Channel\AMQPChannel, 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

66
        $declarator = new Declarator(/** @scrutinizer ignore-type */ $channel);
Loading history...
67
        // $declarator->declareExchanges($exchanges);
68
        foreach ($exchanges as $exchange) {
69
            $declarator->declareForExchange($exchange);
0 ignored issues
show
Bug introduced by
The call to OldSound\RabbitMqBundle\...r::declareForExchange() has too few arguments starting with declarationsRegistry. ( Ignorable by Annotation )

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

69
            $declarator->/** @scrutinizer ignore-call */ 
70
                         declareForExchange($exchange);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
        }
71
72
        return 0;
73
74
    }
75
}
76