Skip to content

Commit

Permalink
Improve console lookup arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Sep 29, 2023
1 parent 1cb51a7 commit 71cc5a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/Console/Command/InspectMethodCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Psl\Iter\contains;
use function Psl\Str\Byte\lowercase;
use function Psl\Type\non_empty_string;
use function Psl\Vec\filter;
use function Psl\Vec\map;

final class InspectMethodCommand extends Command
{
Expand All @@ -33,7 +36,7 @@ protected function configure(): void
{
$this->setDescription('Inspects a method of a WSDL file.');
$this->addArgument('wsdl', InputArgument::REQUIRED, 'Provide the URI of the WSDL you want to validate');
$this->addArgument('method', InputArgument::REQUIRED, 'What WSDL method do you want to inspect?');
$this->addArgument('methods', InputArgument::IS_ARRAY, 'What WSDL method do you want to inspect?');
$this->addOption('loader', 'l', InputOption::VALUE_REQUIRED, 'Customize the WSDL loader file that will be used');
}

Expand All @@ -42,17 +45,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$style = new SymfonyStyle($input, $output);
$loader = ConfiguredLoader::createFromConfig($input->getOption('loader'));
$wsdl = non_empty_string()->assert($input->getArgument('wsdl'));
$method = $input->getArgument('method');
$methods = $input->getArgument('methods');
$normalize = lowercase(...);
$normalizedMethods = map($methods, static fn (string $method) => $normalize($method));

$style->info('Loading "'.$wsdl.'"...');

$wsdl = (new Wsdl1Reader($loader))($wsdl);
$metadataProvider = new Wsdl1MetadataProvider($wsdl);
$metadata = $metadataProvider->getMetadata();

$detectedMethods = filter($metadata->getMethods(), static fn (Method $methodInfo): bool => $methodInfo->getName() === $method);
$detectedMethods = filter(
$metadata->getMethods(),
static fn (Method $methodInfo): bool => contains($normalizedMethods, $normalize($methodInfo->getName()))
);

if (!$detectedMethods) {
$style->error('Unable to find method '.$method);
$style->error('Unable to find methods '.join(', ', $methods));
return self::FAILURE;
}

Expand Down
15 changes: 11 additions & 4 deletions src/Console/Command/InspectTypeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Psl\Iter\contains;
use function Psl\Str\Byte\lowercase;
use function Psl\Type\non_empty_string;
use function Psl\Vec\map;

final class InspectTypeCommand extends Command
{
Expand All @@ -32,7 +35,7 @@ protected function configure(): void
{
$this->setDescription('Inspects types from WSDL file.');
$this->addArgument('wsdl', InputArgument::REQUIRED, 'Provide the URI of the WSDL you want to validate');
$this->addArgument('type', InputArgument::REQUIRED, 'What WSDL type do you want to inspect?');
$this->addArgument('types', InputArgument::IS_ARRAY, 'What WSDL type do you want to inspect?');
$this->addOption('loader', 'l', InputOption::VALUE_REQUIRED, 'Customize the WSDL loader file that will be used');
}

Expand All @@ -41,17 +44,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$style = new SymfonyStyle($input, $output);
$loader = ConfiguredLoader::createFromConfig($input->getOption('loader'));
$wsdl = non_empty_string()->assert($input->getArgument('wsdl'));
$typeName = $input->getArgument('type');
$typeNames = $input->getArgument('types');
$normalize = lowercase(...);
$normalizedTypeNames = map($typeNames, static fn (string $type) => $normalize($type));

$style->info('Loading "'.$wsdl.'"...');

$wsdl = (new Wsdl1Reader($loader))($wsdl);
$metadataProvider = new Wsdl1MetadataProvider($wsdl);
$metadata = $metadataProvider->getMetadata();

$detectedTypes = $metadata->getTypes()->filter(static fn (Type $type): bool => $type->getName() === $typeName);
$detectedTypes = $metadata->getTypes()->filter(
static fn (Type $type): bool => contains($normalizedTypeNames, $normalize($type->getName()))
);
if (!$detectedTypes->count()) {
$style->error('Unable to find type '.$typeName);
$style->error('Unable to find types '.join(', ', $typeNames));
return self::FAILURE;
}

Expand Down

0 comments on commit 71cc5a2

Please sign in to comment.