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
SignedRatio 100.00% 4 / 4 100.00% 2 / 2 3 100.00% 1 / 1
 __construct 100.00% 3 / 3 100.00% 1 / 1 2
 __toString 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Lorekeeper\Core\Support;
6
7use InvalidArgumentException;
8use Stringable;
9
10abstract readonly class SignedRatio implements Stringable
11{
12    public float $value;
13
14    /** @throws InvalidArgumentException */
15    final public function __construct(float $value)
16    {
17        if (!is_finite($value)) {
18            throw new InvalidArgumentException("Ratio {$value} is not a finite number.");
19        }
20
21        $this->value = $value;
22    }
23
24    final public function __toString(): string
25    {
26        return (string) $this->value;
27    }
28}