Lines 100.00% 4 / 4
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Gauge 100.00% 4 / 4 100.00% 3 / 3 4 100.00% 1 / 1
 __construct 100.00% 2 / 2 100.00% 1 / 1 2
 empty 100.00% 1 / 1 100.00% 1 / 1 1
 full 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Lorekeeper\Core\Support;
6
7use InvalidArgumentException;
8
9/**
10 * @template T of NonNegativeInteger
11 */
12final readonly class Gauge
13{
14    /**
15     * @param T $current
16     * @param T $maximum
17     *
18     * @throws InvalidArgumentException
19     */
20    public function __construct(
21        public NonNegativeInteger $current,
22        public NonNegativeInteger $maximum,
23    ) {
24        if ($current->value > $maximum->value) {
25            throw new InvalidArgumentException("Gauge current {$current} is above maximum {$maximum}.");
26        }
27    }
28
29    public function empty(): bool
30    {
31        return $this->current->value === 0;
32    }
33
34    public function full(): bool
35    {
36        return $this->current->value === $this->maximum->value;
37    }
38}