Passed
Push — 6.0 ( 4ac4e1...87e1d7 )
by Olivier
01:56
created

NumberPerUnit::get_as_long()   A

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 NumberPerUnit
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 $number_unit,
29
        private readonly string $per_unit,
30
        private readonly Units $units
31
    ) {
32
    }
33
34
    public function __toString(): string
35
    {
36
        return $this->as(Units::DEFAULT_LENGTH);
37
    }
38
39
    private function get_as_long(): string
40
    {
41
        return $this->as(UnitLength::LONG);
42
    }
43
44
    private function get_as_short(): string
45
    {
46
        return $this->as(UnitLength::SHORT);
47
    }
48
49
    private function get_as_narrow(): string
50
    {
51
        return $this->as(UnitLength::NARROW);
52
    }
53
54
    private function as(UnitLength $length): string
55
    {
56
        return $this->units->format_compound(
57
            $this->number,
58
            $this->number_unit,
59
            $this->per_unit,
60
            $length
61
        );
62
    }
63
}
64