|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace byrokrat\banking; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Account number implementation for accounts not belonging to a bank |
|
9
|
|
|
*/ |
|
10
|
|
|
class UndefinedAccount implements AccountNumber |
|
11
|
|
|
{ |
|
12
|
|
|
use Formatter\FormattableTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $raw; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string Account clearing number |
|
21
|
|
|
*/ |
|
22
|
|
|
private $clearing; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string Check digit of the clearing number |
|
26
|
|
|
*/ |
|
27
|
|
|
private $clearingCheckDigit; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string Account serial number |
|
31
|
|
|
*/ |
|
32
|
|
|
private $serial; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string Check digit |
|
36
|
|
|
*/ |
|
37
|
|
|
private $checkDigit; |
|
38
|
|
|
|
|
39
|
231 |
|
public function __construct(string $raw, string $clearing, string $clearingCheck, string $serial, string $check) |
|
40
|
|
|
{ |
|
41
|
231 |
|
$this->raw = $raw; |
|
42
|
231 |
|
$this->clearing = $clearing; |
|
43
|
231 |
|
$this->clearingCheckDigit = $clearingCheck; |
|
44
|
231 |
|
$this->serial = $serial; |
|
45
|
231 |
|
$this->checkDigit = $check; |
|
46
|
231 |
|
} |
|
47
|
|
|
|
|
48
|
89 |
|
public function getBankName(): string |
|
49
|
|
|
{ |
|
50
|
89 |
|
return ''; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
139 |
|
public function getRawNumber(): string |
|
54
|
|
|
{ |
|
55
|
139 |
|
return $this->raw; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
230 |
|
public function getClearingNumber(): string |
|
59
|
|
|
{ |
|
60
|
230 |
|
return $this->clearing; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
189 |
|
public function getClearingCheckDigit(): string |
|
64
|
|
|
{ |
|
65
|
189 |
|
return $this->clearingCheckDigit; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
191 |
|
public function getSerialNumber(): string |
|
69
|
|
|
{ |
|
70
|
191 |
|
return $this->serial; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
189 |
|
public function getCheckDigit(): string |
|
74
|
|
|
{ |
|
75
|
189 |
|
return $this->checkDigit; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function equals(AccountNumber $account, bool $strict = false): bool |
|
79
|
|
|
{ |
|
80
|
88 |
|
$has = function (string $number): bool { |
|
81
|
88 |
|
return $number !== ''; |
|
82
|
88 |
|
}; |
|
83
|
|
|
|
|
84
|
88 |
|
return (!$this->getBankName() || $this->getBankName() == $account->getBankName()) |
|
85
|
88 |
|
&& $this->getClearingNumber() == $account->getClearingNumber() |
|
86
|
88 |
|
&& $this->getSerialNumber() == $account->getSerialNumber() |
|
87
|
88 |
|
&& $this->getCheckDigit() == $account->getCheckDigit() |
|
88
|
88 |
|
&& !(($has($this->getClearingCheckDigit()) xor $has($account->getClearingCheckDigit())) && $strict) |
|
89
|
|
|
&& ( |
|
90
|
87 |
|
!$has($this->getClearingCheckDigit()) |
|
91
|
5 |
|
|| !$has($account->getClearingCheckDigit()) |
|
92
|
88 |
|
|| $this->getClearingCheckDigit() == $account->getClearingCheckDigit() |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
6 |
|
protected function getFormattable(): AccountNumber |
|
97
|
|
|
{ |
|
98
|
6 |
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|