Lines 100.00% 9 / 9
Methods 100.00% 4 / 4
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 of 100.00% 6 / 6 100.00% 1 / 1 3
 start 100.00% 1 / 1 100.00% 1 / 1 1
 __toString 100.00% 1 / 1 100.00% 1 / 1 1
11final readonly class Rank implements Stringable
12{
13    private const array STARTS = [
14        1 => 0,
15        2 => 900,
16        3 => 3600,
17        4 => 10_000,
18        5 => 22_500,
19        6 => 44_100,
20        7 => 78_400,
21        8 => 129_600,
22        9 => 202_500,
23        10 => 302_500,
24    ];
25
26    /** @var int<1, 10> */
27    public int $value;
28
29    public function __construct(int $value)
30    {
31        $this->value = Type\int_range(min: 1, max: 10)->assert($value);
32    }
33
34    public static function of(GrantsRank $points): self
35    {
36        $rank = 1;
37        foreach (self::STARTS as $candidate => $start) {
38            if ($points->value < $start) {
39                break;
40            }
41
42            $rank = $candidate;
43        }
44
45        return new self($rank);
46    }
47
48    public function start(): int
49    {
50        return self::STARTS[$this->value];
51    }
52
53    public function __toString(): string
54    {
55        return (string) $this->value;
56    }
57}