public function afterExample(ExampleEvent $event)
{
$exception = $event->getException();
if (null !== $exception && $exception instanceof MethodNotFoundException) {
if (null === ($ioTemp = $this->io->cutTemp())) {
if ("\n" !== $this->io->getLastWrittenMessage()) {
$this->io->writeln();
}
}
$shortcut = get_class($exception->getSubject()) . '::' . $exception->getMethod();
if (in_array($shortcut, $this->proposedMethods)) {
return;
}
$this->proposedMethods[] = $shortcut;
if ($this->io->askConfirmation('Do you want me to create this method for you?')) {
$class = new \ReflectionClass($exception->getSubject());
$method = $exception->getMethod();
$content = file_get_contents($class->getFileName());
$content = preg_replace('/}[ \\n]*$/', $this->getMethodContentFor($method) . "\n}\n", $content);
file_put_contents($class->getFileName(), $content);
$this->io->writeln(sprintf("\n<info>Method <value>%s::%s()</value> has been created.</info>", $class->getName(), $method), 6);
}
$this->io->writeln();
if (null !== $ioTemp) {
$this->io->writeTemp($ioTemp);
}
}
}