| Conditions | 34 |
| Paths | 34 |
| Total Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 50 |
| CRAP Score | 34 |
| 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 |
||
| 13 | 36 | public static function canonizeCurrency($currency) |
|
| 14 | { |
||
| 15 | switch ($currency) { |
||
| 16 | 36 | case Currency::DOLLAR: |
|
| 17 | 34 | case '$': |
|
| 18 | 34 | case 'usd': |
|
| 19 | 34 | case 'dollar': |
|
| 20 | 3 | return Currency::DOLLAR; |
|
| 21 | |||
| 22 | 33 | case Currency::EURO: |
|
| 23 | 32 | case '€': |
|
| 24 | 32 | case 'euro': |
|
| 25 | 2 | return Currency::EURO; |
|
| 26 | |||
| 27 | 31 | case Currency::YEN: |
|
| 28 | 30 | case '¥': |
|
| 29 | 2 | return Currency::YEN; |
|
| 30 | |||
| 31 | 29 | case Currency::POUND: |
|
| 32 | 28 | case '£': |
|
| 33 | 2 | return Currency::POUND; |
|
| 34 | |||
| 35 | 27 | case Currency::FRANC: |
|
| 36 | 25 | case 'Fr': |
|
| 37 | 3 | return Currency::FRANC; |
|
| 38 | |||
| 39 | 24 | case Currency::YUAN: |
|
| 40 | 23 | case '元': |
|
| 41 | 2 | return Currency::YUAN; |
|
| 42 | |||
| 43 | 22 | case Currency::KRONA: |
|
| 44 | 21 | case 'Kr': |
|
| 45 | 2 | return Currency::KRONA; |
|
| 46 | |||
| 47 | 20 | case Currency::PESO: |
|
| 48 | 2 | return Currency::PESO; |
|
| 49 | |||
| 50 | 18 | case Currency::WON: |
|
| 51 | 18 | case '₩': |
|
| 52 | 1 | return Currency::WON; |
|
| 53 | |||
| 54 | 17 | case Currency::LIRA: |
|
| 55 | 16 | case '₺': |
|
| 56 | 2 | return Currency::LIRA; |
|
| 57 | |||
| 58 | 15 | case Currency::RUBLE: |
|
| 59 | 8 | case '₽': |
|
| 60 | 8 | case 'ruble': |
|
| 61 | 8 | return Currency::RUBLE; |
|
| 62 | |||
| 63 | 7 | case Currency::RUPEE: |
|
| 64 | 7 | case '₹': |
|
| 65 | 1 | return Currency::RUPEE; |
|
| 66 | |||
| 67 | 6 | case Currency::REAL: |
|
| 68 | 6 | case 'R$': |
|
| 69 | 1 | return Currency::REAL; |
|
| 70 | |||
| 71 | 5 | case Currency::RAND: |
|
| 72 | 5 | case 'R': |
|
| 73 | 1 | return Currency::RAND; |
|
| 74 | |||
| 75 | 4 | case Currency::HRYVNIA: |
|
| 76 | 3 | case '₴': |
|
| 77 | 2 | return Currency::HRYVNIA; |
|
| 78 | |||
| 79 | default: |
||
| 80 | 2 | throw new InvalidArgumentException('Invalid currency: '.$currency); |
|
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 |