diff --git a/generator/src/Commands/GenerateCommand.php b/generator/src/Commands/GenerateCommand.php index 0e7efba7..9a84e814 100644 --- a/generator/src/Commands/GenerateCommand.php +++ b/generator/src/Commands/GenerateCommand.php @@ -9,6 +9,7 @@ use Safe\Generator\FileCreator; use Safe\Generator\ComposerJsonEditor; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Finder\Finder; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -17,6 +18,8 @@ class GenerateCommand extends Command { + private SymfonyStyle $io; + protected function configure(): void { $this @@ -25,6 +28,11 @@ protected function configure(): void ; } + protected function initialize(InputInterface $input, OutputInterface $output) + { + $this->io = new SymfonyStyle($input, $output); + } + protected function execute( // These aren't actually sensitive, they just fill the // stack traces with tons of useless information. @@ -32,7 +40,6 @@ protected function execute( #[\SensitiveParameter] OutputInterface $output ): int { $this->rmGenerated(); - // Let's build the DTD necessary to load the XML files. $this->checkout(DocPage::findReferenceDir(), "master"); DocPage::buildEntities(); @@ -60,22 +67,30 @@ protected function execute( $pastFunctionNames = []; foreach ($versions as $version => $commit) { - $output->writeln('==============================================='); - $output->writeln('Generating safe wrappers for PHP ' . $version); - $output->writeln('==============================================='); + $this->io->title(\sprintf('Generating safe wrappers for PHP %s', $version)); // Scan the documentation for a given PHP version and find all // functions that we need to generate safe wrappers for. $this->checkout(DocPage::findReferenceDir(), $commit); $scanner = new Scanner(DocPage::findReferenceDir()); - $res = $scanner->getMethods($scanner->getFunctionsPaths(), $pastFunctionNames, $output); - $output->writeln( - 'Functions have been ignored and must be dealt with manually: ' . - ($output->isVerbose() ? - implode(', ', $res->overloadedFunctions) : - count($res->overloadedFunctions) . ' functions' - ) - ); + $res = $scanner->getMethods($scanner->getFunctionsPaths(), $pastFunctionNames, $this->io); + + $this->io->newLine(2); + $this->io->success(\sprintf( + '%d functions are safe.', + \count($res->methods), + )); + + if ($res->hasOverloadedFunctions()) { + $this->io->warning(\sprintf( + '%d functions have been ignored and must be dealt with manually. Rerun the command with -v to see them.', + \count($res->overloadedFunctions), + )); + } + + if ($output->isVerbose()) { + $this->io->table(['Function'], \array_map(static fn(string $function): array => [$function], $res->overloadedFunctions)); + } $currentFunctionsByName = []; foreach ($res->methods as $function) { diff --git a/generator/src/XmlDocParser/ScannerResponse.php b/generator/src/XmlDocParser/ScannerResponse.php index e82af9c4..3ef50412 100644 --- a/generator/src/XmlDocParser/ScannerResponse.php +++ b/generator/src/XmlDocParser/ScannerResponse.php @@ -15,4 +15,9 @@ public function __construct( public readonly array $overloadedFunctions ) { } + + public function hasOverloadedFunctions(): bool + { + return 0 <= \count($this->overloadedFunctions); + } }