Total Complexity | 8 |
Total Lines | 80 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Currency |
||
9 | { |
||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | private $quotes; |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $source; |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $timestamp; |
||
22 | /** |
||
23 | * @var CarbonImmutable|null |
||
24 | */ |
||
25 | private $date; |
||
26 | |||
27 | /** |
||
28 | * Currency constructor. |
||
29 | * |
||
30 | * @param array $data |
||
31 | * |
||
32 | * @throws \Exception |
||
33 | */ |
||
34 | public function __construct(array $data) |
||
35 | { |
||
36 | $this->quotes = $data['quotes']; |
||
37 | $this->source = $data['source']; |
||
38 | $this->timestamp = $data['timestamp']; |
||
39 | $this->date = isset($data['date']) ? new CarbonImmutable($data['date']) : null; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param string $name |
||
44 | * |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function __get(string $name) |
||
48 | { |
||
49 | $key = $this->source . $name; |
||
50 | if (! array_key_exists($key, $this->quotes)) { |
||
51 | throw new \InvalidArgumentException($name . ' does not exist in API response. Did you requested it?'); |
||
52 | } |
||
53 | |||
54 | return $this->quotes[$key]; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @return array |
||
59 | */ |
||
60 | public function getQuotes(): array |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getSource(): string |
||
69 | { |
||
70 | return $this->source; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return DateTimeImmutable |
||
75 | * @throws \Exception |
||
76 | */ |
||
77 | public function getTimestamp(): DateTimeImmutable |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return CarbonImmutable|null |
||
84 | */ |
||
85 | public function getDate(): ?CarbonImmutable |
||
88 | } |
||
89 | } |
||
90 |