Completed
Push — master ( 58a943...583fed )
by f
01:21
created

CurrenciesHelper::canonizeCurrency()   D

Complexity

Conditions 38
Paths 38

Size

Total Lines 81
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 38
eloc 60
nc 38
nop 1
dl 0
loc 81
rs 4.8623
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace morphos;
3
4
use Exception;
5
6
trait CurrenciesHelper {
7
    static public function canonizeCurrency($currency) {
8
        switch ($currency) {
9
            case Currency::DOLLAR:
10
            case '$':
11
                return Currency::DOLLAR;
12
13
            case Currency::EURO:
14
            case '€':
15
                return Currency::EURO;
16
17
            case Currency::YEN:
18
            case '¥':
19
                return Currency::YEN;
20
21
            case Currency::POUND:
22
            case '£':
23
                return Currency::POUND;
24
25
            case Currency::AUSTRALIAN_DOLLAR:
26
            case 'A$':
27
                return Currency::AUSTRALIAN_DOLLAR;
28
29
            case Currency::CANADIAN_DOLLAR:
30
            case 'C$':
31
                return Currency::CANADIAN_DOLLAR;
32
33
            case Currency::FRANC:
34
            case 'Fr':
35
                return Currency::FRANC;
36
37
            case Currency::YUAN:
38
            case '元':
39
                return Currency::YUAN;
40
41
            case Currency::KRONA:
42
            case 'Kr':
43
                return Currency::KRONA;
44
45
            case Currency::ZELAND_DOLLAR:
46
            case 'NZ$':
47
                return Currency::ZELAND_DOLLAR;
48
49
            case Currency::PESO:
50
                return Currency::PESO;
51
52
            case Currency::SINGAPORE_DOLLAR:
53
            case 'S$':
54
                return Currency::SINGAPORE_DOLLAR;
55
56
            case Currency::HONG_KONG_DOLLAR:
57
            case 'HK$':
58
                return Currency::HONG_KONG_DOLLAR;
59
60
            case Currency::WON:
61
            case '₩':
62
                return Currency::WON;
63
64
            case Currency::LIRA:
65
            case '₺':
66
                return Currency::LIRA;
67
68
            case Currency::RUBLE:
69
            case '₽':
70
                return Currency::RUBLE;
71
72
            case Currency::RUPEE:
73
            case '₹':
74
                return Currency::RUPEE;
75
76
            case Currency::REAL:
77
            case 'R$':
78
                return Currency::REAL;
79
80
            case Currency::RAND:
81
            case 'R':
82
                return Currency::RAND;
83
84
            default:
85
                throw new Exception('Invalid currency: '.$currency);
86
        }
87
    }
88
}
89