ICanBoogie /
CLDR
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ICanBoogie\CLDR\Numbers; |
||
| 4 | |||
| 5 | use ICanBoogie\CLDR\Core\Locale; |
||
| 6 | use ICanBoogie\CLDR\Core\Localizable; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Representation of a currency. |
||
| 10 | * |
||
| 11 | * @link https://www.unicode.org/reports/tr35/tr35-72/tr35-numbers.html#Currencies |
||
| 12 | * |
||
| 13 | * @implements Localizable<Currency, CurrencyLocalized> |
||
| 14 | */ |
||
| 15 | final class Currency implements Localizable |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Whether a currency code is defined. |
||
| 19 | * |
||
| 20 | * @param string $code |
||
| 21 | * A currency code; for example, EUR. |
||
| 22 | */ |
||
| 23 | public static function is_defined(string $code): bool |
||
| 24 | { |
||
| 25 | return in_array($code, CurrencyData::CODES); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $code |
||
| 30 | * A currency code; for example, EUR. |
||
| 31 | * |
||
| 32 | * @throws CurrencyNotDefined |
||
| 33 | */ |
||
| 34 | public static function assert_is_defined(string $code): void |
||
| 35 | { |
||
| 36 | self::is_defined($code) |
||
| 37 | or throw new CurrencyNotDefined($code); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Returns a {@see CurrencyCode} of the specified code. |
||
| 42 | * |
||
| 43 | * @param string $code |
||
| 44 | * A currency code; for example, EUR. |
||
| 45 | * |
||
| 46 | * @throws CurrencyNotDefined |
||
| 47 | */ |
||
| 48 | public static function of(string $code): self |
||
| 49 | { |
||
| 50 | static $instances; |
||
| 51 | |||
| 52 | self::assert_is_defined($code); |
||
| 53 | |||
| 54 | return $instances[$code] ??= new self($code, self::fraction_for($code)); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Returns the {@see Fraction} for the specified currency code. |
||
| 59 | * |
||
| 60 | * @param string $code |
||
| 61 | * * A currency code; for example, EUR. |
||
| 62 | */ |
||
| 63 | private static function fraction_for(string $code): Fraction |
||
| 64 | { |
||
| 65 | static $default_fraction; |
||
| 66 | |||
| 67 | $data = CurrencyData::FRACTIONS[$code] ?? null; |
||
| 68 | |||
| 69 | if (!$data) { |
||
| 70 | return $default_fraction ??= self::fraction_for(CurrencyData::FRACTIONS_FALLBACK); |
||
| 71 | } |
||
| 72 | |||
| 73 | return Fraction::from($data); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $code |
||
| 78 | * A currency code; for example, EUR. |
||
| 79 | */ |
||
| 80 | private function __construct( |
||
| 81 | public readonly string $code, |
||
| 82 | public readonly Fraction $fraction, |
||
| 83 | ) { |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Returns the {@see $code} of the currency. |
||
| 88 | */ |
||
| 89 | public function __toString(): string |
||
| 90 | { |
||
| 91 | return $this->code; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function __serialize(): array |
||
| 95 | { |
||
| 96 | return [ 'code' => $this->code ]; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param array{ code: string } $data |
||
|
0 ignored issues
–
show
|
|||
| 101 | */ |
||
| 102 | public function __unserialize(array $data): void |
||
| 103 | { |
||
| 104 | $this->code = $data['code']; |
||
|
0 ignored issues
–
show
|
|||
| 105 | $this->fraction = self::fraction_for($this->code); |
||
|
0 ignored issues
–
show
|
|||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Returns a localized currency. |
||
| 110 | */ |
||
| 111 | public function localized(Locale $locale): CurrencyLocalized |
||
| 112 | { |
||
| 113 | return new CurrencyLocalized($this, $locale); |
||
| 114 | } |
||
| 115 | } |
||
| 116 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths