Passed
Pull Request — master (#74)
by Rustam
02:43
created

CommandCollector   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 55
ccs 30
cts 30
cp 1
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A reset() 0 3 1
A getCollected() 0 3 1
A getIndexData() 0 6 1
B collect() 0 28 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Symfony\Component\Console\Event\ConsoleCommandEvent;
8
use Symfony\Component\Console\Event\ConsoleErrorEvent;
9
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
10
11
final class CommandCollector implements CollectorInterface, IndexCollectorInterface
12
{
13
    use CollectorTrait;
14
15
    private array $commands = [];
16
17 2
    public function getCollected(): array
18
    {
19 2
        return $this->commands;
20
    }
21
22 2
    public function collect(object $event): void
23
    {
24 2
        if (!is_object($event) || !$this->isActive()) {
25 1
            return;
26
        }
27
28 1
        if ($event instanceof ConsoleCommandEvent) {
29 1
            $this->commands[get_class($event)] = [
30 1
                'command' => $event->getCommand(),
31 1
                'input' => $event->getInput()->__toString(),
0 ignored issues
show
Bug introduced by
The method __toString() does not exist on Symfony\Component\Console\Input\InputInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Consol...treamableInputInterface or Symfony\Component\Console\Input\Input or Symfony\Component\Console\Input\Input. Are you sure you never get one of those? ( Ignorable by Annotation )

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

31
                'input' => $event->getInput()->/** @scrutinizer ignore-call */ __toString(),
Loading history...
32 1
                'output' => $event->getOutput()->fetch(),
0 ignored issues
show
Bug introduced by
The method fetch() does not exist on Symfony\Component\Console\Output\OutputInterface. It seems like you code against a sub-type of Symfony\Component\Console\Output\OutputInterface such as Symfony\Component\Console\Output\BufferedOutput or Symfony\Component\Consol...put\TrimmedBufferOutput or Yiisoft\Yii\Console\Output\ConsoleBufferedOutput or Yiisoft\Yii\Console\Output\ConsoleBufferedOutput. ( Ignorable by Annotation )

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

32
                'output' => $event->getOutput()->/** @scrutinizer ignore-call */ fetch(),
Loading history...
33
            ];
34
        }
35 1
        if ($event instanceof ConsoleErrorEvent) {
36 1
            $this->commands[get_class($event)] = [
37 1
                'command' => $event->getCommand(),
38 1
                'input' => $event->getInput()->__toString(),
39 1
                'output' => $event->getOutput()->fetch(),
40 1
                'error' => $event->getError()->getMessage(),
41 1
                'exitCode' => $event->getExitCode(),
42
            ];
43
        }
44 1
        if ($event instanceof ConsoleTerminateEvent) {
45 1
            $this->commands[get_class($event)] = [
46 1
                'command' => $event->getCommand(),
47 1
                'input' => $event->getInput()->__toString(),
48 1
                'output' => $event->getOutput()->fetch(),
49 1
                'exitCode' => $event->getExitCode(),
50
            ];
51
        }
52 1
    }
53
54 1
    public function getIndexData(): array
55
    {
56 1
        $command = $this->commands[ConsoleCommandEvent::class];
57
        return [
58 1
            'command' => $command['input'],
59 1
            'commandClass' => get_class($command['command']),
60
        ];
61
    }
62
63 1
    private function reset(): void
0 ignored issues
show
Unused Code introduced by
The method reset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
64
    {
65 1
        $this->commands = [];
66 1
    }
67
}
68