Skip to content

feat(chore): Use SymfonyStyle for console output #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions generator/src/Commands/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,8 @@

class GenerateCommand extends Command
{
private SymfonyStyle $io;

protected function configure(): void
{
$this
Expand All @@ -25,14 +28,18 @@ 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.
#[\SensitiveParameter] InputInterface $input,
#[\SensitiveParameter] OutputInterface $output
): int {
$this->rmGenerated();

// Let's build the DTD necessary to load the XML files.
$this->checkout(DocPage::findReferenceDir(), "master");
DocPage::buildEntities();
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions generator/src/XmlDocParser/ScannerResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public function __construct(
public readonly array $overloadedFunctions
) {
}

public function hasOverloadedFunctions(): bool
{
return 0 <= \count($this->overloadedFunctions);
}
}
Loading