NumberWithUnit::get_as_narrow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ICanBoogie\CLDR\Supplemental\Units;
4
5
use ICanBoogie\Accessor\AccessorTrait;
6
7
/**
8
 * @internal
9
 *
10
 * @property-read string $as_long A long format of the number.
11
 * @property-read string $as_short A short format of the number.
12
 * @property-read string $as_narrow A narrow format of the number.
13
 */
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
0 ignored issues
show
Documentation Bug introduced by
The doc comment float|int|numeric-string at position 4 could not be parsed: Unknown type name 'numeric-string' at position 4 in float|int|numeric-string.
Loading history...
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
49
    {
50
        return $this->as(UnitLength::SHORT);
51
    }
52
53
    private function get_as_narrow(): string
54
    {
55
        return $this->as(UnitLength::NARROW);
56
    }
57
58
    private function as(UnitLength $length): string
59
    {
60
        return $this->units->format($this->number, $this->unit, $length);
61
    }
62
}
63