Conditions | 38 |
Paths | 38 |
Total Lines | 81 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 |