Passed
Push — master ( 529080...279f50 )
by Greg
02:25
created

Money   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertAmount() 0 3 1
A getConvRate() 0 16 4
A getConvUrl() 0 4 1
1
<?php
2
namespace GJClasses;
3
4
class Money
5
{
6
    public function convertAmount($amount, $from_currency, $to_currency)
7
    {
8
        return $this->getConvRate($from_currency, $to_currency) * $amount;
9
    }
10
11
    public function getConvRate($from_currency, $to_currency)
12
    {
13
        list($currency_slug, $full_url) = $this->getConvUrl($from_currency, $to_currency);
14
        $remote = new Remote();
15
        $result = $remote->getFileContents($full_url);
16
        if ($result === false) return false;
17
        $json_result = json_decode($result);
18
        $conversion_rate = $json_result->{$currency_slug}->val;
19
20
        if (!is_null($conversion_rate) && $conversion_rate != '') {
21
22
            return $conversion_rate;
23
24
        } else {
25
26
            return false;
27
28
        }
29
    }
30
31
    public function getConvUrl($from_currency, $to_currency)
32
    {
33
        $currency_slug = $from_currency . '_' . $to_currency;
34
        return array($currency_slug, 'https://free.currencyconverterapi.com/api/v5/convert?q=' . $currency_slug . '&compact=y');
35
    }
36
}
37