diff --git a/rules/TypeDeclaration/TypeNormalizer.php b/rules/TypeDeclaration/TypeNormalizer.php index fab270a1328..eab1e88749a 100644 --- a/rules/TypeDeclaration/TypeNormalizer.php +++ b/rules/TypeDeclaration/TypeNormalizer.php @@ -39,11 +39,11 @@ public function __construct( */ public function normalizeArrayOfUnionToUnionArray(Type $type, int $arrayNesting = 1): Type { - if (! $type instanceof ArrayType && ! $type instanceof ConstantArrayType) { + if (! $type->isArray()->yes()) { return $type; } - if ($type instanceof ConstantArrayType && $arrayNesting === 1) { + if ($type->isConstantArray()->yes() && $arrayNesting === 1) { return $type; } @@ -52,16 +52,17 @@ public function normalizeArrayOfUnionToUnionArray(Type $type, int $arrayNesting $this->collectedNestedArrayTypes = []; } - if ($type->getItemType() instanceof ArrayType) { + $itemType = $type->getIterableValueType(); + if ($itemType instanceof ArrayType) { ++$arrayNesting; - $this->normalizeArrayOfUnionToUnionArray($type->getItemType(), $arrayNesting); - } elseif ($type->getItemType() instanceof UnionType) { - $this->collectNestedArrayTypeFromUnionType($type->getItemType(), $arrayNesting); + $this->normalizeArrayOfUnionToUnionArray($itemType, $arrayNesting); + } elseif ($itemType instanceof UnionType) { + $this->collectNestedArrayTypeFromUnionType($itemType, $arrayNesting); } else { $this->collectedNestedArrayTypes[] = new NestedArrayType( - $type->getItemType(), + $itemType, $arrayNesting, - $type->getKeyType() + $type->getIterableKeyType() ); }