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

Add support for InputInterface::getOption('x'|'y'|'z') #268

Open
Seldaek opened this issue Apr 6, 2022 · 0 comments
Open

Add support for InputInterface::getOption('x'|'y'|'z') #268

Seldaek opened this issue Apr 6, 2022 · 0 comments

Comments

@Seldaek
Copy link

Seldaek commented Apr 6, 2022

When you pass a variable getOption($optName) and $optName is a set of multiple string literals, it should still be possible to resolve the type(s).

It seems fairly easy to tweak

$optStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));
if (count($optStrings) !== 1) {
return $defaultReturnType;
}
$optName = $optStrings[0]->getValue();
$optTypes = [];
foreach ($this->consoleApplicationResolver->findCommands($classReflection) as $command) {
try {
$command->mergeApplicationDefinition();
$option = $command->getDefinition()->getOption($optName);
if (!$option->acceptValue()) {
$optType = new BooleanType();
} else {
$optType = TypeCombinator::union(new StringType(), new NullType());
if ($option->isValueRequired() && ($option->isArray() || $option->getDefault() !== null)) {
$optType = TypeCombinator::removeNull($optType);
}
if ($option->isArray()) {
$optType = new ArrayType(new IntegerType(), $optType);
}
$optType = TypeCombinator::union($optType, $scope->getTypeFromValue($option->getDefault()));
}
$optTypes[] = $optType;
} catch (InvalidArgumentException $e) {
// noop
}
}
return count($optTypes) > 0 ? TypeCombinator::union(...$optTypes) : $defaultReturnType;
to do a loop and concat all the different types instead of returning early a mixed here.

I may try to do this one day, but tonight no time so adding a note here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant