CommandSubscriber::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace RMiller\BehatSpec\Extension\PhpSpecRunExtension;
4
5
use PhpSpec\Console\ConsoleIO;
6
use RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\RunRunner\CompositeRunRunner;
7
use Symfony\Component\Console\ConsoleEvents;
8
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
class CommandSubscriber implements EventSubscriberInterface
12
{
13
    private $runRunner;
14
    private $commands;
15
    private $io;
16
17
    function __construct(CompositeRunRunner $runRunner, ConsoleIO $io, array $commands)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18
    {
19
        $this->runRunner = $runRunner;
20
        $this->commands = $commands;
21
        $this->io = $io;
22
    }
23
24
    public static function getSubscribedEvents()
25
    {
26
        return [ConsoleEvents::TERMINATE => 'runRunCommand'];
27
    }
28
29
    public function runRunCommand(ConsoleTerminateEvent $event)
30
    {
31
        if (!in_array($event->getCommand()->getName(), $this->commands)) {
32
            return;
33
        }
34
35
        $this->io->writeln();
36
        if ($this->io->askConfirmation('Do you want to run the phpspec run command now? (Y/n)')) {
37
            $this->io->writeln();
38
            $this->runRunner->runRunCommand();
39
        }
40
    }
41
}
42