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

QRReference   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 35
ccs 6
cts 7
cp 0.8571
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
 * QRReference
7
 */
8
class QRReference
9
{
10
    const PATTERN = '/^[0-9]{27}$/';
11
12
    /**
13
     * @var string
14
     */
15
    protected $reference;
16
17
    /**
18
     * Constructor
19
     *
20
     * @param string $reference
21
     *
22
     * @throws \InvalidArgumentException When the reference is invalid.
23
     */
24 2
    public function __construct($reference)
25
    {
26 2
        if (!preg_match(self::PATTERN, $reference)) {
27
            throw new \InvalidArgumentException('QR reference is not properly formatted.');
28
        }
29
30 2
        $this->reference = $reference;
31 2
    }
32
33
    /**
34
     * Returns a formatted representation of the reference
35
     *
36
     * @return string
37
     */
38 2
    public function format()
39
    {
40 2
        return $this->reference;
41
    }
42
}
43