From f49b4daba368cdd89ff8a221827848e533cca257 Mon Sep 17 00:00:00 2001 From: Damien Debin Date: Fri, 21 Aug 2020 13:23:09 +0200 Subject: [PATCH] Adjusts GetOption return type if no default value. --- .../InputInterfaceGetOptionDynamicReturnTypeExtension.php | 4 ++-- .../InputInterfaceGetOptionDynamicReturnTypeExtensionTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtension.php b/src/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtension.php index 9aa78b2a..40a3993f 100644 --- a/src/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtension.php +++ b/src/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtension.php @@ -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())); } diff --git a/tests/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtensionTest.php b/tests/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtensionTest.php index c95ca57f..affb0c62 100644 --- a/tests/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtensionTest.php +++ b/tests/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtensionTest.php @@ -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']; yield ['$e', 'array'];