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.

ProduceCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 80.77%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 46
ccs 21
cts 26
cp 0.8077
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 8 1
A execute() 0 16 3
1
<?php
2
3
namespace Bernard\Command;
4
5
use Bernard\Producer;
6
use Bernard\Message\PlainMessage;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class ProduceCommand extends \Symfony\Component\Console\Command\Command
13
{
14
    protected $producer;
15
16
    /**
17
     * @param Producer $producer
18
     */
19 3
    public function __construct(Producer $producer)
20
    {
21 3
        $this->producer = $producer;
22
23 3
        parent::__construct('bernard:produce');
24 3
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 3
    public function configure()
30
    {
31 3
        $this
32 3
            ->addOption('queue', null, InputOption::VALUE_OPTIONAL, 'Name of a queue to add this job to. By default the queue is guessed from the message name.', null)
33 3
            ->addArgument('name', InputArgument::REQUIRED, 'Name for the message eg. "ImportUsers".')
34 3
            ->addArgument('message', InputArgument::OPTIONAL, 'JSON encoded string that is used for message properties.')
35
        ;
36 3
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 3
    public function execute(InputInterface $input, OutputInterface $output)
42
    {
43 3
        $name = $input->getArgument('name');
44 3
        $queue = $input->getOption('queue');
45 3
        $message = [];
46
47 3
        if ($input->getArgument('message')) {
48 2
            $message = json_decode($input->getArgument('message'), true);
49
50 2
            if (json_last_error()) {
51 1
                throw new \RuntimeException('Could not decode invalid JSON ['.json_last_error().']');
52
            }
53 1
        }
54
55 2
        $this->producer->produce(new PlainMessage($name, $message), $queue);
0 ignored issues
show
Bug introduced by
It seems like $name defined by $input->getArgument('name') on line 43 can also be of type array<integer,string> or null; however, Bernard\Message\PlainMessage::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
56 2
    }
57
}
58