Quotes   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 17
c 0
b 0
f 0
dl 0
loc 79
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A __get() 0 8 2
A source() 0 3 1
A quotes() 0 3 1
A timestamp() 0 3 1
A date() 0 3 1
1
<?php
2
3
namespace Orkhanahmadov\Currencylayer\Data;
4
5
class Quotes
6
{
7
    /**
8
     * @var string
9
     */
10
    private $source;
11
    /**
12
     * @var array
13
     */
14
    private $quotes;
15
    /**
16
     * @var int
17
     */
18
    private $timestamp;
19
    /**
20
     * @var \DateTimeInterface|null
21
     */
22
    private $date = null;
23
24
    /**
25
     * Currency constructor.
26
     *
27
     * @param array $data
28
     *
29
     * @throws \Exception
30
     */
31
    public function __construct(array $data)
32
    {
33
        $this->source = $data['source'];
34
        $this->quotes = $data['quotes'];
35
        $this->timestamp = $data['timestamp'];
36
        $this->date = isset($data['date']) ? new \DateTimeImmutable($data['date']) : null;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function source(): string
43
    {
44
        return $this->source;
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function quotes(): array
51
    {
52
        return $this->quotes;
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function timestamp(): int
59
    {
60
        return $this->timestamp;
61
    }
62
63
    /**
64
     * @return \DateTimeInterface|null
65
     */
66
    public function date(): ?\DateTimeInterface
67
    {
68
        return $this->date;
69
    }
70
71
    /**
72
     * @param string $name
73
     *
74
     * @return float
75
     */
76
    public function __get(string $name): float
77
    {
78
        $key = $this->source.$name;
79
        if (!array_key_exists($key, $this->quotes)) {
80
            throw new \InvalidArgumentException("{$name} does not exist in API response. Did you put it in request?");
81
        }
82
83
        return $this->quotes[$key];
84
    }
85
}
86