Completed
Push — master ( 583fed...4b9fc9 )
by f
01:15
created

CurrenciesHelper::canonizeCurrency()   C

Complexity

Conditions 30
Paths 30

Size

Total Lines 65
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 30
eloc 48
nc 30
nop 1
dl 0
loc 65
rs 5.7257
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::FRANC:
26
            case 'Fr':
27
                return Currency::FRANC;
28
29
            case Currency::YUAN:
30
            case '元':
31
                return Currency::YUAN;
32
33
            case Currency::KRONA:
34
            case 'Kr':
35
                return Currency::KRONA;
36
37
            case Currency::PESO:
38
                return Currency::PESO;
39
40
            case Currency::WON:
41
            case '₩':
42
                return Currency::WON;
43
44
            case Currency::LIRA:
45
            case '₺':
46
                return Currency::LIRA;
47
48
            case Currency::RUBLE:
49
            case '₽':
50
                return Currency::RUBLE;
51
52
            case Currency::RUPEE:
53
            case '₹':
54
                return Currency::RUPEE;
55
56
            case Currency::REAL:
57
            case 'R$':
58
                return Currency::REAL;
59
60
            case Currency::RAND:
61
            case 'R':
62
                return Currency::RAND;
63
64
            case Currency::HRYVNIA:
65
            case '₴':
66
                return Currency::HRYVNIA;
67
68
            default:
69
                throw new Exception('Invalid currency: '.$currency);
70
        }
71
    }
72
}
73