From 3332d36e4a9fb0ed36a710062da2b72e9d70e453 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 20 Feb 2026 20:24:54 +0100 Subject: [PATCH 1/3] IsSuperTypeOfResult: cache YES/NO/MAYBE --- src/Type/IsSuperTypeOfResult.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Type/IsSuperTypeOfResult.php b/src/Type/IsSuperTypeOfResult.php index 24bdebc5c7d..7c94ab7cf76 100644 --- a/src/Type/IsSuperTypeOfResult.php +++ b/src/Type/IsSuperTypeOfResult.php @@ -30,6 +30,12 @@ */ final class IsSuperTypeOfResult { + private static self $YES; + + private static self $MAYBE; + + private static self $NO; + /** * @api @@ -71,18 +77,21 @@ public function no(): bool public static function createYes(): self { - return new self(TrinaryLogic::createYes(), []); + return self::$YES ??= new self(TrinaryLogic::createYes(), []); } /** @param list $reasons */ public static function createNo(array $reasons = []): self { + if ($reasons === []) { + return self::$NO ??= new self(TrinaryLogic::createNo(), $reasons); + } return new self(TrinaryLogic::createNo(), $reasons); } public static function createMaybe(): self { - return new self(TrinaryLogic::createMaybe(), []); + return self::$MAYBE ??= new self(TrinaryLogic::createMaybe(), []); } public static function createFromBoolean(bool $value): self From d8ca22163a0cb701ac52a42a1adb89acb8fb3a91 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 20 Feb 2026 20:27:45 +0100 Subject: [PATCH 2/3] cs --- src/Type/IsSuperTypeOfResult.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Type/IsSuperTypeOfResult.php b/src/Type/IsSuperTypeOfResult.php index 7c94ab7cf76..bf49491c426 100644 --- a/src/Type/IsSuperTypeOfResult.php +++ b/src/Type/IsSuperTypeOfResult.php @@ -30,13 +30,13 @@ */ final class IsSuperTypeOfResult { + private static self $YES; private static self $MAYBE; private static self $NO; - /** * @api * @param list $reasons Human-readable explanations of the type relationship @@ -84,7 +84,7 @@ public static function createYes(): self public static function createNo(array $reasons = []): self { if ($reasons === []) { - return self::$NO ??= new self(TrinaryLogic::createNo(), $reasons); + return self::$NO ??= new self(TrinaryLogic::createNo(), $reasons); } return new self(TrinaryLogic::createNo(), $reasons); } From 752580942e0bef2876e2d5498e658af8b2b744b2 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 20 Feb 2026 20:40:24 +0100 Subject: [PATCH 3/3] cache createFromBoolean() --- src/Type/IsSuperTypeOfResult.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Type/IsSuperTypeOfResult.php b/src/Type/IsSuperTypeOfResult.php index bf49491c426..2ce7d21e2d9 100644 --- a/src/Type/IsSuperTypeOfResult.php +++ b/src/Type/IsSuperTypeOfResult.php @@ -96,7 +96,10 @@ public static function createMaybe(): self public static function createFromBoolean(bool $value): self { - return new self(TrinaryLogic::createFromBoolean($value), []); + if ($value === true) { + return self::createYes(); + } + return self::createNo(); } public function toAcceptsResult(): AcceptsResult