Skip to content

Make function-info 4000x faster #590

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

Merged
merged 1 commit into from
Feb 7, 2025
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
28 changes: 21 additions & 7 deletions generator/src/Commands/FunctionInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Safe\Commands;

use Safe\XmlDocParser\Scanner;
use Safe\XmlDocParser\Method;
use Safe\XmlDocParser\DocPage;
use Safe\PhpStanFunctions\PhpStanFunctionMapReader;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;

class FunctionInfoCommand extends Command
{
Expand All @@ -24,14 +26,26 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$scanner = new Scanner(DocPage::findReferenceDir());
$res = $scanner->getMethods($scanner->getFunctionsPaths(), $output);
$target = $input->getArgument("function");
$targetFilename = str_replace("_", "-", $target) . ".xml";

foreach ($res->methods as $function) {
$name = $function->getFunctionName();
if ($name == $input->getArgument("function")) {
$phpStanFunctionMapReader = new PhpStanFunctionMapReader();

$finder = new Finder();
$finder->in(DocPage::findReferenceDir())->name($targetFilename)->sortByName();

foreach ($finder as $file) {
$docPage = new DocPage($file->getPathname());
$isFalsy = $docPage->detectFalsyFunction();
$isNullsy = $docPage->detectNullsyFunction();
$isEmpty = $docPage->detectEmptyFunction();
$errorType = $isFalsy ? Method::FALSY_TYPE : ($isNullsy ? Method::NULLSY_TYPE : Method::EMPTY_TYPE);

$functionObjects = $docPage->getMethodSynopsis();
$rootEntity = $docPage->loadAndResolveFile();
foreach ($functionObjects as $functionObject) {
$function = new Method($functionObject, $rootEntity, $docPage->getModule(), $phpStanFunctionMapReader, $errorType);
$output->writeln((string)$function);
break;
}
}

Expand Down