File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 3131final 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
You can’t perform that action at this time.
0 commit comments