Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Type/IsSuperTypeOfResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
final class IsSuperTypeOfResult
{

private static self $YES;

private static self $MAYBE;

private static self $NO;

/**
* @api
* @param list<string> $reasons Human-readable explanations of the type relationship
Expand Down Expand Up @@ -71,23 +77,29 @@ public function no(): bool

public static function createYes(): self
{
return new self(TrinaryLogic::createYes(), []);
return self::$YES ??= new self(TrinaryLogic::createYes(), []);
}

/** @param list<string> $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
{
return new self(TrinaryLogic::createFromBoolean($value), []);
if ($value === true) {
return self::createYes();
}
return self::createNo();
}

public function toAcceptsResult(): AcceptsResult
Expand Down
Loading