Skip to content

Adjusts getOption return type if no default value. #95

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

Merged
merged 1 commit into from
Oct 1, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
if (!$option->acceptValue()) {
$optType = new BooleanType();
} else {
$optType = TypeCombinator::union(new StringType(), new IntegerType(), new NullType());
$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(), TypeCombinator::remove($optType, new IntegerType()));
$optType = new ArrayType(new IntegerType(), $optType);
}
$optType = TypeCombinator::union($optType, $scope->getTypeFromValue($option->getDefault()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function testArgumentTypes(string $expression, string $type): void
public function argumentTypesProvider(): Iterator
{
yield ['$a', 'bool'];
yield ['$b', 'int|string|null'];
yield ['$c', 'int|string|null'];
yield ['$b', 'string|null'];
yield ['$c', 'string|null'];
yield ['$d', 'array<int, string|null>'];
yield ['$e', 'array<int, string>'];

Expand Down