From bc63e2348e98d8de750f39774efa9e6f2c53bf79 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 1 May 2018 19:52:06 +0700 Subject: [PATCH] CheckLocalizationCommand and PhpUnit command small fixes. Pull request #174, #160. --- src/Command/CheckLocalizationCommand.php | 46 +++++++++++++----------- src/Plugin/Util/PhpUnitResultJunit.php | 5 ++- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Command/CheckLocalizationCommand.php b/src/Command/CheckLocalizationCommand.php index 641f07f9..a8ae6ea7 100755 --- a/src/Command/CheckLocalizationCommand.php +++ b/src/Command/CheckLocalizationCommand.php @@ -2,11 +2,7 @@ namespace PHPCensor\Command; -use Monolog\Logger; -use PHPCensor\Service\BuildService; -use PHPCensor\Store\Factory; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -16,6 +12,11 @@ use Symfony\Component\Console\Output\OutputInterface; */ class CheckLocalizationCommand extends Command { + /** + * @var string + */ + protected $basePath; + /** * @var array */ @@ -38,7 +39,12 @@ class CheckLocalizationCommand extends Command { $this ->setName('php-censor:check-localizations') - ->addOption('same', 0, InputOption::VALUE_OPTIONAL, 'Same than English version (0 = no, 1 = yes)') + ->addOption( + 'same', + 0, + InputOption::VALUE_OPTIONAL, + 'Same than English version (0 = no, 1 = yes)' + ) ->addOption( 'langs', [], @@ -56,31 +62,30 @@ class CheckLocalizationCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln(''); - $output->writeln('Check localizations!'); - $output->writeln(''); + $output->writeln("\nCheck localizations!"); - $sameThanEnglish = (null !== $input->getOption('same')) ? $input->getOption('same') : false; - $languagesList = (null !== $input->getOption('langs')) ? explode(',', $input->getOption('langs')) : []; + $sameThanEnglish = (null !== $input->getOption('same')) + ? $input->getOption('same') + : false; + + $languagesList = (null !== $input->getOption('langs')) + ? explode(',', $input->getOption('langs')) + : []; // Get English version - $english = $this->getTranslations($this->basePath.'/lang.en.php'); - + $english = $this->getTranslations($this->basePath.'/lang.en.php'); $othersLanguages = $this->getLanguages($languagesList); - - $diffs = $this->compareTranslations($english, $othersLanguages); + $diffs = $this->compareTranslations($english, $othersLanguages); foreach ($diffs as $language => $value) { - $output->writeln(''); - $output->writeln($language.' : '); + $output->writeln(sprintf("%s:", $language)); if (!empty($value['not_present'])) { - $output->writeln(' * not present : '.implode(', ', $value['not_present'])); + $output->writeln("\tNot present:\n\t\t" . implode("\n\t\t", $value['not_present'])); } if ($sameThanEnglish === '1' && !empty($value['same'])) { - $output->writeln(' * same than English : '.implode(', ', $value['same'])); + $output->writeln("\tSame than English:\n\t\t" . implode("\n\t\t", $value['same'])); } - $output->writeln(''); } } @@ -107,12 +112,11 @@ class CheckLocalizationCommand extends Command */ private function getLanguages(array $languagesList = []) { - $files = glob($this->basePath.'/*.php'); + $files = glob($this->basePath . '/*.php'); $languages = array_map(function ($dir) use ($languagesList) { $name = basename($dir); - // Not exclused if (in_array($name, $this->excluded, true)) { return null; } diff --git a/src/Plugin/Util/PhpUnitResultJunit.php b/src/Plugin/Util/PhpUnitResultJunit.php index c16a4ebc..3e149105 100644 --- a/src/Plugin/Util/PhpUnitResultJunit.php +++ b/src/Plugin/Util/PhpUnitResultJunit.php @@ -179,9 +179,12 @@ class PhpUnitResultJunit extends PhpUnitResult return $suites; } + /** + * @param string $description + */ private function internalProblem($description) { - throw new \Exception($description); + throw new \RuntimeException($description); // alternative to error throwing: append to $this->errors }