Lines
100.00%
3 / 3
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| NonNegativeInteger | 100.00% | 3 / 3 | 100.00% | 3 / 3 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| equals | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | |||||
| __toString | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Core\Support; | |
| 6 | ||
| 7 | use Psl\Comparison\Equable; | |
| 8 | use Psl\Type; | |
| 9 | use Stringable; | |
| 10 | ||
| 11 | /** | |
| 12 | * @implements Equable<static> | |
| 13 | */ | |
| 14 | abstract readonly class NonNegativeInteger implements Equable, Stringable | |
| 15 | { | |
| 16 | /** @var non-negative-int */ | |
| 17 | public int $value; | |
| 18 | ||
| 19 | final public function __construct(int $value) | |
| 20 | { | |
| 21 | $this->value = Type\uint()->assert($value); | |
| 22 | } | |
| 23 | ||
| 24 | /** | |
| 25 | * @param static $other | |
| 26 | * | |
| 27 | * @mago-expect analysis:redundant-logical-operation | |
| 28 | */ | |
| 29 | final public function equals(mixed $other): bool | |
| 30 | { | |
| 31 | return $other instanceof static && $other->value === $this->value; | |
| 32 | } | |
| 33 | ||
| 34 | final public function __toString(): string | |
| 35 | { | |
| 36 | return (string) $this->value; | |
| 37 | } | |
| 38 | } |