CurrenciesHelper   A
last analyzed

Complexity

Total Complexity 34

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 78
ccs 50
cts 50
cp 1
rs 9.68
c 0
b 0
f 0
wmc 34
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D canonizeCurrency() 0 70 34
1
<?php
2
namespace morphos;
3
4
use InvalidArgumentException;
5
6
trait CurrenciesHelper
7
{
8
    /**
9
     * @param string $currency
10
     * @return string
11
     * @throws InvalidArgumentException
12
     */
13 36
    public static function canonizeCurrency($currency)
14
    {
15
        switch ($currency) {
16 36
            case Currency::DOLLAR:
17 34
            case '$':
18 34
            case 'usd':
19 34
            case 'dollar':
20 3
                return Currency::DOLLAR;
21
22 33
            case Currency::EURO:
23 32
            case '€':
24 32
            case 'euro':
25 2
                return Currency::EURO;
26
27 31
            case Currency::YEN:
28 30
            case '¥':
29 2
                return Currency::YEN;
30
31 29
            case Currency::POUND:
32 28
            case '£':
33 2
                return Currency::POUND;
34
35 27
            case Currency::FRANC:
36 25
            case 'Fr':
37 3
                return Currency::FRANC;
38
39 24
            case Currency::YUAN:
40 23
            case '元':
41 2
                return Currency::YUAN;
42
43 22
            case Currency::KRONA:
44 21
            case 'Kr':
45 2
                return Currency::KRONA;
46
47 20
            case Currency::PESO:
48 2
                return Currency::PESO;
49
50 18
            case Currency::WON:
51 18
            case '₩':
52 1
                return Currency::WON;
53
54 17
            case Currency::LIRA:
55 16
            case '₺':
56 2
                return Currency::LIRA;
57
58 15
            case Currency::RUBLE:
59 8
            case '₽':
60 8
            case 'ruble':
61 8
                return Currency::RUBLE;
62
63 7
            case Currency::RUPEE:
64 7
            case '₹':
65 1
                return Currency::RUPEE;
66
67 6
            case Currency::REAL:
68 6
            case 'R$':
69 1
                return Currency::REAL;
70
71 5
            case Currency::RAND:
72 5
            case 'R':
73 1
                return Currency::RAND;
74
75 4
            case Currency::HRYVNIA:
76 3
            case '₴':
77 2
                return Currency::HRYVNIA;
78
79
            default:
80 2
                throw new InvalidArgumentException('Invalid currency: '.$currency);
81
        }
82
    }
83
}
84