|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* BC holds a Swiss bank clearing number |
|
7
|
|
|
*/ |
|
8
|
|
|
class BC implements FinancialInstitutionInterface |
|
9
|
|
|
{ |
|
10
|
|
|
const PATTERN = '/^[0-9]{3,5}$/'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var int |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $bc; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Constructor |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $bic |
|
|
|
|
|
|
21
|
|
|
* |
|
22
|
|
|
* @throws \InvalidArgumentException When the BC does contain invalid characters or the length does not match. |
|
23
|
|
|
*/ |
|
24
|
5 |
|
public function __construct($bc) |
|
25
|
|
|
{ |
|
26
|
5 |
|
$bc = (string) $bc; |
|
27
|
5 |
|
if (!preg_match(self::PATTERN, $bc)) { |
|
28
|
2 |
|
throw new \InvalidArgumentException('BC is not properly formatted.'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
3 |
|
$this->bc = (int) ltrim($bc, '0'); |
|
32
|
3 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Extracts the BC from an IBAN |
|
36
|
|
|
* |
|
37
|
|
|
* @param IBAN $iban |
|
38
|
|
|
* |
|
39
|
|
|
* @throws \InvalidArgumentException When the supplied IBAN is not from Switzerland |
|
40
|
|
|
*/ |
|
41
|
4 |
|
public static function fromIBAN(IBAN $iban) |
|
42
|
|
|
{ |
|
43
|
4 |
|
if ($iban->getCountry() !== 'CH') { |
|
44
|
1 |
|
throw new \InvalidArgumentException('BC can only be extracted from Swiss IBANs.'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
3 |
|
return new self(substr($iban->normalize(), 4, 5)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns a formatted representation of the BIC |
|
52
|
|
|
* |
|
53
|
|
|
* @return string The formatted BIC |
|
54
|
|
|
*/ |
|
55
|
3 |
|
public function format() |
|
56
|
|
|
{ |
|
57
|
3 |
|
return sprintf('%d', $this->bc); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function asDom(\DOMDocument $doc) |
|
64
|
|
|
{ |
|
65
|
2 |
|
$xml = $doc->createElement('FinInstnId'); |
|
66
|
2 |
|
$clearingSystem = $doc->createElement('ClrSysMmbId'); |
|
67
|
2 |
|
$clearingSystemId = $doc->createElement('ClrSysId'); |
|
68
|
2 |
|
$clearingSystemId->appendChild($doc->createElement('Cd', 'CHBCC')); |
|
69
|
2 |
|
$clearingSystem->appendChild($clearingSystemId); |
|
70
|
2 |
|
$clearingSystem->appendChild($doc->createElement('MmbId', $this->format())); |
|
71
|
2 |
|
$xml->appendChild($clearingSystem); |
|
72
|
|
|
|
|
73
|
2 |
|
return $xml; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.