Passed
Pull Request — master (#92)
by Daniel
04:10
created

EventListenerGetCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 9
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\Event\Command;
6
7
use Jellyfish\Event\EventListenerProviderInterface;
8
use Jellyfish\Serializer\SerializerInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class EventListenerGetCommand extends Command
15
{
16
    public const NAME = 'event:listener:get';
17
    public const DESCRIPTION = 'Retrieve registered event listeners by type (JSON)';
18
    /**
19
     * @var \Jellyfish\Event\EventListenerProviderInterface
20
     */
21
    protected $eventListenerProvider;
22
23
    /**
24
     * @var \Jellyfish\Serializer\SerializerInterface
25
     */
26
    protected $serializer;
27
28
    /**
29
     * @param \Jellyfish\Event\EventListenerProviderInterface $eventListenerProvider
30
     * @param \Jellyfish\Serializer\SerializerInterface $serializer
31
     */
32
    public function __construct(
33
        EventListenerProviderInterface $eventListenerProvider,
34
        SerializerInterface $serializer
35
    ) {
36
        parent::__construct();
37
38
        $this->eventListenerProvider = $eventListenerProvider;
39
        $this->serializer = $serializer;
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    protected function configure(): void
46
    {
47
        parent::configure();
48
49
        $this->setName(static::NAME);
50
        $this->setDescription(static::DESCRIPTION);
51
52
        $this->addArgument('type', InputArgument::REQUIRED, 'Type');
53
    }
54
55
    /**
56
    * @param \Symfony\Component\Console\Input\InputInterface $input
57
    * @param \Symfony\Component\Console\Output\OutputInterface $output
58
    *
59
    * @return int
60
    */
61
    protected function execute(InputInterface $input, OutputInterface $output): int
62
    {
63
        $type = $input->getArgument('type');
64
65
        $json = $this->serializer->serialize((object) $this->eventListenerProvider->getListenersByType($type), 'json');
0 ignored issues
show
Bug introduced by
It seems like $type can also be of type null and string[]; however, parameter $type of Jellyfish\Event\EventLis...e::getListenersByType() 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

65
        $json = $this->serializer->serialize((object) $this->eventListenerProvider->getListenersByType(/** @scrutinizer ignore-type */ $type), 'json');
Loading history...
66
67
        $output->write($json);
68
69
        return 0;
70
    }
71
}
72