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