Passed
Push — master ( 596ccb...28a195 )
by Esteban De La Fuente
06:18
created

Moneda   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 448
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 143
c 2
b 0
f 0
dl 0
loc 448
ccs 0
cts 10
cp 0
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSimbolo() 0 3 1
A getSeparadorDecimal() 0 3 1
A getGlosa() 0 3 1
A getSeparadorMiles() 0 3 1
A getDecimales() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * LibreDTE: Biblioteca PHP (Núcleo).
7
 * Copyright (C) LibreDTE <https://www.libredte.cl>
8
 *
9
 * Este programa es software libre: usted puede redistribuirlo y/o modificarlo
10
 * bajo los términos de la Licencia Pública General Affero de GNU publicada por
11
 * la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o
12
 * (a su elección) cualquier versión posterior de la misma.
13
 *
14
 * Este programa se distribuye con la esperanza de que sea útil, pero SIN
15
 * GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD
16
 * PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública
17
 * General Affero de GNU para obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la Licencia Pública General Affero de
20
 * GNU junto a este programa.
21
 *
22
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
23
 */
24
25
namespace libredte\lib\Core\Package\Billing\Component\Document\Enum;
26
27
/**
28
 * Enum con las monedas reconocidas en la aplicación.
29
 */
30
enum Moneda: string
31
{
32
    /**
33
     * Pesos chilenos.
34
     */
35
    case CLP = 'CLP';
36
37
    /**
38
     * Unidad de Fomento de Chile (UF).
39
     */
40
    case CLF = 'CLF';
41
42
    /**
43
     * Unidad Tributaria Mensual de Chile.
44
     */
45
    case UTM = 'UTM';
46
47
    /**
48
     * Unidad Tributaria Anual de Chile.
49
     */
50
    case UTA = 'UTA';
51
52
    /**
53
     * Dólar de Estados Unidos.
54
     */
55
    case USD = 'USD';
56
57
    /**
58
     * Euro.
59
     */
60
    case EUR = 'EUR';
61
62
    /**
63
     * I love Bitcoin <3
64
     */
65
    case BTC = 'BTC';
66
67
    /**
68
     * Peso argentino.
69
     */
70
    case ARS = 'ARS';
71
72
    /**
73
     * Libra esterlina.
74
     */
75
    case GBP = 'GBP';
76
77
    /**
78
     * Corona sueca.
79
     */
80
    case SEK = 'SEK';
81
82
    /**
83
     * Dólar de Hong Kong.
84
     */
85
    case HKD = 'HKD';
86
87
    /**
88
     * Rand sudafricano.
89
     */
90
    case ZAR = 'ZAR';
91
92
    /**
93
     * Peso colombiano.
94
     */
95
    case COP = 'COP';
96
97
    /**
98
     * Peso mexicano.
99
     */
100
    case MXN = 'MXN';
101
102
    /**
103
     * Bolívar venezolano.
104
     */
105
    case VES = 'VES';
106
107
    /**
108
     * Dólar de Singapur.
109
     */
110
    case SGD = 'SGD';
111
112
    /**
113
     * Rupia india.
114
     */
115
    case INR = 'INR';
116
117
    /**
118
     * Nuevo dólar taiwanés.
119
     */
120
    case TWD = 'TWD';
121
122
    /**
123
     * Dirham de Emiratos Árabes Unidos.
124
     */
125
    case AED = 'AED';
126
127
    /**
128
     * Won surcoreano.
129
     */
130
    case KRW = 'KRW';
131
132
    /**
133
     * Zloty polaco.
134
     */
135
    case PLN = 'PLN';
136
137
    /**
138
     * Corona checa.
139
     */
140
    case CZK = 'CZK';
141
142
    /**
143
     * Forint húngaro.
144
     */
145
    case HUF = 'HUF';
146
147
    /**
148
     * Baht tailandés.
149
     */
150
    case THB = 'THB';
151
152
    /**
153
     * Lira turca.
154
     */
155
    case TRY = 'TRY';
156
157
    /**
158
     * Ringgit malayo.
159
     */
160
    case MYR = 'MYR';
161
162
    /**
163
     * Rublo ruso.
164
     */
165
    case RUB = 'RUB';
166
167
    /**
168
     * Rupia indonesia.
169
     */
170
    case IDR = 'IDR';
171
172
    /**
173
     * Grivna ucraniana.
174
     */
175
    case UAH = 'UAH';
176
177
    /**
178
     * Shekel israelí.
179
     */
180
    case ILS = 'ILS';
181
182
    /**
183
     * Peso filipino.
184
     */
185
    case PHP = 'PHP';
186
187
    /**
188
     * Riyal saudí.
189
     */
190
    case SAR = 'SAR';
191
192
    /**
193
     * Rupia pakistaní.
194
     */
195
    case PKR = 'PKR';
196
197
    /**
198
     * Dong vietnamita.
199
     */
200
    case VND = 'VND';
201
202
    /**
203
     * Libra egipcia.
204
     */
205
    case EGP = 'EGP';
206
207
    /**
208
     * Leu rumano.
209
     */
210
    case RON = 'RON';
211
212
    /**
213
     * Corona islandesa.
214
     */
215
    case ISK = 'ISK';
216
217
    /**
218
     * Rial iraní.
219
     */
220
    case IRR = 'IRR';
221
222
    /**
223
     * Colón costarricense.
224
     */
225
    case CRC = 'CRC';
226
227
    /**
228
     * Balboa panameño.
229
     */
230
    case PAB = 'PAB';
231
232
    /**
233
     * Guaraní paraguayo.
234
     */
235
    case PYG = 'PYG';
236
237
    /**
238
     * Sol peruano.
239
     */
240
    case PEN = 'PEN';
241
242
    /**
243
     * Peso uruguayo.
244
     */
245
    case UYU = 'UYU';
246
247
    /**
248
     * Dólar australiano.
249
     */
250
    case AUD = 'AUD';
251
252
    /**
253
     * Boliviano.
254
     */
255
    case BOB = 'BOB';
256
257
    /**
258
     * Yuan chino.
259
     */
260
    case CNY = 'CNY';
261
262
    /**
263
     * Real brasileño.
264
     */
265
    case BRL = 'BRL';
266
267
    /**
268
     * Corona danesa.
269
     */
270
    case DKK = 'DKK';
271
272
    /**
273
     * Dólar canadiense.
274
     */
275
    case CAD = 'CAD';
276
277
    /**
278
     * Yen japonés.
279
     */
280
    case JPY = 'JPY';
281
282
    /**
283
     * Franco suizo.
284
     */
285
    case CHF = 'CHF';
286
287
    /**
288
     * Corona noruega.
289
     */
290
    case NOK = 'NOK';
291
292
    /**
293
     * Dólar neozelandés.
294
     */
295
    case NZD = 'NZD';
296
297
    /**
298
     * Monedas no especificadas.
299
     *
300
     * En estricto rigor ISO 4217 define XXX como "Sin divisa".
301
     */
302
    case XXX = 'XXX';
303
304
    /**
305
     * Glosas para las monedas.
306
     *
307
     * Si una glosa no está definida se entregará $name.
308
     *
309
     * @var array<string, string>
310
     */
311
    private const GLOSAS = [
312
        self::CLP->value => 'Peso chileno',
313
        self::CLF->value => 'Unidad de fomento de Chile',
314
        self::UTM->value => 'Unidad tributaria mensual de Chile',
315
        self::UTA->value => 'Unidad tributaria anual de Chile',
316
        self::USD->value => 'Dólar estadounidense',
317
        self::EUR->value => 'Euro',
318
        self::BTC->value => 'Bitcoin',
319
    ];
320
321
    /**
322
     * Cantidad de decimales que cada moneda puede tener.
323
     *
324
     * Si un decimal no está definido se entregará "2" por defecto.
325
     *
326
     * @var array<string, int>
327
     */
328
    private const DECIMALES = [
329
        self::CLP->value => 0,
330
        self::UTM->value => 0,
331
        self::UTA->value => 0,
332
        self::BTC->value => 8,
333
        self::KRW->value => 0,
334
        self::VND->value => 0,
335
        self::ISK->value => 0,
336
        self::PYG->value => 0,
337
        self::JPY->value => 0,
338
    ];
339
340
    /**
341
     * Símbolos de las monedas reconocidas.
342
     *
343
     * @var array<string, string>
344
     */
345
    private const SIMBOLOS = [
346
        self::CLP->value => '$',
347
        self::CLF->value => 'UF',
348
        self::UTM->value => 'UTM',
349
        self::UTA->value => 'UTA',
350
        self::USD->value => '$',
351
        self::EUR->value => '€',
352
        self::BTC->value => '₿',
353
        self::ARS->value => '$',
354
        self::GBP->value => '£',
355
        self::SEK->value => 'kr',
356
        self::HKD->value => 'HK$',
357
        self::ZAR->value => 'R',
358
        self::COP->value => '$',
359
        self::MXN->value => '$',
360
        self::VES->value => 'Bs.',
361
        self::SGD->value => 'S$',
362
        self::INR->value => '₹',
363
        self::TWD->value => 'NT$',
364
        self::AED->value => 'د.إ',
365
        self::KRW->value => '₩',
366
        self::PLN->value => 'zł',
367
        self::CZK->value => 'Kč',
368
        self::HUF->value => 'Ft',
369
        self::THB->value => '฿',
370
        self::TRY->value => '₺',
371
        self::MYR->value => 'RM',
372
        self::RUB->value => '₽',
373
        self::IDR->value => 'Rp',
374
        self::UAH->value => '₴',
375
        self::ILS->value => '₪',
376
        self::PHP->value => '₱',
377
        self::SAR->value => '﷼',
378
        self::PKR->value => '₨',
379
        self::VND->value => '₫',
380
        self::EGP->value => '£',
381
        self::RON->value => 'lei',
382
        self::ISK->value => 'kr',
383
        self::IRR->value => '﷼',
384
        self::CRC->value => '₡',
385
        self::PAB->value => 'B/.',
386
        self::PYG->value => '₲',
387
        self::PEN->value => 'S/',
388
        self::UYU->value => '$U',
389
        self::AUD->value => 'A$',
390
        self::BOB->value => 'Bs.',
391
        self::CNY->value => '¥',
392
        self::BRL->value => 'R$',
393
        self::DKK->value => 'kr',
394
        self::CAD->value => 'C$',
395
        self::JPY->value => '¥',
396
        self::CHF->value => 'CHF',
397
        self::NOK->value => 'kr',
398
        self::NZD->value => 'NZ$',
399
        self::XXX->value => '',
400
    ];
401
402
    /**
403
     * Separadores decimal de las monedas.
404
     *
405
     * Si no está definido el separador se entregará "." por defecto.
406
     *
407
     * @var array <string, string>
408
     */
409
    private const SEPARADORES_DECIMAL = [
410
        self::CLP->value => ',',
411
        self::CLF->value => ',',
412
        self::UTM->value => ',',
413
        self::UTA->value => ',',
414
    ];
415
416
    /**
417
     * Separadores de miles de las monedas.
418
     *
419
     * Si no está definido el separador se entregará "," por defecto.
420
     *
421
     * @var array <string, string>
422
     */
423
    private const SEPARADORES_MILES = [
424
        self::CLP->value => '.',
425
        self::CLF->value => '.',
426
        self::UTM->value => '.',
427
        self::UTA->value => '.',
428
    ];
429
430
    /**
431
     * Entrega la glosa de la moneda.
432
     *
433
     * @return string
434
     */
435
    public function getGlosa(): string
436
    {
437
        return self::GLOSAS[$this->value] ?? $this->name;
0 ignored issues
show
Bug introduced by
The constant libredte\lib\Core\Packag...ent\Enum\Moneda::GLOSAS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug Best Practice introduced by
The property name does not exist on libredte\lib\Core\Packag...nt\Document\Enum\Moneda. Did you maybe forget to declare it?
Loading history...
438
    }
439
440
    /**
441
     * Entrega la cantidad de decimales de la moneda.
442
     *
443
     * @return int
444
     */
445
    public function getDecimales(): int
446
    {
447
        return self::DECIMALES[$this->value] ?? 2;
0 ignored issues
show
Bug introduced by
The constant libredte\lib\Core\Packag...\Enum\Moneda::DECIMALES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
448
    }
449
450
    /**
451
     * Entrega el símbolo de la moneda.
452
     *
453
     * @return string
454
     */
455
    public function getSimbolo(): string
456
    {
457
        return self::SIMBOLOS[$this->value];
0 ignored issues
show
Bug introduced by
The constant libredte\lib\Core\Packag...t\Enum\Moneda::SIMBOLOS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
458
    }
459
460
    /**
461
     * Entrega el separador decimal que usa la moneda.
462
     *
463
     * @return string
464
     */
465
    public function getSeparadorDecimal(): string
466
    {
467
        return self::SEPARADORES_DECIMAL[$this->value] ?? '.';
0 ignored issues
show
Bug introduced by
The constant libredte\lib\Core\Packag...da::SEPARADORES_DECIMAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
468
    }
469
470
    /**
471
     * Entrega el separado de miles que usa la moneda.
472
     *
473
     * @return string
474
     */
475
    public function getSeparadorMiles(): string
476
    {
477
        return self::SEPARADORES_MILES[$this->value] ?? ',';
0 ignored issues
show
Bug introduced by
The constant libredte\lib\Core\Packag...neda::SEPARADORES_MILES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
478
    }
479
}
480