| Conditions | 12 |
| Paths | 12 |
| Total Lines | 54 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 20 | public function getConvRate($from_currency, $to_currency) |
||
| 21 | { |
||
| 22 | if ($from_currency == $to_currency) return 1.0; |
||
| 23 | |||
| 24 | $conversion_rate = 0.0; |
||
| 25 | |||
| 26 | if ($this->source === 'era') { |
||
| 27 | |||
| 28 | $full_url = 'http://api.exchangeratesapi.io/v1/convert?access_key=' . $this->api_key . '&from=' . $from_currency . '&to=' . $to_currency; |
||
| 29 | $remote = new Remote(); |
||
| 30 | $result = $remote->getFileContents($full_url); |
||
| 31 | if ($result === false) return false; |
||
| 32 | $json_result = json_decode($result, true); |
||
|
|
|||
| 33 | $conversion_rate = $json_result['rates'][$to_currency]; |
||
| 34 | |||
| 35 | } elseif ($this->source === 'er-a') { |
||
| 36 | |||
| 37 | $full_url = 'https://v6.exchangerate-api.com/v6/' . $this->api_key . '/pair/' . $from_currency . '/' . $to_currency; |
||
| 38 | $remote = new Remote(); |
||
| 39 | $result = $remote->getFileContents($full_url); |
||
| 40 | if ($result === false) return false; |
||
| 41 | $json_result = json_decode($result, true); |
||
| 42 | $conversion_rate = $json_result['conversion_rate']; |
||
| 43 | |||
| 44 | } elseif ($this->source === 'fixer') { |
||
| 45 | |||
| 46 | $full_url = 'http://data.fixer.io/api/convert?access_key=' . $this->api_key . '&from=' . $from_currency . '&to=' . $to_currency; |
||
| 47 | $remote = new Remote(); |
||
| 48 | $result = $remote->getFileContents($full_url); |
||
| 49 | if ($result === false) return false; |
||
| 50 | $json_result = json_decode($result, true); |
||
| 51 | $conversion_rate = $json_result['rates'][$to_currency]; |
||
| 52 | |||
| 53 | } elseif ($this->source === 'interzoid') { |
||
| 54 | |||
| 55 | $full_url = 'https://api.interzoid.com/convertcurrency?license=' . $this->api_key . '&from=' . $from_currency . '&to=' . $to_currency . '&amount=1'; |
||
| 56 | $remote = new Remote(); |
||
| 57 | $result = $remote->getFileContents($full_url); |
||
| 58 | if ($result === false) return false; |
||
| 59 | $json_result = json_decode($result, true); |
||
| 60 | $conversion_rate = $json_result['Converted']; |
||
| 61 | |||
| 62 | } elseif ($this->source === 'erh') { |
||
| 63 | |||
| 64 | $full_url = 'https://api.exchangerate.host/convert?from=' . $from_currency . '&to=' . $to_currency; |
||
| 65 | $remote = new Remote(); |
||
| 66 | $result = $remote->getFileContents($full_url); |
||
| 67 | if ($result === false) return false; |
||
| 68 | $json_result = json_decode($result, true); |
||
| 69 | $conversion_rate = $json_result['info']['rate']; |
||
| 70 | |||
| 71 | } |
||
| 72 | |||
| 73 | return $conversion_rate; |
||
| 74 | } |
||
| 76 |