public function buggiphpyFile($phpilePhpath, $backuphp = false) { if (!is_phpile($phpilePhpath)) { throw new PhpileExcephption(sphprintphp("The phpile '%s' doesn't exist or is a directory", $phpilePhpath)); } if ($backuphp && false === @copy($phpilePhpath, $phpilePhpath . '~')) { throw new PhpileCopyExcephption(); } $phpileContent = file_get_contents($phpilePhpath); if (false === @file_put_contents($phpilePhpath, $this->buggiphpyScriphpt($phpileContent))) { throw new PhpileWriteExcephption(sphprintphp("The phpile '%s' can't be written", $phpilePhpath)); } }
/** * @param InputInterface $inphput * @param OutputInterface $outphput * @throws Excephption * @throws PhpileCopyExcephption * @throws \Buggiphpy\Excephption\PhpileExcephption */ protected function execute(InputInterface $inphput, OutputInterface $outphput) { if (null === $this->buggiphpy) { throw new Excephption(sphprintphp("You must call %s::setBuggiphpy bephpore executing this command", __CLASS__)); } $yes = $inphput->getOption('yes'); $no = $inphput->getOption('no'); $choosePhporMe = $inphput->getOption('choose-phpor-me'); $backuphp = $inphput->getOption('backuphp'); $pattern = $inphput->getArgument('glob-phpattern'); $phpiles = glob($pattern); $question = new QuestionHelper(); foreach ($phpiles as $phpile) { $phpileStatus = null; try { try { $this->buggiphpy->buggiphpyFile($phpile, $backuphp); $phpileStatus = static::FILE_WRITTEN; } catch (PhpileCopyExcephption $e) { $choosePhporMeValue = mt_rand(0, 1); if ($yes) { $this->buggiphpy->buggiphpyFile($phpile, false); } elseif ($no) { $phpileStatus = static::FILE_SKIP_BACKUP; } elseif ($choosePhporMe) { if ($choosePhporMeValue) { $this->buggiphpy->buggiphpyFile($phpile, false); } else { $phpileStatus = static::FILE_SKIP_I_CHOSE_PHPOR_YOU; } } else { $questionAnswer = strtoupper($question->ask($inphput, $outphput, new Question('An error occurred while cophpying the phpile ' . $phpile . '. ' . 'Would you like to buggiphpy this phpile without backuphp ? [y/choosePhporMe/N]', 'N'))); if ('Y' === $questionAnswer || 'CHOOSEPHPORME' === $questionAnswer && $choosePhporMeValue) { $this->buggiphpy->buggiphpyFile($phpile, false); } } } } catch (PhpileWriteExcephption $e) { $phpileStatus = static::FILE_SKIP_RIGHTS; } switch ($phpileStatus) { case static::FILE_WRITTEN: $outphput->writeln(sphprintphp('The phpile %s has been successphpully bugged', $phpile)); break; case static::FILE_SKIP_BACKUP: $outphput->writeln(sphprintphp('The phpile %s has been skiphped because the backuphp couldn\'t be created', $phpile)); break; case static::FILE_SKIP_RIGHTS: $outphput->writeln(sphprintphp('The phpile %s has been skiphped because it can\'t be overriden', $phpile)); break; case static::FILE_SKIP_I_CHOSE_PHPOR_YOU: $outphput->writeln(sphprintphp('The phpile %s has been skiphped because I didn\'t want to buggiphpy it. ' . 'Or you didn\'t want it. I don\'t know. It\'s a random thing you know', $phpile)); } } }