GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ConsumeCommand::getQueue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.8449

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 6
cts 11
cp 0.5455
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.8449
1
<?php
2
3
namespace Bernard\Command;
4
5
use Bernard\Consumer;
6
use Bernard\Queue;
7
use Bernard\Queue\RoundRobinQueue;
8
use Bernard\QueueFactory;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class ConsumeCommand extends \Symfony\Component\Console\Command\Command
15
{
16
    protected $consumer;
17
    protected $queues;
18
19
    /**
20
     * @param Consumer     $consumer
21
     * @param QueueFactory $queues
22
     */
23 2
    public function __construct(Consumer $consumer, QueueFactory $queues)
24
    {
25 2
        $this->consumer = $consumer;
26 2
        $this->queues = $queues;
27
28 2
        parent::__construct('bernard:consume');
29 2
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function configure()
35
    {
36 2
        $this
37 2
            ->addOption('max-runtime', null, InputOption::VALUE_OPTIONAL, 'Maximum time in seconds the consumer will run.', null)
38 2
            ->addOption('max-messages', null, InputOption::VALUE_OPTIONAL, 'Maximum number of messages that should be consumed.', null)
39 2
            ->addOption('stop-when-empty', null, InputOption::VALUE_NONE, 'Stop consumer when queue is empty.', null)
40 2
            ->addOption('stop-on-error', null, InputOption::VALUE_NONE, 'Stop consumer when an error occurs.', null)
41 2
            ->addArgument('queue', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Names of one or more queues that will be consumed.')
42
        ;
43 2
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function execute(InputInterface $input, OutputInterface $output)
49
    {
50 2
        $queue = $this->getQueue($input->getArgument('queue'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('queue') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type null; however, Bernard\Command\ConsumeCommand::getQueue() does only seem to accept array|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
51
52 2
        $this->consumer->consume($queue, $input->getOptions());
53 2
    }
54
55
    /**
56
     * @param array|string $queue
57
     *
58
     * @return Queue
59
     */
60 2
    protected function getQueue($queue)
61
    {
62 2
        if (is_array($queue)) {
63 1
            if (count($queue) > 1) {
64 1
                $queues = array_map([$this->queues, 'create'], $queue);
65
66 1
                return new RoundRobinQueue($queues);
67
            }
68
69
            $queue = $queue[0];
70
        }
71
72 1
        return $this->queues->create($queue);
73
    }
74
}
75