Issues (662)

src/Supplemental/Units/Sequence.php (1 issue)

1
<?php
2
3
namespace ICanBoogie\CLDR\Supplemental\Units;
4
5
use ICanBoogie\Accessor\AccessorTrait;
6
7
/**
8
 * Representation of a unit/number sequence.
9
 *
10
 * @internal
11
 *
12
 * @property-read string $as_long Long string representation.
13
 * @property-read string $as_short Short string representation.
14
 * @property-read string $as_narrow Narrow string representation.
15
 *
16
 * @link https://unicode.org/reports/tr35/tr35-general.html#Unit_Sequences
17
 */
18
final class Sequence
19
{
20
    use SequenceCompanion;
21
22
    /**
23
     * @uses get_as_long
24
     * @uses get_as_short
25
     * @uses get_as_narrow
26
     */
27
    use AccessorTrait;
28
29
    /**
30
     * @var array<string, float|int|numeric-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, float|int|numeric-string> at position 8 could not be parsed: Unknown type name 'numeric-string' at position 8 in array<string, float|int|numeric-string>.
Loading history...
31
     */
32
    private array $sequence = [];
33
34
    public function __construct(
35
        private readonly Units $units
36
    ) {
37
    }
38
39
    public function __toString(): string
40
    {
41
        return $this->format();
42
    }
43
44
    private function get_as_long(): string
45
    {
46
        return $this->format(UnitLength::LONG);
47
    }
48
49
    private function get_as_short(): string
50
    {
51
        return $this->format(UnitLength::SHORT);
52
    }
53
54
    private function get_as_narrow(): string
55
    {
56
        return $this->format(UnitLength::NARROW);
57
    }
58
59
    /**
60
     * Formats the sequence.
61
     */
62
    public function format(UnitLength $length = Units::DEFAULT_LENGTH): string
63
    {
64
        return $this->units->format_sequence($this->sequence, $length);
65
    }
66
}
67