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 $currency
10
     * @return string
11
     * @throws InvalidArgumentException
12
     */
13 30
    public static function canonizeCurrency($currency)
14
    {
15
        switch ($currency) {
16 30
            case Currency::DOLLAR:
17 28
            case '$':
18 28
            case 'usd':
19 28
            case 'dollar':
20 3
                return Currency::DOLLAR;
21
22 27
            case Currency::EURO:
23 26
            case '€':
24 26
            case 'euro':
25 2
                return Currency::EURO;
26
27 25
            case Currency::YEN:
28 24
            case '¥':
29 2
                return Currency::YEN;
30
31 23
            case Currency::POUND:
32 22
            case '£':
33 2
                return Currency::POUND;
34
35 21
            case Currency::FRANC:
36 19
            case 'Fr':
37 3
                return Currency::FRANC;
38
39 18
            case Currency::YUAN:
40 17
            case '元':
41 2
                return Currency::YUAN;
42
43 16
            case Currency::KRONA:
44 15
            case 'Kr':
45 2
                return Currency::KRONA;
46
47 14
            case Currency::PESO:
48 2
                return Currency::PESO;
49
50 12
            case Currency::WON:
51 12
            case '₩':
52 1
                return Currency::WON;
53
54 11
            case Currency::LIRA:
55 10
            case '₺':
56 2
                return Currency::LIRA;
57
58 9
            case Currency::RUBLE:
59 8
            case '₽':
60 8
            case 'ruble':
61 2
                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