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

CreditorReference   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 33
ccs 4
cts 7
cp 0.5714
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A format() 0 4 1
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