From 0ed815cc7bc20f05f53b4119b87353027f115c31 Mon Sep 17 00:00:00 2001 From: Silas Joisten Date: Thu, 15 May 2025 14:13:31 +0200 Subject: [PATCH 1/2] feat(chore): Use symfony style --- generator/src/Commands/GenerateCommand.php | 40 +++++++++++++------ .../src/XmlDocParser/ScannerResponse.php | 5 +++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/generator/src/Commands/GenerateCommand.php b/generator/src/Commands/GenerateCommand.php index 0e7efba7..eb32ad11 100644 --- a/generator/src/Commands/GenerateCommand.php +++ b/generator/src/Commands/GenerateCommand.php @@ -4,11 +4,13 @@ namespace Safe\Commands; +use Safe\Templating\Filesystem; use Safe\XmlDocParser\Scanner; use Safe\XmlDocParser\DocPage; 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 +19,8 @@ class GenerateCommand extends Command { + private SymfonyStyle $io; + protected function configure(): void { $this @@ -25,6 +29,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 +41,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 +68,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); + } } From c716ae66f516d8042a06ac463644ff670f0ea64b Mon Sep 17 00:00:00 2001 From: Silas Joisten Date: Thu, 15 May 2025 14:15:04 +0200 Subject: [PATCH 2/2] Update generator/src/Commands/GenerateCommand.php --- generator/src/Commands/GenerateCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/generator/src/Commands/GenerateCommand.php b/generator/src/Commands/GenerateCommand.php index eb32ad11..9a84e814 100644 --- a/generator/src/Commands/GenerateCommand.php +++ b/generator/src/Commands/GenerateCommand.php @@ -4,7 +4,6 @@ namespace Safe\Commands; -use Safe\Templating\Filesystem; use Safe\XmlDocParser\Scanner; use Safe\XmlDocParser\DocPage; use Safe\Generator\FileCreator;