Skip to content

Commit 1ee1a79

Browse files
committed
fix: for using ConstantArrayTypeBuilder and UnionType
1 parent a54bd80 commit 1ee1a79

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Type/Php/PregSplitDynamicReturnTypeExtension.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use PHPStan\Type\StringType;
2727
use PHPStan\Type\Type;
2828
use PHPStan\Type\TypeCombinator;
29+
use PHPStan\Type\UnionType;
2930
use function count;
3031
use function is_array;
3132
use function is_int;
@@ -113,13 +114,16 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
113114
$returnStringType = new StringType();
114115
}
115116

116-
$capturedArrayType = new ConstantArrayType(
117-
[new ConstantIntegerType(0), new ConstantIntegerType(1)],
118-
[$returnStringType, IntegerRangeType::fromInterval(0, null)],
119-
[2],
120-
[],
121-
TrinaryLogic::createYes(),
117+
$arrayTypeBuilder = ConstantArrayTypeBuilder::createEmpty();
118+
$arrayTypeBuilder->setOffsetValueType(
119+
new ConstantIntegerType(0),
120+
$returnStringType
122121
);
122+
$arrayTypeBuilder->setOffsetValueType(
123+
new ConstantIntegerType(1),
124+
IntegerRangeType::fromInterval(0, null)
125+
);
126+
$capturedArrayType = $arrayTypeBuilder->getArray();
123127

124128
$returnInternalValueType = $returnStringType;
125129
if ($capturesOffset !== null) {
@@ -203,7 +207,7 @@ private function isValidPattern(string $pattern): bool
203207

204208
private function isIntOrStringValue(Type $type): bool
205209
{
206-
return $type->isInteger()->yes() || $type->isString()->yes() || $type->isConstantScalarValue()->yes();
210+
return (new UnionType([new IntegerType(), new StringType()]))->isSuperTypeOf($type)->yes();
207211
}
208212

209213
}

0 commit comments

Comments
 (0)