Skip to content
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

Improve console lookup arguments #15

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
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
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