Skip to content

Commit a95ed66

Browse files
committed
feat add if state for nonEmptySubject
1 parent 97ed353 commit a95ed66

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/Type/Php/PregSplitDynamicReturnTypeExtension.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,38 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
9494
}
9595

9696
$capturedArrayType = new ConstantArrayType(
97-
[
98-
new ConstantIntegerType(0),
99-
new ConstantIntegerType(1)], [$stringType, IntegerRangeType::fromInterval(0, null)
100-
],
97+
[new ConstantIntegerType(0), new ConstantIntegerType(1)], [$stringType, IntegerRangeType::fromInterval(0, null)],
10198
[2],
10299
[],
103100
TrinaryLogic::createYes()
104101
);
102+
105103
$valueType = $stringType;
106104
if ($flagArg !== null) {
107105
$flagState = $this->bitwiseFlagAnalyser->bitwiseOrContainsConstant($flagArg->value, $scope, 'PREG_SPLIT_OFFSET_CAPTURE');
108106
if ($flagState->yes()) {
109-
return TypeUtils::toBenevolentUnion(
110-
TypeCombinator::union(
111-
TypeCombinator::intersect(
112-
new ArrayType(new IntegerType(), $capturedArrayType),
113-
new AccessoryArrayListType()
114-
),
115-
new ConstantBooleanType(false)
116-
)
117-
);
107+
if ($subjectType->isNonEmptyString()->yes()) {
108+
return TypeUtils::toBenevolentUnion(
109+
TypeCombinator::union(
110+
TypeCombinator::intersect(
111+
new ArrayType(new IntegerType(), $capturedArrayType),
112+
new NonEmptyArrayType(),
113+
new AccessoryArrayListType(),
114+
),
115+
new ConstantBooleanType(false)
116+
)
117+
);
118+
} else {
119+
return TypeUtils::toBenevolentUnion(
120+
TypeCombinator::union(
121+
TypeCombinator::intersect(
122+
new ArrayType(new IntegerType(), $capturedArrayType),
123+
new AccessoryArrayListType(),
124+
),
125+
new ConstantBooleanType(false)
126+
)
127+
);
128+
}
118129
}
119130
if ($flagState->maybe()) {
120131
$valueType = TypeCombinator::union(new StringType(), $capturedArrayType);

0 commit comments

Comments
 (0)