Conversion   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 22
c 0
b 0
f 0
dl 0
loc 103
rs 10

8 Methods

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