Passed
Push — master ( 5ee16c...ec5b4c )
by Antonio Oertel
32s
created

SaoPaulo::normalizeNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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