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

RegionCurrency::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace ICanBoogie\CLDR\Supplemental\Territory;
4
5
final class RegionCurrency
6
{
7
    /**
8
     * @param array<string, array{ _from?: string, _to?: string, _tender?: string }> $data
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
9
     */
10
    public static function from(array $data): self
11
    {
12
        $code = key($data);
13
        $properties = current($data);
14
15
        assert(is_string($code));
16
        assert(is_array($properties));
17
18
        return new self(
19
            code: $code,
20
            from: $properties['_from'] ?? null,
21
            to: $properties['_to'] ?? null,
22
            tender: ($properties['_tender'] ?? null) != 'false',
23
        );
24
    }
25
26
    private function __construct(
27
        public readonly string $code,
28
        public readonly ?string $from,
29
        public readonly ?string $to,
30
        public readonly bool $tender,
31
    ) {
32
    }
33
}
34