Passed
Push — master ( b4f1ba...dc5416 )
by Alessandro
02:37 queued 22s
created

Rates::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: alessandrominoccheri
6
 * Date: 05/09/18
7
 * Time: 12:59
8
 */
9
10
namespace CurrencyConverter;
11
12
class Rates
13
{
14
    private $apiCaller;
15
16 4
    public function __construct(ApiCaller $apiCaller)
17
    {
18 4
        $this->apiCaller = $apiCaller;
19 4
    }
20
21 4
    public function getRates(string $fromCurrency, string $toCurrency)
22
    {
23 4
        $this->apiCaller->convert(
24
            $fromCurrency,
25
            $toCurrency
26
        );
27
28 3
        if ($this->apiCaller->isLastCallEmpty()) {
29 1
            return 0;
30
        }
31
32 2
        $result = $this->apiCaller->getLastResponse();
33
34 2
        $conversion = json_decode($result, true);
35 2
        $key = $fromCurrency . '_' . $toCurrency;
36
37 2
        if (!isset($conversion[$key])) {
38 1
            return 0;
39
        }
40
41 1
        return $conversion[$fromCurrency . '_' . $toCurrency];
42
    }
43
44
}
45