Total Complexity | 8 |
Total Lines | 88 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | final class CurrencyInfo |
||
8 | { |
||
9 | /** |
||
10 | * @var int |
||
11 | */ |
||
12 | private $currencyCodeA; |
||
13 | |||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | private $currencyCodeB; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | private $date; |
||
23 | |||
24 | /** |
||
25 | * @var float |
||
26 | */ |
||
27 | private $rateSell; |
||
28 | |||
29 | /** |
||
30 | * @var float|null |
||
31 | */ |
||
32 | private $rateBuy; |
||
33 | |||
34 | /** |
||
35 | * @var float|null |
||
36 | */ |
||
37 | private $rateCross; |
||
38 | |||
39 | public function __construct( |
||
40 | int $currencyCodeA, |
||
41 | int $currencyCodeB, |
||
42 | int $date, |
||
43 | ?float $rateSell = null, |
||
44 | ?float $rateBuy = null, |
||
45 | ?float $rateCross = null |
||
46 | ) { |
||
47 | $this->currencyCodeA = $currencyCodeA; |
||
48 | $this->currencyCodeB = $currencyCodeB; |
||
49 | $this->date = $date; |
||
50 | $this->rateSell = $rateSell; |
||
51 | $this->rateBuy = $rateBuy; |
||
52 | $this->rateCross = $rateCross; |
||
53 | } |
||
54 | |||
55 | public static function fromResponse(array $data) |
||
56 | { |
||
57 | return new self( |
||
58 | $data['currencyCodeA'], |
||
59 | $data['currencyCodeB'], |
||
60 | $data['date'], |
||
61 | $data['rateSell'] ?? null, |
||
62 | $data['rateBuy'] ?? null, |
||
63 | $data['rateCross'] ?? null |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | public function currencyCodeA(): int |
||
68 | { |
||
69 | return $this->currencyCodeA; |
||
70 | } |
||
71 | |||
72 | public function currencyCodeB(): int |
||
73 | { |
||
74 | return $this->currencyCodeB; |
||
75 | } |
||
76 | |||
77 | public function date(): \DateTime |
||
78 | { |
||
79 | return (new \DateTime())->setTimestamp($this->date); |
||
80 | } |
||
81 | |||
82 | public function rateSell(): ?float |
||
83 | { |
||
84 | return $this->rateSell; |
||
85 | } |
||
86 | |||
87 | public function rateBuy(): ?float |
||
90 | } |
||
91 | |||
92 | public function rateCross(): ?float |
||
93 | { |
||
94 | return $this->rateCross; |
||
95 | } |
||
96 | } |
||
97 |