Skip to content

Commit 98f1c1e

Browse files
committed
Make function-info 4000x faster
We don't need to load all 4000 xml files - we can just search for a file whose name matches the function name, and open that one
1 parent 5f5d38a commit 98f1c1e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

generator/src/Commands/FunctionInfoCommand.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
namespace Safe\Commands;
66

7-
use Safe\XmlDocParser\Scanner;
7+
use Safe\XmlDocParser\Method;
88
use Safe\XmlDocParser\DocPage;
9+
use Safe\PhpStanFunctions\PhpStanFunctionMapReader;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Input\InputArgument;
1213
use Symfony\Component\Console\Output\OutputInterface;
14+
use Symfony\Component\Finder\Finder;
1315

1416
class FunctionInfoCommand extends Command
1517
{
@@ -24,14 +26,26 @@ protected function configure(): void
2426

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

30-
foreach ($res->methods as $function) {
31-
$name = $function->getFunctionName();
32-
if ($name == $input->getArgument("function")) {
32+
$phpStanFunctionMapReader = new PhpStanFunctionMapReader();
33+
34+
$finder = new Finder();
35+
$finder->in(DocPage::findReferenceDir())->name($targetFilename)->sortByName();
36+
37+
foreach ($finder as $file) {
38+
$docPage = new DocPage($file->getPathname());
39+
$isFalsy = $docPage->detectFalsyFunction();
40+
$isNullsy = $docPage->detectNullsyFunction();
41+
$isEmpty = $docPage->detectEmptyFunction();
42+
$errorType = $isFalsy ? Method::FALSY_TYPE : ($isNullsy ? Method::NULLSY_TYPE : Method::EMPTY_TYPE);
43+
44+
$functionObjects = $docPage->getMethodSynopsis();
45+
$rootEntity = $docPage->loadAndResolveFile();
46+
foreach ($functionObjects as $functionObject) {
47+
$function = new Method($functionObject, $rootEntity, $docPage->getModule(), $phpStanFunctionMapReader, $errorType);
3348
$output->writeln((string)$function);
34-
break;
3549
}
3650
}
3751

0 commit comments

Comments
 (0)