|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Behastan\Command; |
| 6 | + |
| 7 | +use Behastan\Analyzer\UnusedDefinitionsAnalyzer; |
| 8 | +use Behastan\Finder\BehatMetafilesFinder; |
| 9 | +use Symfony\Component\Console\Command\Command; |
| 10 | +use Symfony\Component\Console\Input\InputArgument; |
| 11 | +use Symfony\Component\Console\Input\InputInterface; |
| 12 | +use Symfony\Component\Console\Output\OutputInterface; |
| 13 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 14 | +use Webmozart\Assert\Assert; |
| 15 | + |
| 16 | +final class DefinitionStatsCommand extends Command |
| 17 | +{ |
| 18 | + public function __construct( |
| 19 | + private readonly SymfonyStyle $symfonyStyle, |
| 20 | + private readonly BehatMetafilesFinder $behatMetafilesFinder, |
| 21 | + private readonly UnusedDefinitionsAnalyzer $unusedDefinitionsAnalyzer, |
| 22 | + ) { |
| 23 | + parent::__construct(); |
| 24 | + } |
| 25 | + |
| 26 | + protected function configure(): void |
| 27 | + { |
| 28 | + $this->setName('definitions-stats'); |
| 29 | + |
| 30 | + $this->setDescription('Get Definition usage stats'); |
| 31 | + |
| 32 | + $this->addArgument( |
| 33 | + 'test-directory', |
| 34 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
| 35 | + 'Directories with *.Context.php and feature.yml files' |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 40 | + { |
| 41 | + $testDirectories = (array) $input->getArgument('test-directory'); |
| 42 | + Assert::allDirectory($testDirectories); |
| 43 | + |
| 44 | + $featureFiles = $this->behatMetafilesFinder->findFeatureFiles($testDirectories); |
| 45 | + if ($featureFiles === []) { |
| 46 | + $this->symfonyStyle->error('No *.feature files found. Please provide correct test directory'); |
| 47 | + return self::FAILURE; |
| 48 | + } |
| 49 | + |
| 50 | + $contextFiles = $this->behatMetafilesFinder->findContextFiles($testDirectories); |
| 51 | + if ($contextFiles === []) { |
| 52 | + $this->symfonyStyle->error('No *Context.php files found. Please provide correct test directory'); |
| 53 | + return self::FAILURE; |
| 54 | + } |
| 55 | + |
| 56 | + $this->symfonyStyle->title('Usage stats for PHP definitions in *Feature files'); |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + return Command::SUCCESS; |
| 61 | + } |
| 62 | +} |
0 commit comments