1 | <?php |
||
9 | class Iban |
||
10 | { |
||
11 | /** |
||
12 | * @var BbanInterface |
||
13 | */ |
||
14 | private $bban; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $countryCode; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $checkDigits; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | private static $countriesSupported = [ |
||
30 | 'ES' => SpainBban::class, |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * Iban constructor. |
||
35 | * |
||
36 | * @param string $countryCode |
||
37 | * @param string $checkDigits |
||
38 | * @param BbanInterface $bban |
||
39 | * |
||
40 | * @throws InvalidArgumentException |
||
41 | */ |
||
42 | public function __construct($countryCode, $checkDigits, BbanInterface $bban) |
||
52 | |||
53 | /** |
||
54 | * @param string $iban |
||
55 | * |
||
56 | * @throws InvalidArgumentException |
||
57 | * |
||
58 | * @return static |
||
59 | */ |
||
60 | public static function fromString($iban) |
||
80 | |||
81 | /** |
||
82 | * @param BbanInterface $bban |
||
83 | * @param string $countryCode |
||
84 | * |
||
85 | * @throws InvalidArgumentException |
||
86 | * |
||
87 | * @return static |
||
88 | */ |
||
89 | public static function fromBbanAndCountry(BbanInterface $bban, $countryCode) |
||
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | public function countryCode() |
||
109 | |||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | public function ibanCheckDigits() |
||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | public function bankCode() |
||
125 | |||
126 | /** |
||
127 | * @return string |
||
128 | */ |
||
129 | public function branchCode() |
||
133 | |||
134 | /** |
||
135 | * @return string |
||
136 | */ |
||
137 | public function countryCheckDigits() |
||
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | public function accountNumber() |
||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | public function __toString() |
||
159 | |||
160 | /** |
||
161 | * @param $countryCode |
||
162 | * |
||
163 | * @throws InvalidArgumentException |
||
164 | */ |
||
165 | private static function validateCountryCodeFormat($countryCode) |
||
171 | |||
172 | /** |
||
173 | * @param $checkDigits |
||
174 | * |
||
175 | * @throws InvalidArgumentException |
||
176 | */ |
||
177 | private static function validateCheckDigitsFormat($checkDigits) |
||
183 | |||
184 | /** |
||
185 | * @param string $countryCode |
||
186 | * @param string $checkDigits |
||
187 | * @param BbanInterface $bban |
||
188 | * |
||
189 | * @throws InvalidArgumentException |
||
190 | */ |
||
191 | private static function validateControlDigit( |
||
202 | |||
203 | /** |
||
204 | * @param $countryCode |
||
205 | * |
||
206 | * @throws InvalidArgumentException |
||
207 | */ |
||
208 | private static function validateSupportedCountry($countryCode) |
||
219 | |||
220 | /** |
||
221 | * @param $countryCode |
||
222 | * @param $checkDigits |
||
223 | * @param BbanInterface $bban |
||
224 | * |
||
225 | * @return string |
||
226 | */ |
||
227 | private static function validateChecksum($countryCode, $checkDigits, BbanInterface $bban) |
||
239 | |||
240 | /** |
||
241 | * @param string $value |
||
242 | * |
||
243 | * @return int |
||
244 | */ |
||
245 | private static function digitToInt($value) |
||
253 | } |
||
254 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: