Skip to content

Commit 3332d36

Browse files
committed
IsSuperTypeOfResult: cache YES/NO/MAYBE
1 parent cabdea2 commit 3332d36

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Type/IsSuperTypeOfResult.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
*/
3131
final class IsSuperTypeOfResult
3232
{
33+
private static self $YES;
34+
35+
private static self $MAYBE;
36+
37+
private static self $NO;
38+
3339

3440
/**
3541
* @api
@@ -71,18 +77,21 @@ public function no(): bool
7177

7278
public static function createYes(): self
7379
{
74-
return new self(TrinaryLogic::createYes(), []);
80+
return self::$YES ??= new self(TrinaryLogic::createYes(), []);
7581
}
7682

7783
/** @param list<string> $reasons */
7884
public static function createNo(array $reasons = []): self
7985
{
86+
if ($reasons === []) {
87+
return self::$NO ??= new self(TrinaryLogic::createNo(), $reasons);
88+
}
8089
return new self(TrinaryLogic::createNo(), $reasons);
8190
}
8291

8392
public static function createMaybe(): self
8493
{
85-
return new self(TrinaryLogic::createMaybe(), []);
94+
return self::$MAYBE ??= new self(TrinaryLogic::createMaybe(), []);
8695
}
8796

8897
public static function createFromBoolean(bool $value): self

0 commit comments

Comments
 (0)