Skip to content

Commit

Permalink
avoid counters
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 16, 2023
1 parent d0120e7 commit 432a32d
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/Console/Command/SwitchFormatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symplify\ConfigTransformer\Configuration\ConfigurationFactory;
use Symplify\ConfigTransformer\Converter\ConfigFormatConverter;
Expand Down Expand Up @@ -52,12 +51,11 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$configuration = $this->configurationFactory->createFromInput($input);
$totalFileCount = $this->getTotalFileCount($configuration);

$fileInfos = $this->configFileFinder->findFileInfos($configuration->getSources());

if ($fileInfos === []) {
$successMessage = sprintf('No YAML configs found in %d files, good job!', $totalFileCount);
$this->symfonyStyle->success($successMessage);
$this->symfonyStyle->success('No YAML configs found, good job!');

return self::SUCCESS;
}
Expand All @@ -74,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// report fail in CI in case of changed files to notify the users about old configs
if ($configuration->isDryRun()) {
$successMessage = sprintf('%d file(s) out of %d should be switched to PHP', count($fileInfos), $totalFileCount);
$successMessage = sprintf('%d file(s) should be switched to PHP', count($fileInfos));
$this->symfonyStyle->error($successMessage);

return self::FAILURE;
Expand All @@ -95,19 +93,4 @@ private function removeOriginalYamlFileInfo(Configuration $configuration, SplFil

FileSystem::delete($fileInfo->getRealPath());
}

private function getTotalFileCount(Configuration $configuration): int
{
if (count($configuration->getSources()) === 1) {
$sources = $configuration->getSources();
if (is_file($sources[0])) {
return 1;
}
}

return Finder::create()
->files()
->in($configuration->getSources())
->count();
}
}

0 comments on commit 432a32d

Please sign in to comment.