Pernambuco::getRegex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Brazanation\Documents\StateRegistration;
4
5
use Brazanation\Documents\StateRegistration\Pernambuco\EFisco;
6
use Brazanation\Documents\StateRegistration\Pernambuco\Old;
7
8
final class Pernambuco implements StateInterface
9
{
10
    const LONG_NAME = 'Pernambuco';
11
12
    const SHORT_NAME = 'PE';
13
14
    /**
15
     * @var State
16
     */
17
    private $calculation;
18
19 22
    public function __construct()
20
    {
21 22
        $this->calculation = new EFisco();
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 22
    public function getState() : string
28
    {
29 22
        return $this->calculation->getState();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 22
    public function normalizeNumber(string $number) : string
36
    {
37 22
        $this->defineStrategy($number);
38
39 22
        return $this->calculation->normalizeNumber($number);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 22
    public function getLength() : int
46
    {
47 22
        return $this->calculation->getLength();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 4
    public function getFormat() : string
54
    {
55 4
        return $this->calculation->getFormat();
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 22
    public function getNumberOfDigits() : int
62
    {
63 22
        return $this->calculation->getNumberOfDigits();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 4
    public function getRegex() : string
70
    {
71 4
        return $this->calculation->getRegex();
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     *
77
     * @see http://www.sintegra.gov.br/Cad_Estados/cad_PE.html
78
     */
79 20
    public function calculateDigit(string $baseNumber) : string
80
    {
81 20
        return $this->calculation->calculateDigit($baseNumber);
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 22
    public function extractBaseNumber(string $number) : string
88
    {
89 22
        return $this->calculation->extractBaseNumber($number);
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 22
    public function extractCheckerDigit(string $number) : string
96
    {
97 22
        return $this->calculation->extractCheckerDigit($number);
98
    }
99
100
    /**
101
     * It will load calculation strategy based on number format.
102
     *
103
     * @param string $number Number of document.
104
     */
105 22
    private function defineStrategy(string $number)
106
    {
107 22
        $number = preg_replace('/\D/', '', $number);
108 22
        if ($this->calculation->getLength() != strlen($number)) {
109 18
            $this->calculation = new Old();
110
        }
111
    }
112
}
113