|
6 | 6 | use PHPStan\Analyser\Scope;
|
7 | 7 | use PHPStan\Php\PhpVersion;
|
8 | 8 | use PHPStan\Reflection\FunctionReflection;
|
9 |
| -use PHPStan\Reflection\ParametersAcceptorSelector; |
10 | 9 | use PHPStan\Type\Accessory\AccessoryArrayListType;
|
11 | 10 | use PHPStan\Type\Accessory\NonEmptyArrayType;
|
12 | 11 | use PHPStan\Type\ArrayType;
|
@@ -41,32 +40,34 @@ public function getTypeFromFunctionCall(
|
41 | 40 | Scope $scope,
|
42 | 41 | ): ?Type
|
43 | 42 | {
|
44 |
| - if (count($functionCall->getArgs()) < 2) { |
| 43 | + $args = $functionCall->getArgs(); |
| 44 | + if (count($args) < 2) { |
45 | 45 | return null;
|
46 | 46 | }
|
47 | 47 |
|
48 |
| - $delimiterType = $scope->getType($functionCall->getArgs()[0]->value); |
49 |
| - $isSuperset = (new ConstantStringType(''))->isSuperTypeOf($delimiterType); |
50 |
| - if ($isSuperset->yes()) { |
51 |
| - if ($this->phpVersion->getVersionId() >= 80000) { |
| 48 | + $delimiterType = $scope->getType($args[0]->value); |
| 49 | + $isEmptyString = (new ConstantStringType(''))->isSuperTypeOf($delimiterType); |
| 50 | + if ($isEmptyString->yes()) { |
| 51 | + if ($this->phpVersion->throwsTypeErrorForInternalFunctions()) { |
52 | 52 | return new NeverType();
|
53 | 53 | }
|
54 | 54 | return new ConstantBooleanType(false);
|
55 |
| - } elseif ($isSuperset->no()) { |
56 |
| - $arrayType = AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new StringType())); |
57 |
| - if ( |
58 |
| - !isset($functionCall->getArgs()[2]) |
59 |
| - || IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($scope->getType($functionCall->getArgs()[2]->value))->yes() |
60 |
| - ) { |
61 |
| - return TypeCombinator::intersect($arrayType, new NonEmptyArrayType()); |
62 |
| - } |
| 55 | + } |
| 56 | + |
| 57 | + $returnType = AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new StringType())); |
| 58 | + if ( |
| 59 | + !isset($args[2]) |
| 60 | + || IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($scope->getType($args[2]->value))->yes() |
| 61 | + ) { |
| 62 | + $returnType = TypeCombinator::intersect($returnType, new NonEmptyArrayType()); |
| 63 | + } |
63 | 64 |
|
64 |
| - return $arrayType; |
| 65 | + if (!$this->phpVersion->throwsValueErrorForInternalFunctions() && $isEmptyString->maybe()) { |
| 66 | + $returnType = TypeCombinator::union($returnType, new ConstantBooleanType(false)); |
65 | 67 | }
|
66 | 68 |
|
67 |
| - $returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType(); |
68 | 69 | if ($delimiterType instanceof MixedType) {
|
69 |
| - return TypeUtils::toBenevolentUnion($returnType); |
| 70 | + $returnType = TypeUtils::toBenevolentUnion($returnType); |
70 | 71 | }
|
71 | 72 |
|
72 | 73 | return $returnType;
|
|
0 commit comments