TerritoryCode::__serialize()   A
last analyzed

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\Territory;
4
5
/**
6
 * A territory code.
7
 */
8
final class TerritoryCode
9
{
10
    /**
11
     * Whether a currency code is defined.
12
     *
13
     * @param string $code
14
     *     A currency code; for example, EUR.
15
     */
16
    public static function is_defined(string $code): bool
17
    {
18
        return in_array($code, TerritoryData::CODES);
19
    }
20
21
    /**
22
     * @param string $code
23
     *     A currency code; for example, EUR.
24
     *
25
     * @throws TerritoryNotDefined
26
     */
27
    public static function assert_is_defined(string $code): void
28
    {
29
        self::is_defined($code)
30
            or throw new TerritoryNotDefined($code);
31
    }
32
33
    /**
34
     * Returns a {@see TerritoryCode} of the specified code.
35
     *
36
     * @param string $code
37
     *     A currency code; for example, EUR.
38
     *
39
     * @throws TerritoryNotDefined
40
     */
41
    public static function of(string $code): self
42
    {
43
        static $instances;
44
45
        self::assert_is_defined($code);
46
47
        return $instances[$code] ??= new self($code);
48
    }
49
50
    /**
51
     * @param string $value
52
     *     A territory code; for example, CA.
53
    */
54
    private function __construct(
55
        public readonly string $value,
56
    ) {
57
    }
58
59
    /**
60
     * Returns the {@see $value} of the currency.
61
     */
62
    public function __toString(): string
63
    {
64
        return $this->value;
65
    }
66
67
    public function __serialize(): array
68
    {
69
        return [ 'value' => $this->value ];
70
    }
71
72
    /**
73
     * @param array{ value: string } $data
0 ignored issues
show
Bug introduced by
The type ICanBoogie\CLDR\Supplemental\Territory\value was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
74
     */
75
    public function __unserialize(array $data): void
76
    {
77
        $this->value = $data['value'];
0 ignored issues
show
Bug introduced by
The property value is declared read-only in ICanBoogie\CLDR\Suppleme...Territory\TerritoryCode.
Loading history...
78
    }
79
}
80