Transaction::fromArray()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PomeloPHP\Model;
3
4
class Transaction
5
{
6
    /**
7
     * @var int
8
     */
9
    private $amount;
10
11
    /**
12
     * @var string
13
     */
14
    private $currency;
15
16
    /**
17
     * @return int
18
     */
19
    public function getAmount()
20
    {
21
        return $this->amount;
22
    }
23
24
    /**
25
     * @param int $amount
26
     */
27
    public function setAmount(int $amount)
28
    {
29
        $this->amount = $amount;
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getCurrency()
36
    {
37
        return $this->currency;
38
    }
39
40
    /**
41
     * @param string $currency
42
     */
43
    public function setCurrency(string $currency)
44
    {
45
        $this->currency = $currency;
46
    }
47
48
    /**
49
     * @param array $json
50
     * @return $this
51
     */
52
    public function fromArray(array $json)
53
    {
54
        if (array_key_exists('amount', $json) && array_key_exists('currency', $json)) {
55
            $this->amount = $json['amount'];
56
            $this->currency = $json['currency'];
57
58
            return $this;
59
        }
60
61
        throw new \InvalidArgumentException('amount and currency are required to sign a transaction');
62
    }
63
}
64