Passed
Push — master ( b90889...9f43de )
by Dennis
30s
created

Payment::amount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Link0\Bunq\Domain;
4
5
use DateTimeInterface;
6
use DateTimeZone;
7
use Money\Currency;
8
use Money\Money;
9
10
final class Payment
11
{
12
    const TYPE_IDEAL = 'IDEAL';
13
    const TYPE_BUNQ = 'BUNQ';
14
    const TYPE_EBA_SCT = 'EBA_SCT';
15
16
    /**
17
     * @var Id
18
     */
19
    private $id;
20
21
    /**
22
     * @var DateTimeInterface
23
     */
24
    private $created;
25
26
    /**
27
     * @var DateTimeInterface
28
     */
29
    private $updated;
30
31
    /**
32
     * @var Money
33
     */
34
    private $amount;
35
36
    /**
37
     * @var string
38
     */
39
    private $description;
40
41
    /**
42
     * @var string
43
     */
44
    private $type;
45
46
    /**
47
     * @var LabelMonetaryAccount
48
     */
49
    private $alias;
50
51
    /**
52
     * @var LabelMonetaryAccount
53
     */
54
    private $counterpartyAlias;
55
56
    public static function fromArray($value)
57
    {
58
        $timezone = new DateTimeZone('UTC');
59
60
        $payment = new Payment();
61
        $payment->id = Id::fromInteger(intval($value['id']));
62
        $payment->created = new \DateTimeImmutable($value['created'], $timezone);
63
        $payment->updated = new \DateTimeImmutable($value['updated'], $timezone);
64
        $payment->amount = new Money(
65
            $value['amount']['value'] * 100, // cents
66
            new Currency($value['amount']['currency'])
67
        );
68
        $payment->description = $value['description'];
69
        $payment->type = $value['type'];
70
71
        $payment->alias = LabelMonetaryAccount::fromArray($value['alias']);
72
        $payment->counterpartyAlias = LabelMonetaryAccount::fromArray($value['counterparty_alias']);
73
74
        return $payment;
75
    }
76
77
    /**
78
     * @return Id
79
     */
80
    public function id(): Id
81
    {
82
        return $this->id;
83
    }
84
85
    /**
86
     * @return DateTimeInterface
87
     */
88
    public function created(): DateTimeInterface
89
    {
90
        return $this->created;
91
    }
92
93
    /**
94
     * @return DateTimeInterface
95
     */
96
    public function updated(): DateTimeInterface
97
    {
98
        return $this->updated;
99
    }
100
101
    /**
102
     * @return Money
103
     */
104
    public function amount(): Money
105
    {
106
        return $this->amount;
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function description(): string
113
    {
114
        return $this->description;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function type(): string
121
    {
122
        return $this->type;
123
    }
124
125
    /**
126
     * @return LabelMonetaryAccount
127
     */
128
    public function alias(): LabelMonetaryAccount
129
    {
130
        return $this->alias;
131
    }
132
133
    /**
134
     * @return LabelMonetaryAccount
135
     */
136
    public function counterpartyAlias(): LabelMonetaryAccount
137
    {
138
        return $this->counterpartyAlias;
139
    }
140
}
141