Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;

final class AccessoryNonEmptyArrayTypeCorrector
Expand All @@ -26,6 +27,12 @@ public function correct(Type $mainType): Type
if ($type instanceof NonEmptyArrayType) {
return new ArrayType(new MixedType(), new MixedType());
}

if ($type instanceof ArrayType
&& $type->getIterableValueType() instanceof IntersectionType
&& $type->getIterableValueType()->isString()->yes()) {
return new ArrayType(new MixedType(), new StringType());
}
}

return $mainType;
Expand Down
7 changes: 0 additions & 7 deletions src/NodeTypeResolver/NodeTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
Expand Down Expand Up @@ -180,11 +178,6 @@ public function getType(Node $node): Type
}
}

// correction for explode() that always returns array
if ($node instanceof FuncCall && $node->name instanceof Name && $node->name->toString() === 'explode') {
return new ArrayType(new IntegerType(), new StringType());
}

if ($node instanceof Ternary) {
$ternaryType = $this->resolveTernaryType($node);
if (! $ternaryType instanceof MixedType) {
Expand Down
Loading