Donor   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 204
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 204
rs 10
c 0
b 0
f 0
wmc 19

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 32 1
A getMandateSource() 0 3 1
A getDonationAmount() 0 3 1
A getName() 0 3 1
A getComment() 0 3 1
A getPayerNumber() 0 3 1
A getAttribute() 0 7 2
A getCreated() 0 3 1
A getAccount() 0 3 1
A getState() 0 3 1
A getPostalAddress() 0 3 1
A getDonorId() 0 3 1
A getEmail() 0 3 1
A getAttributes() 0 3 1
A hasAttribute() 0 3 1
A getUpdated() 0 3 1
A getMandateKey() 0 3 1
A getPhone() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of byrokrat\giroapp.
5
 *
6
 * byrokrat\giroapp is free software: you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * byrokrat\giroapp is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * Copyright 2016-21 Hannes Forsgård
20
 */
21
22
declare(strict_types=1);
23
24
namespace byrokrat\giroapp\Domain;
25
26
use byrokrat\giroapp\Exception\UnknownIdentifierException;
27
use byrokrat\giroapp\Domain\State\StateInterface;
28
use byrokrat\banking\AccountNumber;
29
use byrokrat\id\IdInterface;
30
use Money\Money;
31
32
/**
33
 * Models an individual donor
34
 */
35
class Donor
36
{
37
    /**
38
     * @var string
39
     */
40
    private $mandateKey;
41
42
    /**
43
     * @var StateInterface
44
     */
45
    private $state;
46
47
    /**
48
     * @var string
49
     */
50
    private $mandateSource;
51
52
    /**
53
     * @var string
54
     */
55
    private $payerNumber;
56
57
    /**
58
     * @var AccountNumber
59
     */
60
    private $account;
61
62
    /**
63
     * @var IdInterface
64
     */
65
    private $donorId;
66
67
    /**
68
     * @var string
69
     */
70
    private $name;
71
72
    /**
73
     * @var PostalAddress
74
     */
75
    private $address;
76
77
    /**
78
     * @var string
79
     */
80
    private $email;
81
82
    /**
83
     * @var string
84
     */
85
    private $phone;
86
87
    /**
88
     * @var Money
89
     */
90
    private $donationAmount;
91
92
    /**
93
     * @var string
94
     */
95
    private $comment;
96
97
    /**
98
     * @var \DateTimeImmutable
99
     */
100
    private $created;
101
102
    /**
103
     * @var \DateTimeImmutable
104
     */
105
    private $updated;
106
107
    /**
108
     * @var string[] Loaded attributes
109
     */
110
    private $attributes;
111
112
    /**
113
     * @param string[] $attributes
114
     */
115
    public function __construct(
116
        string $mandateKey,
117
        StateInterface $state,
118
        string $mandateSource,
119
        string $payerNumber,
120
        AccountNumber $account,
121
        IdInterface $donorId,
122
        string $name,
123
        PostalAddress $address,
124
        string $email,
125
        string $phone,
126
        Money $donationAmount,
127
        string $comment,
128
        \DateTimeImmutable $created,
129
        \DateTimeImmutable $updated,
130
        array $attributes = []
131
    ) {
132
        $this->mandateKey = $mandateKey;
133
        $this->state = $state;
134
        $this->mandateSource = $mandateSource;
135
        $this->payerNumber = $payerNumber;
136
        $this->account = $account;
137
        $this->donorId = $donorId;
138
        $this->name = $name;
139
        $this->address = $address;
140
        $this->email = $email;
141
        $this->phone = $phone;
142
        $this->donationAmount = $donationAmount;
143
        $this->comment = $comment;
144
        $this->created = $created;
145
        $this->updated = $updated;
146
        $this->attributes = $attributes;
147
    }
148
149
    public function getMandateKey(): string
150
    {
151
        return $this->mandateKey;
152
    }
153
154
    public function getState(): StateInterface
155
    {
156
        return $this->state;
157
    }
158
159
    public function getMandateSource(): string
160
    {
161
        return $this->mandateSource;
162
    }
163
164
    public function getPayerNumber(): string
165
    {
166
        return $this->payerNumber;
167
    }
168
169
    public function getAccount(): AccountNumber
170
    {
171
        return $this->account;
172
    }
173
174
    public function getDonorId(): IdInterface
175
    {
176
        return $this->donorId;
177
    }
178
179
    public function getName(): string
180
    {
181
        return $this->name;
182
    }
183
184
    public function getPostalAddress(): PostalAddress
185
    {
186
        return $this->address;
187
    }
188
189
    public function getEmail(): string
190
    {
191
        return $this->email;
192
    }
193
194
    public function getPhone(): string
195
    {
196
        return $this->phone;
197
    }
198
199
    public function getDonationAmount(): Money
200
    {
201
        return $this->donationAmount;
202
    }
203
204
    public function getComment(): string
205
    {
206
        return $this->comment;
207
    }
208
209
    public function getCreated(): \DateTimeImmutable
210
    {
211
        return $this->created;
212
    }
213
214
    public function getUpdated(): \DateTimeImmutable
215
    {
216
        return $this->updated;
217
    }
218
219
    public function hasAttribute(string $key): bool
220
    {
221
        return isset($this->attributes[$key]);
222
    }
223
224
    public function getAttribute(string $key): string
225
    {
226
        if (!$this->hasAttribute($key)) {
227
            throw new UnknownIdentifierException("Unknown attribute $key");
228
        }
229
230
        return $this->attributes[$key];
231
    }
232
233
    /**
234
     * @return string[]
235
     */
236
    public function getAttributes(): array
237
    {
238
        return $this->attributes;
239
    }
240
}
241