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

QRReference::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.032
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