diff --git a/generator/src/Commands/ScanObjectsCommand.php b/generator/src/Commands/ScanObjectsCommand.php index de0871db..1f7c0348 100644 --- a/generator/src/Commands/ScanObjectsCommand.php +++ b/generator/src/Commands/ScanObjectsCommand.php @@ -4,14 +4,20 @@ namespace Safe\Commands; +use Safe\Domain\MethodDefinition; +use Safe\XmlDocParser\Method; use Safe\XmlDocParser\Scanner; use Safe\XmlDocParser\DocPage; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; -class ScanObjectsCommand extends Command +final class ScanObjectsCommand extends Command { + private SymfonyStyle $io; + private Scanner $scanner; + protected function configure(): void { $this @@ -20,20 +26,26 @@ protected function configure(): void ; } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function initialize(InputInterface $input, OutputInterface $output): void { - $scanner = new Scanner(DocPage::referenceDir()); + $this->io = new SymfonyStyle($input, $output); + $this->scanner = new Scanner(DocPage::referenceDir()); + } - $paths = $scanner->getMethodsPaths(); + protected function execute(InputInterface $input, OutputInterface $output): int + { + $this->io->title($this->getDescription()); - $res = $scanner->getMethods($paths, [], $output); + $result = $this->scanner->getMethods($this->scanner->getMethodsPaths(), [], $output); - foreach ($res->methods as $function) { - $name = $function->getFunctionName(); - $output->writeln('Found method '.$name); - } + $this->io->table( + ['Method', 'Error Type', 'Safe'], + \array_merge( + \array_map(static fn(Method $method) => [$method->getFunctionName(), $method->getErrorType()->name, '✅'], $result->methods), + \array_map(static fn(MethodDefinition $method) => [$method->name, $method->errorType->name, '❌'], $result->overloadedFunctions), + ), + ); - $output->writeln('These methods are overloaded: '.\implode(', ', $res->overloadedFunctions)); - return 0; + return self::SUCCESS; } } diff --git a/generator/src/Domain/MethodDefinition.php b/generator/src/Domain/MethodDefinition.php new file mode 100644 index 00000000..26b72c30 --- /dev/null +++ b/generator/src/Domain/MethodDefinition.php @@ -0,0 +1,21 @@ +name; + } +} diff --git a/generator/src/XmlDocParser/Scanner.php b/generator/src/XmlDocParser/Scanner.php index 3ac8438f..030de94a 100644 --- a/generator/src/XmlDocParser/Scanner.php +++ b/generator/src/XmlDocParser/Scanner.php @@ -4,6 +4,7 @@ namespace Safe\XmlDocParser; +use Safe\Domain\MethodDefinition; use function array_merge; use function iterator_to_array; use Safe\PhpStanFunctions\PhpStanFunctionMapReader; @@ -115,7 +116,7 @@ public function getMethods(array $paths, array $pastFunctionNames, OutputInterfa { /** @var Method[] $functions */ $functions = []; - /** @var string[] $overloadedFunctions */ + /** @var MethodDefinition[] $overloadedFunctions */ $overloadedFunctions = []; $phpStanFunctionMapReader = new PhpStanFunctionMapReader(); @@ -149,12 +150,9 @@ public function getMethods(array $paths, array $pastFunctionNames, OutputInterfa if ($errorType !== ErrorType::UNKNOWN || $wasThisFunctionUnsafe) { $functionObjects = $docPage->getMethodSynopsis(); if (count($functionObjects) > 1) { - $overloadedFunctions = array_merge($overloadedFunctions, \array_map(function ($functionObject) { - return $functionObject->methodname->__toString(); - }, $functionObjects)); - $overloadedFunctions = \array_filter($overloadedFunctions, function (string $functionName) use ($ignoredFunctions) { - return !isset($ignoredFunctions[$functionName]); - }); + $overloadedFunctions = \array_merge($overloadedFunctions, \array_map(static fn(\SimpleXMLElement $functionObject) => new MethodDefinition((string) $functionObject->methodname, $errorType), $functionObjects)); + $overloadedFunctions = \array_filter($overloadedFunctions, static fn(MethodDefinition $method) => !\array_key_exists($method->name, $ignoredFunctions)); + continue; } $rootEntity = $docPage->loadAndResolveFile(); @@ -167,6 +165,7 @@ public function getMethods(array $paths, array $pastFunctionNames, OutputInterfa } } } + $progressBar->finish(); $output->writeln(""); diff --git a/generator/src/XmlDocParser/ScannerResponse.php b/generator/src/XmlDocParser/ScannerResponse.php index e82af9c4..43918ff7 100644 --- a/generator/src/XmlDocParser/ScannerResponse.php +++ b/generator/src/XmlDocParser/ScannerResponse.php @@ -4,11 +4,13 @@ namespace Safe\XmlDocParser; +use Safe\Domain\MethodDefinition; + class ScannerResponse { /** * @param Method[] $methods - * @param string[] $overloadedFunctions + * @param MethodDefinition[] $overloadedFunctions */ public function __construct( public readonly array $methods,