koel/app/Values/LicenseStatus.php

44 lines
899 B
PHP
Raw Normal View History

2024-01-05 16:42:50 +00:00
<?php
namespace App\Values;
2024-04-18 17:20:14 +00:00
use App\Enums\LicenseStatus as Status;
2024-01-05 16:42:50 +00:00
use App\Models\License;
final class LicenseStatus
{
2024-04-18 17:20:14 +00:00
private function __construct(public Status $status, public ?License $license)
2024-01-05 16:42:50 +00:00
{
}
public function isValid(): bool
{
2024-04-18 17:20:14 +00:00
return $this->status === Status::VALID;
2024-01-05 16:42:50 +00:00
}
2024-01-08 13:02:26 +00:00
public function hasNoLicense(): bool
{
2024-04-18 17:20:14 +00:00
return $this->status === Status::NO_LICENSE;
2024-01-08 13:02:26 +00:00
}
2024-01-05 16:42:50 +00:00
public static function noLicense(): self
{
2024-04-18 17:20:14 +00:00
return new self(Status::NO_LICENSE, null);
2024-01-05 16:42:50 +00:00
}
public static function valid(License $license): self
{
2024-04-18 17:20:14 +00:00
return new self(Status::VALID, $license);
2024-01-05 16:42:50 +00:00
}
public static function invalid(License $license): self
{
2024-04-18 17:20:14 +00:00
return new self(Status::INVALID, $license);
2024-01-05 16:42:50 +00:00
}
public static function unknown(License $license): self
{
2024-04-18 17:20:14 +00:00
return new self(Status::UNKNOWN, $license);
2024-01-05 16:42:50 +00:00
}
}