richardmiller /
PhpSpecRunExtension
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
|
|||
| 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 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.