Lines
100.00%
4 / 4
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | ||
| __toString | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 10 | final readonly class DropRate implements Stringable | |
| 11 | { | |
| 12 | public float $percentage; | |
| 13 | ||
| 14 | public function __construct(float $percentage) | |
| 15 | { | |
| 16 | if ($percentage < 0.0 || $percentage > 100.0) { | |
| 17 | throw new InvalidArgumentException("Drop rate must be between 0 and 100, got '{$percentage}'."); | |
| 18 | } | |
| 19 | ||
| 20 | $this->percentage = $percentage; | |
| 21 | } | |
| 22 | ||
| 23 | public function __toString(): string | |
| 24 | { | |
| 25 | return "{$this->percentage}%"; | |
| 26 | } | |
| 27 | } |