Conditions | 30 |
Paths | 30 |
Total Lines | 65 |
Code Lines | 48 |
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::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 |