Completed
Push — wip ( 681ec1 )
by z38
02:37
created

CreditorReference::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Z38\SwissPayment;
4
5
/**
6
 * CreditorReference is a reference based on ISO 11649.
7
 */
8
class CreditorReference
9
{
10
    const PATTERN = '/^RF[0-9]{2}[0-9A-Z]{1,21}$/';
11
12
    /**
13
     * @var string
14
     */
15
    protected $reference;
16
17
    /**
18
     * @param string $reference
19
     *
20
     * @throws \InvalidArgumentException When the reference is invalid.
21
     */
22 2
    public function __construct($reference)
23
    {
24 2
        if (!preg_match(self::PATTERN, $reference)) {
25
            throw new \InvalidArgumentException('Creditor reference is not properly formatted.');
26
        }
27
28 2
        $this->reference = $reference;
29 2
    }
30
31
    /**
32
     * Returns a formatted representation of the reference
33
     *
34
     * @return string
35
     */
36
    public function format()
37
    {
38
        return $this->reference;
39
    }
40
}
41