Passed
Push — master ( e876ed...96eedf )
by Orkhan
01:40
created

Conversion::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Orkhanahmadov\Currencylayer;
4
5
use Carbon\CarbonImmutable;
6
use DateTimeImmutable;
7
8
class Conversion
9
{
10
    /**
11
     * @var string
12
     */
13
    private $from;
14
    /**
15
     * @var string
16
     */
17
    private $to;
18
    /**
19
     * @var int|float
20
     */
21
    private $amount;
22
    /**
23
     * @var CarbonImmutable
24
     */
25
    private $timestamp;
26
    /**
27
     * @var float
28
     */
29
    private $quote;
30
    /**
31
     * @var float
32
     */
33
    private $result;
34
    /**
35
     * @var CarbonImmutable|null
36
     */
37
    private $date;
38
39
    /**
40
     * Conversion constructor.
41
     *
42
     * @param array $data
43
     * @throws \Exception
44
     */
45
    public function __construct(array $data)
46
    {
47
        $this->from = $data['query']['from'];
48
        $this->to = $data['query']['to'];
49
        $this->amount = $data['query']['amount'];
50
        $this->quote = $data['info']['quote'];
51
        $this->result = $data['result'];
52
        $this->timestamp = new CarbonImmutable($data['info']['timestamp']);
53
        $this->date = isset($data['date']) ? new CarbonImmutable($data['date']) : null;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getFrom(): string
60
    {
61
        return $this->from;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getTo(): string
68
    {
69
        return $this->to;
70
    }
71
72
    /**
73
     * @return float|int
74
     */
75
    public function getAmount()
76
    {
77
        return $this->amount;
78
    }
79
80
    /**
81
     * @return DateTimeImmutable
82
     */
83
    public function getTimestamp(): DateTimeImmutable
84
    {
85
        return $this->timestamp;
86
    }
87
88
    /**
89
     * @return float
90
     */
91
    public function getQuote(): float
92
    {
93
        return $this->quote;
94
    }
95
96
    /**
97
     * @return float
98
     */
99
    public function getResult(): float
100
    {
101
        return $this->result;
102
    }
103
104
    /**
105
     * @return CarbonImmutable|null
106
     */
107
    public function getDate(): ?CarbonImmutable
108
    {
109
        return $this->date;
110
    }
111
}
112