Fraction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A from() 0 10 1
1
<?php
2
3
namespace ICanBoogie\CLDR\Numbers;
4
5
/**
6
 * @internal
7
 *
8
 * @link https://www.unicode.org/reports/tr35/tr35-72/tr35-numbers.html#Supplemental_Currency_Data
9
 */
10
final class Fraction
11
{
12
    /**
13
     * @param array{ _digits?: string, _rounding?: string, _cashDigits?: string, _cashRounding?: string } $data
0 ignored issues
show
Documentation Bug introduced by
The doc comment _digits?: string, _round... _cashRounding?: string at position 0 could not be parsed: Unknown type name '_digits?' at position 0 in _digits?: string, _rounding?: string, _cashDigits?: string, _cashRounding?: string.
Loading history...
14
     */
15
    public static function from(array $data): self
16
    {
17
        $digits = (int)($data['_digits'] ?? 2);
18
        $rounding = (int)($data['_rounding'] ?? 0);
19
20
        return new self(
21
            $digits,
22
            $rounding,
23
            (int)($data['_cashDigits'] ?? $digits),
24
            (int)($data['_cashRounding'] ?? $rounding)
25
        );
26
    }
27
28
    /**
29
     * @param int $digits
30
     *     The minimum and maximum number of decimal digits normally formatted.
31
     * @param int $rounding
32
     *     The rounding increment, in units of 10^-digits.
33
     * @param int $cash_digits
34
     *     The number of decimal digits to be used when formatting quantities used in cash transactions.
35
     * @param int $cash_rounding
36
     *     The cash rounding increment, in units of 10^cashDigits.
37
     */
38
    private function __construct(
39
        public readonly int $digits,
40
        public readonly int $rounding,
41
        public readonly int $cash_digits,
42
        public readonly int $cash_rounding
43
    ) {
44
    }
45
}
46