Completed
Push — master ( 8ab33d...89db39 )
by Richard
03:16 queued 01:35
created

CommandSubscriber.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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