/**
  * @param AntiMattr\MongoDB\Migrations\Configuration\Configuration
  * @param Symfony\Component\Console\Input\InputInterface
  * @param string $version
  * @param string $up
  * @param string $down
  *
  * @return string $path
  *
  * @throws InvalidArgumentException
  */
 protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
 {
     $placeHolders = array('<namespace>', '<version>', '<up>', '<down>');
     $replacements = array($configuration->getMigrationsNamespace(), $version, $up ? "        " . implode("\n        ", explode("\n", $up)) : null, $down ? "        " . implode("\n        ", explode("\n", $down)) : null);
     $code = str_replace($placeHolders, $replacements, self::$_template);
     $dir = $this->getDirectory($configuration);
     // Verify Migrations directory exists
     if (!file_exists($dir)) {
         throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir));
     }
     $path = $this->buildVersionPath($dir, $version);
     // Output Version
     file_put_contents($path, $code);
     if ($editorCmd = $input->getOption('editor-cmd')) {
         shell_exec(sprintf('%s %s', $editorCmd, escapeshellarg($path)));
     }
     return $path;
 }