From d6dab6464586433f4d16060419af9855eafa7bcc Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 5 Sep 2025 12:20:27 +0200 Subject: [PATCH 1/2] Faster ArrayType->hasOffsetValueType() --- src/Type/ArrayType.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 7453ae3315..88a7617901 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -268,8 +268,12 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType public function hasOffsetValueType(Type $offsetType): TrinaryLogic { - $allowedArrayKeys = AllowedArrayKeysTypes::getType(); - $offsetType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + $offsetArrayKeyType = $offsetType->toArrayKey(); + if ($offsetArrayKeyType instanceof ErrorType) { + $allowedArrayKeys = AllowedArrayKeysTypes::getType(); + $offsetArrayKeyType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + } + $offsetType = $offsetArrayKeyType; if ($this->getKeyType()->isSuperTypeOf($offsetType)->no() && ($offsetType->isString()->no() || !$offsetType->isConstantScalarValue()->no()) From dc6e2c09cddf8256d37fb87de5520ab360ae3a14 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 5 Sep 2025 12:24:05 +0200 Subject: [PATCH 2/2] Update ConstantArrayType.php --- src/Type/Constant/ConstantArrayType.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 9418c81fa7..b4e2ed6f36 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -582,8 +582,11 @@ public function findTypeAndMethodNames(): array public function hasOffsetValueType(Type $offsetType): TrinaryLogic { - $allowedArrayKeys = AllowedArrayKeysTypes::getType(); - $offsetArrayKeyType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + $offsetArrayKeyType = $offsetType->toArrayKey(); + if ($offsetArrayKeyType instanceof ErrorType) { + $allowedArrayKeys = AllowedArrayKeysTypes::getType(); + $offsetArrayKeyType = TypeCombinator::intersect($allowedArrayKeys, $offsetType)->toArrayKey(); + } return $this->recursiveHasOffsetValueType($offsetArrayKeyType); }