-
-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathFunctionInfoCommand.php
More file actions
56 lines (46 loc) · 1.77 KB
/
FunctionInfoCommand.php
File metadata and controls
56 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace Safe\Commands;
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
{
protected function configure(): void
{
$this
->setName('function-info')
->setDescription('Displays parsed info about a function.')
->addArgument('function', InputArgument::REQUIRED, 'The function name to display info about.')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$target = $input->getArgument("function");
$targetFilename = str_replace("_", "-", $target) . ".xml";
$phpStanFunctionMapReader = new PhpStanFunctionMapReader();
$finder = new Finder();
$finder->in(DocPage::referenceDir() . "/*/functions/")->name($targetFilename)->sortByName();
foreach ($finder as $file) {
$docPage = new DocPage($file->getPathname());
$functionObjects = $docPage->getMethodSynopsis();
$rootEntity = $docPage->loadAndResolveFile();
foreach ($functionObjects as $functionObject) {
$function = new Method(
$functionObject,
$rootEntity,
$docPage->getModule(),
$phpStanFunctionMapReader,
$docPage->getErrorType()
);
$output->writeln((string)$function);
}
}
return 0;
}
}