BIC   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A format() 0 4 1
A asDom() 0 7 1
1
<?php
2
3
namespace Z38\SwissPayment;
4
5
/**
6
 * BIC
7
 */
8
class BIC implements FinancialInstitutionInterface
9
{
10
    const PATTERN = '/^[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}$/';
11
12
    /**
13
     * @var string
14
     */
15
    protected $bic;
16
17
    /**
18
     * Constructor
19
     *
20
     * @param string $bic
21
     *
22
     * @throws \InvalidArgumentException When the BIC does contain invalid characters or the length does not match.
23
     */
24 8
    public function __construct($bic)
25
    {
26 8
        if (!preg_match(self::PATTERN, $bic)) {
27 2
            throw new \InvalidArgumentException('BIC is not properly formatted.');
28
        }
29
30 6
        $this->bic = $bic;
31 6
    }
32
33
    /**
34
     * Returns a formatted representation of the BIC
35
     *
36
     * @return string The formatted BIC
37
     */
38 5
    public function format()
39
    {
40 5
        return $this->bic;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function asDom(\DOMDocument $doc)
47
    {
48 2
        $xml = $doc->createElement('FinInstnId');
49 2
        $xml->appendChild($doc->createElement('BIC', $this->format()));
50
51 2
        return $xml;
52
    }
53
}
54