Skip to content

Commit 5a5255e

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents 0807b1b + 29af0ba commit 5a5255e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Type/IsSuperTypeOfResult.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
final class IsSuperTypeOfResult
3232
{
3333

34+
private static self $YES;
35+
36+
private static self $MAYBE;
37+
38+
private static self $NO;
39+
3440
/**
3541
* @api
3642
* @param list<string> $reasons Human-readable explanations of the type relationship
@@ -71,23 +77,29 @@ 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
8998
{
90-
return new self(TrinaryLogic::createFromBoolean($value), []);
99+
if ($value === true) {
100+
return self::createYes();
101+
}
102+
return self::createNo();
91103
}
92104

93105
public function toAcceptsResult(): AcceptsResult

0 commit comments

Comments
 (0)