From 4ee9651ef9653f304e994b804dc5d1e17dc6d3b5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Feb 2026 12:18:07 +0100 Subject: [PATCH 1/3] Faster IsSuperTypeOfResult creation --- src/Type/Accessory/AccessoryArrayListType.php | 6 ++++-- src/Type/Accessory/AccessoryLiteralStringType.php | 6 ++++-- src/Type/Accessory/AccessoryLowercaseStringType.php | 6 ++++-- src/Type/Accessory/AccessoryNonEmptyStringType.php | 6 ++++-- src/Type/Accessory/AccessoryNonFalsyStringType.php | 6 ++++-- src/Type/Accessory/AccessoryNumericStringType.php | 6 ++++-- src/Type/Accessory/AccessoryUppercaseStringType.php | 6 ++++-- src/Type/Accessory/HasMethodType.php | 6 +++--- src/Type/Accessory/HasOffsetType.php | 8 ++++---- src/Type/Accessory/HasOffsetValueType.php | 10 +++++++--- src/Type/Accessory/HasPropertyType.php | 10 +++++----- src/Type/Accessory/NonEmptyArrayType.php | 6 ++++-- src/Type/Accessory/OversizedArrayType.php | 6 ++++-- 13 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/Type/Accessory/AccessoryArrayListType.php b/src/Type/Accessory/AccessoryArrayListType.php index d6624108f2..ff3536f473 100644 --- a/src/Type/Accessory/AccessoryArrayListType.php +++ b/src/Type/Accessory/AccessoryArrayListType.php @@ -110,8 +110,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isList()), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isArray()->and($otherType->isList())->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/AccessoryLiteralStringType.php b/src/Type/Accessory/AccessoryLiteralStringType.php index abf0b2cbc4..da1abf5e37 100644 --- a/src/Type/Accessory/AccessoryLiteralStringType.php +++ b/src/Type/Accessory/AccessoryLiteralStringType.php @@ -106,8 +106,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isLiteralString(), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isLiteralString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/AccessoryLowercaseStringType.php b/src/Type/Accessory/AccessoryLowercaseStringType.php index 13ce997f52..2e5ca83146 100644 --- a/src/Type/Accessory/AccessoryLowercaseStringType.php +++ b/src/Type/Accessory/AccessoryLowercaseStringType.php @@ -103,8 +103,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isLowercaseString(), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isLowercaseString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/AccessoryNonEmptyStringType.php b/src/Type/Accessory/AccessoryNonEmptyStringType.php index a635ea8618..2499084ba4 100644 --- a/src/Type/Accessory/AccessoryNonEmptyStringType.php +++ b/src/Type/Accessory/AccessoryNonEmptyStringType.php @@ -108,8 +108,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isNonEmptyString(), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isNonEmptyString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/AccessoryNonFalsyStringType.php b/src/Type/Accessory/AccessoryNonFalsyStringType.php index dc5548789a..9f2eebdbd2 100644 --- a/src/Type/Accessory/AccessoryNonFalsyStringType.php +++ b/src/Type/Accessory/AccessoryNonFalsyStringType.php @@ -110,8 +110,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return IsSuperTypeOfResult::createYes(); } - return (new IsSuperTypeOfResult($otherType->isNonFalsyString(), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isNonFalsyString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/AccessoryNumericStringType.php b/src/Type/Accessory/AccessoryNumericStringType.php index 625c82675d..bece8e04ec 100644 --- a/src/Type/Accessory/AccessoryNumericStringType.php +++ b/src/Type/Accessory/AccessoryNumericStringType.php @@ -103,8 +103,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isNumericString(), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isNumericString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/AccessoryUppercaseStringType.php b/src/Type/Accessory/AccessoryUppercaseStringType.php index f4f63666fe..a85c74745b 100644 --- a/src/Type/Accessory/AccessoryUppercaseStringType.php +++ b/src/Type/Accessory/AccessoryUppercaseStringType.php @@ -103,8 +103,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isUppercaseString(), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isUppercaseString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/HasMethodType.php b/src/Type/Accessory/HasMethodType.php index 15ed3561b1..2201e0e5be 100644 --- a/src/Type/Accessory/HasMethodType.php +++ b/src/Type/Accessory/HasMethodType.php @@ -100,12 +100,12 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult } if ($otherType instanceof self) { - $limit = IsSuperTypeOfResult::createYes(); + $limit = TrinaryLogic::createYes(); } else { - $limit = IsSuperTypeOfResult::createMaybe(); + $limit = TrinaryLogic::createMaybe(); } - return $limit->and(new IsSuperTypeOfResult($otherType->hasMethod($this->methodName), [])); + return new IsSuperTypeOfResult($limit->and($otherType->hasMethod($this->methodName)), []); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/HasOffsetType.php b/src/Type/Accessory/HasOffsetType.php index 004c4b8cb8..b6757fefb6 100644 --- a/src/Type/Accessory/HasOffsetType.php +++ b/src/Type/Accessory/HasOffsetType.php @@ -101,10 +101,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - $result = new IsSuperTypeOfResult($otherType->isOffsetAccessible()->and($otherType->hasOffsetValueType($this->offsetType)), []); - - return $result - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isOffsetAccessible()->and($otherType->hasOffsetValueType($this->offsetType))->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/HasOffsetValueType.php b/src/Type/Accessory/HasOffsetValueType.php index 60a4478a06..e3b06be521 100644 --- a/src/Type/Accessory/HasOffsetValueType.php +++ b/src/Type/Accessory/HasOffsetValueType.php @@ -116,11 +116,15 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - $result = new IsSuperTypeOfResult($otherType->isOffsetAccessible()->and($otherType->hasOffsetValueType($this->offsetType)), []); + $result = new IsSuperTypeOfResult( + $otherType->isOffsetAccessible() + ->and($otherType->hasOffsetValueType($this->offsetType)) + ->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); return $result - ->and($otherType->getOffsetValueType($this->offsetType)->isSuperTypeOf($this->valueType)) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + ->and($otherType->getOffsetValueType($this->offsetType)->isSuperTypeOf($this->valueType)); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/HasPropertyType.php b/src/Type/Accessory/HasPropertyType.php index de88c702d7..9c471e44cd 100644 --- a/src/Type/Accessory/HasPropertyType.php +++ b/src/Type/Accessory/HasPropertyType.php @@ -92,15 +92,15 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult } if ($otherType instanceof self) { - $limit = IsSuperTypeOfResult::createYes(); + $limit = TrinaryLogic::createYes(); } else { - $limit = IsSuperTypeOfResult::createMaybe(); + $limit = TrinaryLogic::createMaybe(); } - return $limit->and(new IsSuperTypeOfResult( - $otherType->hasInstanceProperty($this->propertyName)->or($otherType->hasStaticProperty($this->propertyName)), + return new IsSuperTypeOfResult( + $limit->and($otherType->hasInstanceProperty($this->propertyName)->or($otherType->hasStaticProperty($this->propertyName))), [], - )); + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/NonEmptyArrayType.php b/src/Type/Accessory/NonEmptyArrayType.php index d06699b90d..688da67695 100644 --- a/src/Type/Accessory/NonEmptyArrayType.php +++ b/src/Type/Accessory/NonEmptyArrayType.php @@ -110,8 +110,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isIterableAtLeastOnce()), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isArray()->and($otherType->isIterableAtLeastOnce())->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult diff --git a/src/Type/Accessory/OversizedArrayType.php b/src/Type/Accessory/OversizedArrayType.php index d624455997..4956e87992 100644 --- a/src/Type/Accessory/OversizedArrayType.php +++ b/src/Type/Accessory/OversizedArrayType.php @@ -98,8 +98,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isOversizedArray()), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isArray()->and($otherType->isOversizedArray())->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [], + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult From 83a62980801cb547d14578b209314c2f20843825 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Feb 2026 12:24:14 +0100 Subject: [PATCH 2/3] Update CallableType.php --- src/Type/CallableType.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Type/CallableType.php b/src/Type/CallableType.php index 6e2c98b88c..bf7fb57aa8 100644 --- a/src/Type/CallableType.php +++ b/src/Type/CallableType.php @@ -204,8 +204,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOf($this); } - return (new IsSuperTypeOfResult($otherType->isCallable(), [])) - ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); + return new IsSuperTypeOfResult( + $otherType->isCallable()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), + [] + ); } public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult From eb719d42d57bb4bdc47a3e1282dc2e0f65f43444 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Feb 2026 13:53:43 +0100 Subject: [PATCH 3/3] Update CallableType.php --- src/Type/CallableType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/CallableType.php b/src/Type/CallableType.php index bf7fb57aa8..9d9cfb65e4 100644 --- a/src/Type/CallableType.php +++ b/src/Type/CallableType.php @@ -206,7 +206,7 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult return new IsSuperTypeOfResult( $otherType->isCallable()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()), - [] + [], ); }