Conditions | 14 |
Paths | 26 |
Total Lines | 59 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Tests | 43 |
CRAP Score | 14.0543 |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
26 | 20 | public function getExchangeRate($originalCurrency, $targetCurrency) |
|
27 | { |
||
28 | 20 | $rate = null; |
|
29 | |||
30 | 20 | switch ($originalCurrency) { |
|
31 | 20 | case 'GBP': |
|
32 | 7 | switch($targetCurrency) { |
|
33 | 7 | case 'GBP': |
|
34 | 3 | $rate = 1.00; |
|
35 | 3 | break; |
|
36 | 5 | case 'USD': |
|
37 | 3 | $rate = random_int(124, 139) / 100; |
|
38 | 3 | break; |
|
39 | 3 | case 'EUR': |
|
40 | 3 | $rate = random_int(111, 115) / 100; |
|
41 | 3 | break; |
|
42 | default: |
||
43 | break; |
||
44 | } |
||
45 | 7 | break; |
|
46 | 14 | case 'USD': |
|
47 | 7 | switch($targetCurrency) { |
|
48 | 7 | case 'GBP': |
|
49 | 3 | $rate = random_int(77, 82) / 100; |
|
50 | 3 | break; |
|
51 | 5 | case 'USD': |
|
52 | 3 | $rate = 1.00; |
|
53 | 3 | break; |
|
54 | 3 | case 'EUR': |
|
55 | 3 | $rate = random_int(87, 92) / 100; |
|
56 | 3 | break; |
|
57 | default: |
||
58 | break; |
||
59 | } |
||
60 | 7 | break; |
|
61 | 8 | case 'EUR': |
|
62 | 7 | switch($targetCurrency) { |
|
63 | 7 | case 'GBP': |
|
64 | 3 | $rate = random_int(85, 90) / 100; |
|
65 | 3 | break; |
|
66 | 5 | case 'USD': |
|
67 | 3 | $rate = random_int(109, 114) / 100; |
|
68 | 3 | break; |
|
69 | 3 | case 'EUR': |
|
70 | 3 | $rate = 1.00; |
|
71 | 3 | break; |
|
72 | default: |
||
73 | break; |
||
74 | } |
||
75 | 7 | break; |
|
76 | default: |
||
77 | 1 | break; |
|
78 | } |
||
79 | |||
80 | 20 | if (null === $rate) { |
|
81 | 1 | throw new CurrencyExchangeRateNotFoundException($originalCurrency, $targetCurrency); |
|
82 | } |
||
83 | |||
84 | 19 | return (float)$rate; |
|
85 | } |
||
86 | } |