From 56c69cdc0075507e5ef952eb70fa968488c9f2c8 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 23 Nov 2024 10:03:39 +0100 Subject: [PATCH] Utilize PHPStan Type interface in TypeNormalizer --- rules/TypeDeclaration/TypeNormalizer.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rules/TypeDeclaration/TypeNormalizer.php b/rules/TypeDeclaration/TypeNormalizer.php index fab270a132..eab1e88749 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() ); }