diff --git a/src/Type/Symfony/HeaderBagDynamicReturnTypeExtension.php b/src/Type/Symfony/HeaderBagDynamicReturnTypeExtension.php index 4450a063..42c6878a 100644 --- a/src/Type/Symfony/HeaderBagDynamicReturnTypeExtension.php +++ b/src/Type/Symfony/HeaderBagDynamicReturnTypeExtension.php @@ -39,13 +39,13 @@ public function getTypeFromMethodCall( $isFalseType = (new ConstantBooleanType(false))->isSuperTypeOf($firstArgType); $compareTypes = $isTrueType->compareTo($isFalseType); - $defaultArgType = isset($methodCall->args[1]) ? $scope->getType($methodCall->args[1]->value) : new NullType(); - if ($compareTypes === $isTrueType) { + $defaultArgType = isset($methodCall->args[1]) ? $scope->getType($methodCall->args[1]->value) : new NullType(); + return TypeCombinator::union($defaultArgType, new StringType()); } if ($compareTypes === $isFalseType) { - return TypeCombinator::union($defaultArgType, new ArrayType(new IntegerType(), new StringType())); + return new ArrayType(new IntegerType(), new StringType()); } return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); diff --git a/tests/Type/Symfony/HeaderBagDynamicReturnTypeExtensionTest.php b/tests/Type/Symfony/HeaderBagDynamicReturnTypeExtensionTest.php index 67fb6199..084f4aca 100644 --- a/tests/Type/Symfony/HeaderBagDynamicReturnTypeExtensionTest.php +++ b/tests/Type/Symfony/HeaderBagDynamicReturnTypeExtensionTest.php @@ -25,13 +25,10 @@ public function getProvider(): Iterator yield ['$test1', 'string|null']; yield ['$test2', 'string|null']; yield ['$test3', 'string']; - yield ['$test4', 'array|string']; yield ['$test5', 'string|null']; yield ['$test6', 'string']; - yield ['$test7', 'array|string']; - yield ['$test8', 'array|null']; - yield ['$test9', 'array|string']; - yield ['$test10', 'array']; + yield ['$test8', 'array']; + yield ['$test9', 'array']; } } diff --git a/tests/Type/Symfony/header_bag_get.php b/tests/Type/Symfony/header_bag_get.php index dd21d017..ed2d36aa 100644 --- a/tests/Type/Symfony/header_bag_get.php +++ b/tests/Type/Symfony/header_bag_get.php @@ -5,14 +5,11 @@ $test1 = $bag->get('foo'); $test2 = $bag->get('foo', null); $test3 = $bag->get('foo', 'baz'); -$test4 = $bag->get('foo', ['baz']); $test5 = $bag->get('foo', null, true); $test6 = $bag->get('foo', 'baz', true); -$test7 = $bag->get('foo', ['baz'], true); $test8 = $bag->get('foo', null, false); $test9 = $bag->get('foo', 'baz', false); -$test10 = $bag->get('foo', ['baz'], false); die;