Passed
Push — 6.0 ( 4cc368...44c261 )
by Olivier
01:44
created

TerritoryCode   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 372
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 306
dl 0
loc 372
rs 10
c 0
b 0
f 0
wmc 8
1
<?php
2
3
/**
4
 * CODE GENERATED; DO NOT EDIT.
5
 *
6
 * {@see \ICanBoogie\CLDR\Generator\Command\GenerateTerritoryCode}
7
 */
8
9
namespace ICanBoogie\CLDR;
10
11
/**
12
 * A territory code.
13
 */
14
final class TerritoryCode
15
{
16
    /**
17
     * @link https://github.com/unicode-org/cldr-json/blob/45.0.0/cldr-json/cldr-localenames-full/main/en-001/territories.json
18
     */
19
    public const CODES =
20
        [
21
            '001',
22
            '002',
23
            '003',
24
            '005',
25
            '009',
26
            '011',
27
            '013',
28
            '014',
29
            '015',
30
            '017',
31
            '018',
32
            '019',
33
            '021',
34
            '029',
35
            '030',
36
            '034',
37
            '035',
38
            '039',
39
            '053',
40
            '054',
41
            '057',
42
            '061',
43
            142,
44
            143,
45
            145,
46
            150,
47
            151,
48
            154,
49
            155,
50
            202,
51
            419,
52
            'AC',
53
            'AD',
54
            'AE',
55
            'AF',
56
            'AG',
57
            'AI',
58
            'AL',
59
            'AM',
60
            'AO',
61
            'AQ',
62
            'AR',
63
            'AS',
64
            'AT',
65
            'AU',
66
            'AW',
67
            'AX',
68
            'AZ',
69
            'BA',
70
            'BB',
71
            'BD',
72
            'BE',
73
            'BF',
74
            'BG',
75
            'BH',
76
            'BI',
77
            'BJ',
78
            'BL',
79
            'BM',
80
            'BN',
81
            'BO',
82
            'BQ',
83
            'BR',
84
            'BS',
85
            'BT',
86
            'BV',
87
            'BW',
88
            'BY',
89
            'BZ',
90
            'CA',
91
            'CC',
92
            'CD',
93
            'CF',
94
            'CG',
95
            'CH',
96
            'CI',
97
            'CK',
98
            'CL',
99
            'CM',
100
            'CN',
101
            'CO',
102
            'CP',
103
            'CQ',
104
            'CR',
105
            'CU',
106
            'CV',
107
            'CW',
108
            'CX',
109
            'CY',
110
            'CZ',
111
            'DE',
112
            'DG',
113
            'DJ',
114
            'DK',
115
            'DM',
116
            'DO',
117
            'DZ',
118
            'EA',
119
            'EC',
120
            'EE',
121
            'EG',
122
            'EH',
123
            'ER',
124
            'ES',
125
            'ET',
126
            'EU',
127
            'EZ',
128
            'FI',
129
            'FJ',
130
            'FK',
131
            'FM',
132
            'FO',
133
            'FR',
134
            'GA',
135
            'GB',
136
            'GD',
137
            'GE',
138
            'GF',
139
            'GG',
140
            'GH',
141
            'GI',
142
            'GL',
143
            'GM',
144
            'GN',
145
            'GP',
146
            'GQ',
147
            'GR',
148
            'GS',
149
            'GT',
150
            'GU',
151
            'GW',
152
            'GY',
153
            'HK',
154
            'HM',
155
            'HN',
156
            'HR',
157
            'HT',
158
            'HU',
159
            'IC',
160
            'ID',
161
            'IE',
162
            'IL',
163
            'IM',
164
            'IN',
165
            'IO',
166
            'IQ',
167
            'IR',
168
            'IS',
169
            'IT',
170
            'JE',
171
            'JM',
172
            'JO',
173
            'JP',
174
            'KE',
175
            'KG',
176
            'KH',
177
            'KI',
178
            'KM',
179
            'KN',
180
            'KP',
181
            'KR',
182
            'KW',
183
            'KY',
184
            'KZ',
185
            'LA',
186
            'LB',
187
            'LC',
188
            'LI',
189
            'LK',
190
            'LR',
191
            'LS',
192
            'LT',
193
            'LU',
194
            'LV',
195
            'LY',
196
            'MA',
197
            'MC',
198
            'MD',
199
            'ME',
200
            'MF',
201
            'MG',
202
            'MH',
203
            'MK',
204
            'ML',
205
            'MM',
206
            'MN',
207
            'MO',
208
            'MP',
209
            'MQ',
210
            'MR',
211
            'MS',
212
            'MT',
213
            'MU',
214
            'MV',
215
            'MW',
216
            'MX',
217
            'MY',
218
            'MZ',
219
            'NA',
220
            'NC',
221
            'NE',
222
            'NF',
223
            'NG',
224
            'NI',
225
            'NL',
226
            'NO',
227
            'NP',
228
            'NR',
229
            'NU',
230
            'NZ',
231
            'OM',
232
            'PA',
233
            'PE',
234
            'PF',
235
            'PG',
236
            'PH',
237
            'PK',
238
            'PL',
239
            'PM',
240
            'PN',
241
            'PR',
242
            'PS',
243
            'PT',
244
            'PW',
245
            'PY',
246
            'QA',
247
            'QO',
248
            'RE',
249
            'RO',
250
            'RS',
251
            'RU',
252
            'RW',
253
            'SA',
254
            'SB',
255
            'SC',
256
            'SD',
257
            'SE',
258
            'SG',
259
            'SH',
260
            'SI',
261
            'SJ',
262
            'SK',
263
            'SL',
264
            'SM',
265
            'SN',
266
            'SO',
267
            'SR',
268
            'SS',
269
            'ST',
270
            'SV',
271
            'SX',
272
            'SY',
273
            'SZ',
274
            'TA',
275
            'TC',
276
            'TD',
277
            'TF',
278
            'TG',
279
            'TH',
280
            'TJ',
281
            'TK',
282
            'TL',
283
            'TM',
284
            'TN',
285
            'TO',
286
            'TR',
287
            'TT',
288
            'TV',
289
            'TW',
290
            'TZ',
291
            'UA',
292
            'UG',
293
            'UM',
294
            'UN',
295
            'US',
296
            'UY',
297
            'UZ',
298
            'VA',
299
            'VC',
300
            'VE',
301
            'VG',
302
            'VI',
303
            'VN',
304
            'VU',
305
            'WF',
306
            'WS',
307
            'XA',
308
            'XB',
309
            'XK',
310
            'YE',
311
            'YT',
312
            'ZA',
313
            'ZM',
314
            'ZW',
315
            'ZZ',
316
        ];
317
318
    /**
319
     * Whether a currency code is defined.
320
     *
321
     * @param string $code
322
     *     A currency code; for example, EUR.
323
     */
324
    public static function is_defined(string $code): bool
325
    {
326
        return in_array($code, self::CODES);
327
    }
328
329
    /**
330
     * @param string $code
331
     *     A currency code; for example, EUR.
332
     *
333
     * @throws TerritoryNotDefined
334
     */
335
    public static function assert_is_defined(string $code): void
336
    {
337
        self::is_defined($code)
338
            or throw new TerritoryNotDefined($code);
339
    }
340
341
    /**
342
     * Returns a {@see CurrencyCode} of the specified code.
343
     *
344
     * @param string $code
345
     *     A currency code; for example, EUR.
346
     *
347
     * @throws TerritoryNotDefined
348
     */
349
    public static function of(string $code): self
350
    {
351
        static $instances;
352
353
        self::assert_is_defined($code);
354
355
        return $instances[$code] ??= new self($code);
356
    }
357
358
    /**
359
     * @param string $value
360
     *     A territory value; for example, CA.
361
    */
362
    private function __construct(
363
        public readonly string $value,
364
    ) {
365
    }
366
367
    /**
368
     * Returns the {@see $value} of the currency.
369
     */
370
    public function __toString(): string
371
    {
372
        return $this->value;
373
    }
374
375
    public function __serialize(): array
376
    {
377
        return [ 'value' => $this->value ];
378
    }
379
380
    /**
381
     * @param array{ value: string } $data
382
     */
383
    public function __unserialize(array $data): void
384
    {
385
        $this->value = $data['value'];
386
    }
387
}
388