Completed
Push — master ( f58be8...855521 )
by Tilita
03:07
created

BasePublisherCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace NeedleProject\LaravelRabbitMq\Command;
3
4
use Illuminate\Console\Command;
5
use Monolog\Handler\StreamHandler;
6
use Monolog\Logger;
7
use NeedleProject\LaravelRabbitMq\ConsumerInterface;
8
use NeedleProject\LaravelRabbitMq\Container;
9
use NeedleProject\LaravelRabbitMq\PublisherInterface;
10
use Psr\Log\LoggerAwareInterface;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
/**
15
 * Class BasePublisherCommand
16
 *
17
 * @package NeedleProject\LaravelRabbitMq\Command
18
 * @author  Adrian Tilita <[email protected]>
19
 */
20
class BasePublisherCommand extends Command
21
{
22
    /**
23
     * The name and signature of the console command.
24
     *
25
     * @var string
26
     */
27
    protected $signature = 'rabbitmq:publish {publisher} {message}';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Publish one message';
35
36
    /**
37
     * @var null|Container
38
     */
39
    private $container = null;
40
41
    /**
42
     * BasePublisherCommand constructor.
43
     *
44
     * @param Container $container
45
     */
46 1
    public function __construct(Container $container)
47
    {
48 1
        $this->container = $container;
49 1
    }
50
51
    /**
52
     * @param string $publisherAliasName
53
     * @return PublisherInterface
54
     */
55 1
    protected function getPublisher(string $publisherAliasName): PublisherInterface
56
    {
57 1
        return $this->container->getPublisher($publisherAliasName);
58
    }
59
60
    /**
61
     * Execute the console command.
62
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
63
     */
64 1
    public function handle()
65
    {
66 1
        $this->getPublisher($this->input->getArgument('publisher'))
0 ignored issues
show
Bug introduced by
It seems like $this->input->getArgument('publisher') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, NeedleProject\LaravelRab...Command::getPublisher() does only seem to accept 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...
67 1
            ->publish($this->input->getArgument('message'));
0 ignored issues
show
Bug introduced by
It seems like $this->input->getArgument('message') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, NeedleProject\LaravelRab...herInterface::publish() does only seem to accept 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...
68
    }
69
}