| Total Complexity | 7 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | final class NumberWithUnit |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @uses get_as_long |
||
| 18 | * @uses get_as_short |
||
| 19 | * @uses get_as_narrow |
||
| 20 | */ |
||
| 21 | use AccessorTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param float|int|numeric-string $number |
||
|
|
|||
| 25 | */ |
||
| 26 | public function __construct( |
||
| 27 | private readonly float|int|string $number, |
||
| 28 | private readonly string $unit, |
||
| 29 | private readonly Units $units |
||
| 30 | ) { |
||
| 31 | } |
||
| 32 | |||
| 33 | public function __toString(): string |
||
| 34 | { |
||
| 35 | return $this->as(Units::DEFAULT_LENGTH); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function per(Unit|string $unit): NumberPerUnit |
||
| 39 | { |
||
| 40 | return new NumberPerUnit($this->number, $this->unit, $unit, $this->units); |
||
| 41 | } |
||
| 42 | |||
| 43 | private function get_as_long(): string |
||
| 44 | { |
||
| 45 | return $this->as(UnitLength::LONG); |
||
| 46 | } |
||
| 47 | |||
| 48 | private function get_as_short(): string |
||
| 51 | } |
||
| 52 | |||
| 53 | private function get_as_narrow(): string |
||
| 56 | } |
||
| 57 | |||
| 58 | private function as(UnitLength $length): string |
||
| 61 | } |
||
| 62 | } |
||
| 63 |