Completed
Push — scrutinizer ( 42ac6a...7bc18e )
by z38
02:40
created

BIC::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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 7
    public function __construct($bic)
25
    {
26 7
        if (!preg_match(self::PATTERN, $bic)) {
27 2
            throw new \InvalidArgumentException('BIC is not properly formatted.');
28
        }
29
30 5
        $this->bic = $bic;
31 5
    }
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