Skip to content

Commit 9954344

Browse files
committed
add combination limit
1 parent 61e6673 commit 9954344

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Type/Php/ImplodeFunctionReturnTypeExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Internal\CombinationsHelper;
88
use PHPStan\Reflection\FunctionReflection;
9+
use PHPStan\Reflection\InitializerExprTypeResolver;
910
use PHPStan\Type\Accessory\AccessoryLiteralStringType;
1011
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
1112
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
@@ -128,6 +129,10 @@ private function inferConstantType(ConstantArrayType $arrayType, ConstantStringT
128129
}
129130
}
130131

132+
if (count($strings) > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT) {
133+
return null;
134+
}
135+
131136
return TypeCombinator::union(...$strings);
132137
}
133138

tests/PHPStan/Analyser/nsrt/implode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ public function constArrays4($constArr) {
4646
public function constArrays5($constArr) {
4747
assertType("'1a'|'1b'|'1c'|'2a'|'2b'|'2c'|'3a'|'3b'|'3c'", implode('', $constArr));
4848
}
49+
50+
/** @param array{0: 1, 1: 'a'|'b', 3?: 'c'|'d', 4?: 'e'|'f', 5?: 'g'|'h', 6?: 'x'|'y'} $constArr */
51+
public function constArrays6($constArr) {
52+
assertType("string", implode('', $constArr));
53+
}
4954
}

0 commit comments

Comments
 (0)