| Conditions | 3 |
| Paths | 3 |
| Total Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3.1105 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | 2 | public function convert($from, $to) |
|
| 17 | { |
||
| 18 | $url = 'https://free.currencyconverterapi.com' |
||
| 19 | . '/api/v5/convert' |
||
| 20 | 2 | . '?q=' . $from . '_' . $to |
|
| 21 | 2 | . '&compact=ultra' |
|
| 22 | 2 | . '&apiKey=' . $this->apiKey; |
|
| 23 | |||
| 24 | |||
| 25 | 2 | if ($handle = @fopen($url, 'r')) { |
|
| 26 | $this->response = fgets($handle, 4096); |
||
| 27 | |||
| 28 | fclose($handle); |
||
| 29 | |||
| 30 | return; |
||
| 31 | } |
||
| 32 | |||
| 33 | 2 | $errorMessage = 'Error on convert rates'; |
|
| 34 | |||
| 35 | 2 | $errors = error_get_last(); |
|
| 36 | 2 | if (isset ($errors['message'])) { |
|
| 37 | 2 | $errorMessage = $errors['message']; |
|
| 38 | } |
||
| 39 | |||
| 40 | 2 | throw new \Exception($errorMessage); |
|
| 41 | } |
||
| 42 | |||
| 53 |