Skip to content

Commit 8c0035f

Browse files
Improve
1 parent 6ffb23c commit 8c0035f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(
9090
return TypeUtils::toBenevolentUnion($defaultReturnType);
9191
}
9292

93-
$stringOrArray = new UnionType([new StringType(), new ArrayType(new MixedType(), new MixedType())]);
94-
if (!$stringOrArray->isSuperTypeOf($subjectArgumentType)->yes()) {
95-
return $defaultReturnType;
96-
}
97-
9893
$replaceArgumentType = null;
9994
if (array_key_exists($functionReflection->getName(), self::FUNCTIONS_REPLACE_POSITION)) {
10095
$replaceArgumentPosition = self::FUNCTIONS_REPLACE_POSITION[$functionReflection->getName()];
@@ -109,12 +104,20 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(
109104

110105
$result = [];
111106

112-
$stringArgumentType = TypeCombinator::intersect(new StringType(), $subjectArgumentType);
107+
if ($subjectArgumentType->isString()->yes()) {
108+
$stringArgumentType = $subjectArgumentType;
109+
} else {
110+
$stringArgumentType = TypeCombinator::intersect(new StringType(), $subjectArgumentType);
111+
}
113112
if ($stringArgumentType->isString()->yes()) {
114113
$result[] = $this->getReplaceType($stringArgumentType, $replaceArgumentType);
115114
}
116115

117-
$arrayArgumentType = TypeCombinator::intersect(new ArrayType(new MixedType(), new MixedType()), $subjectArgumentType);
116+
if ($subjectArgumentType->isArray()->yes()) {
117+
$arrayArgumentType = $subjectArgumentType;
118+
} else {
119+
$arrayArgumentType = TypeCombinator::intersect(new ArrayType(new MixedType(), new MixedType()), $subjectArgumentType);
120+
}
118121
if ($arrayArgumentType->isArray()->yes()) {
119122
$keyShouldBeOptional = in_array(
120123
$functionReflection->getName(),

0 commit comments

Comments
 (0)