Skip to content

Commit 6d40f8a

Browse files
authored
[NodeTypeResolver] Handle ArrayType with intersection string on AccessoryNonEmptyArrayTypeCorrector (#7332)
* [NodeTypeResolver] Handle ArrayType with intersection string on AccessoryNonEmptyArrayTypeCorrector * [NodeTypeResolver] Handle ArrayType with intersection string on AccessoryNonEmptyArrayTypeCorrector
1 parent b6edd89 commit 6d40f8a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/NodeTypeResolver/NodeTypeCorrector/AccessoryNonEmptyArrayTypeCorrector.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Type\ArrayType;
99
use PHPStan\Type\IntersectionType;
1010
use PHPStan\Type\MixedType;
11+
use PHPStan\Type\StringType;
1112
use PHPStan\Type\Type;
1213

1314
final class AccessoryNonEmptyArrayTypeCorrector
@@ -26,6 +27,12 @@ public function correct(Type $mainType): Type
2627
if ($type instanceof NonEmptyArrayType) {
2728
return new ArrayType(new MixedType(), new MixedType());
2829
}
30+
31+
if ($type instanceof ArrayType
32+
&& $type->getIterableValueType() instanceof IntersectionType
33+
&& $type->getIterableValueType()->isString()->yes()) {
34+
return new ArrayType(new MixedType(), new StringType());
35+
}
2936
}
3037

3138
return $mainType;

src/NodeTypeResolver/NodeTypeResolver.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
use PHPStan\Type\Constant\ConstantBooleanType;
3535
use PHPStan\Type\Constant\ConstantStringType;
3636
use PHPStan\Type\ErrorType;
37-
use PHPStan\Type\IntegerType;
3837
use PHPStan\Type\MixedType;
3938
use PHPStan\Type\NeverType;
4039
use PHPStan\Type\NullType;
4140
use PHPStan\Type\ObjectType;
4241
use PHPStan\Type\ObjectWithoutClassType;
43-
use PHPStan\Type\StringType;
4442
use PHPStan\Type\ThisType;
4543
use PHPStan\Type\Type;
4644
use PHPStan\Type\TypeCombinator;
@@ -180,11 +178,6 @@ public function getType(Node $node): Type
180178
}
181179
}
182180

183-
// correction for explode() that always returns array
184-
if ($node instanceof FuncCall && $node->name instanceof Name && $node->name->toString() === 'explode') {
185-
return new ArrayType(new IntegerType(), new StringType());
186-
}
187-
188181
if ($node instanceof Ternary) {
189182
$ternaryType = $this->resolveTernaryType($node);
190183
if (! $ternaryType instanceof MixedType) {

0 commit comments

Comments
 (0)