Skip to content

Commit 28f5852

Browse files
committed
remove accessory array type, to allow array type fill
1 parent 3db92ed commit 28f5852

4 files changed

Lines changed: 28 additions & 91 deletions

File tree

rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/FixtureIntersection/cover_intersection.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/FixtureIntersection/cover_intersection_with_docblock.php.inc

Lines changed: 0 additions & 53 deletions
This file was deleted.

rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
use PhpParser\Node\Identifier;
1313
use PhpParser\Node\VariadicPlaceholder;
1414
use PHPStan\Reflection\ReflectionProvider;
15-
use PHPStan\Type\Accessory\AccessoryArrayListType;
1615
use PHPStan\Type\ArrayType;
1716
use PHPStan\Type\Constant\ConstantArrayType;
18-
use PHPStan\Type\IntersectionType;
1917
use PHPStan\Type\MixedType;
2018
use PHPStan\Type\NeverType;
2119
use PHPStan\Type\ObjectType;
2220
use PHPStan\Type\ThisType;
2321
use PHPStan\Type\Type;
24-
use PHPStan\Type\TypeCombinator;
25-
use PHPStan\Type\TypeUtils;
2622
use PHPStan\Type\UnionType;
2723
use Rector\NodeTypeResolver\NodeTypeResolver;
2824
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
@@ -94,15 +90,6 @@ private function resolveStrictArgValueType(Arg $arg): Type
9490
{
9591
$argValueType = $this->nodeTypeResolver->getNativeType($arg->value);
9692

97-
if ($argValueType instanceof IntersectionType) {
98-
dump($argValueType);
99-
100-
$argValueType = TypeCombinator::remove($argValueType, new AccessoryArrayListType());
101-
102-
dump($argValueType);
103-
die;
104-
}
105-
10693
return $this->normalizeType($argValueType);
10794
}
10895

src/NodeTypeResolver/NodeTypeResolver.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
use PHPStan\Reflection\ClassReflection;
3030
use PHPStan\Reflection\Native\NativeFunctionReflection;
3131
use PHPStan\Reflection\ReflectionProvider;
32+
use PHPStan\Type\Accessory\AccessoryArrayListType;
3233
use PHPStan\Type\ArrayType;
3334
use PHPStan\Type\Constant\ConstantArrayType;
3435
use PHPStan\Type\Constant\ConstantBooleanType;
3536
use PHPStan\Type\Constant\ConstantStringType;
3637
use PHPStan\Type\ErrorType;
38+
use PHPStan\Type\IntersectionType;
3739
use PHPStan\Type\MixedType;
3840
use PHPStan\Type\NeverType;
3941
use PHPStan\Type\NullType;
@@ -279,6 +281,10 @@ public function getNativeType(Expr $expr): Type
279281
$type = $this->resolveArrayDimFetchType($expr, $scope, $type);
280282
}
281283

284+
if ($type instanceof IntersectionType) {
285+
$type = $this->cleanArrayIntersectionType($type);
286+
}
287+
282288
if (! $type instanceof UnionType) {
283289
if ($this->isAnonymousObjectType($type)) {
284290
return new ObjectWithoutClassType();
@@ -675,4 +681,26 @@ private function isSubstrOnPHP74(FuncCall $funcCall): bool
675681

676682
return ! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersion::PHP_80);
677683
}
684+
685+
private function cleanArrayIntersectionType(Type $type): Type
686+
{
687+
if (! $type instanceof IntersectionType) {
688+
return $type;
689+
}
690+
691+
$cleanTypes = [];
692+
foreach ($type->getTypes() as $intersectionType) {
693+
if ($intersectionType instanceof AccessoryArrayListType) {
694+
continue;
695+
}
696+
697+
$cleanTypes[] = $intersectionType;
698+
}
699+
700+
if (count($cleanTypes) === 1) {
701+
return $cleanTypes[0];
702+
}
703+
704+
return new IntersectionType($cleanTypes);
705+
}
678706
}

0 commit comments

Comments
 (0)