42 lines
878 B
PHP
42 lines
878 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Shared\ValueObjects\Config;
|
||
|
|
|
||
|
|
use Shared\DDD\Model\Equatable;
|
||
|
|
|
||
|
|
final readonly class RequestsPerMinute implements \Stringable, Equatable
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
public int $value,
|
||
|
|
) {
|
||
|
|
if ($this->value < 1) {
|
||
|
|
throw new \InvalidArgumentException(sprintf('Requests per minute must be at least 1, got %d.', $this->value));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toInt(): int
|
||
|
|
{
|
||
|
|
return $this->value;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isGreaterThan(self $other): bool
|
||
|
|
{
|
||
|
|
return $this->value > $other->value;
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
public function __toString(): string
|
||
|
|
{
|
||
|
|
return (string) $this->value;
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
public function equals(mixed $other): bool
|
||
|
|
{
|
||
|
|
return $other instanceof self
|
||
|
|
&& $this->value === $other->value;
|
||
|
|
}
|
||
|
|
}
|