Lines 100.00% 4 / 4
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
DropRate 100.00% 4 / 4 100.00% 2 / 2 4 100.00% 1 / 1
 __construct 100.00% 3 / 3 100.00% 1 / 1 3
 __toString 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Lorekeeper\Core\World\Quest\Reward;
6
7use InvalidArgumentException;
8use Stringable;
9
10final 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}