Skip to content
Merged
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
50 changes: 30 additions & 20 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\Finder\Finder;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -30,6 +31,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->rmGenerated();

// Let's build the DTD necessary to load the XML files.
$this->checkout(DocPage::findReferenceDir(), "master");
DocPage::buildEntities();

// PHP documentation is a living document, which broadly reflects
Expand Down Expand Up @@ -64,7 +66,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->checkout(DocPage::findReferenceDir(), $commit);
$scanner = new Scanner(DocPage::findReferenceDir());
$res = $scanner->getMethods($scanner->getFunctionsPaths(), $output);
$output->writeln('These functions have been ignored and must be dealt with manually: '.\implode(', ', $res->overloadedFunctions));
$output->writeln(
'Functions have been ignored and must be dealt with manually: ' .
($output->isVerbose() ?
implode(', ', $res->overloadedFunctions) :
count($res->overloadedFunctions) . ' functions'
)
);

$currentFunctionsByName = [];
foreach ($res->methods as $function) {
Expand All @@ -83,8 +91,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$missingMethods[] = $oldFunction;
}
}
$output->writeln('Methods no longer need safe wrappers in ' . $version . ': ' .
\implode(', ', \array_map(fn($m) => $m->getFunctionName(), $missingMethods)));
$output->writeln(
'Functions no longer need safe wrappers in ' . $version . ': ' .
($output->isVerbose() ?
\implode(', ', \array_map(fn($m) => $m->getFunctionName(), $missingMethods)) :
count($missingMethods) . ' functions'
)
);

$genDir = FileCreator::getSafeRootDir() . "/generated/$version";
$fileCreator = new FileCreator();
Expand All @@ -111,32 +124,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int

private function checkout(string $dir, string $commit): void
{
$process = new Process(['git', 'clean', '-fdx'], $dir);
$process->setTimeout(10);
$code = $process->run();
if ($code !== 0) {
throw new \RuntimeException("Failed to git-clean in $dir (exit $code):\n{$process->getErrorOutput()}");
}

$process = new Process(['git', 'checkout', $commit], $dir);
$process->setTimeout(10);
$code = $process->run();
if ($code !== 0) {
throw new \RuntimeException("Failed to checkout $commit in $dir");
throw new \RuntimeException("Failed to checkout $commit in $dir (exit $code):\n{$process->getErrorOutput()}");
}
}

private function rmGenerated(): void
{
$exceptions = \glob(FileCreator::getSafeRootDir() . '/generated/Exceptions/*.php');
if ($exceptions === false) {
throw new \RuntimeException('Failed to require the generated exception files');
}

foreach ($exceptions as $exception) {
\unlink($exception);
}

$files = \glob(FileCreator::getSafeRootDir() . '/generated/*.php');
if ($files === false) {
throw new \RuntimeException('Failed to require the generated files');
}

foreach ($files as $file) {
\unlink($file);
$finder = new Finder();
$finder->in(FileCreator::getSafeRootDir() . "/generated");
foreach ($finder as $file) {
if ($file->isFile()) {
\unlink($file->getPathname());
}
}

if (\file_exists(DocPage::findDocDir() . '/entities/generated.ent')) {
Expand Down
Loading