SaoPaulo   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
dl 0
loc 103
ccs 25
cts 25
cp 1
rs 10
c 1
b 0
f 1
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getNumberOfDigits() 0 3 1
A defineStrategy() 0 4 2
A calculateDigit() 0 3 1
A getState() 0 3 1
A extractCheckerDigit() 0 3 1
A getRegex() 0 3 1
A extractBaseNumber() 0 3 1
A getFormat() 0 3 1
A getLength() 0 3 1
A normalizeNumber() 0 7 1
A __construct() 0 3 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 12
    public function __construct()
20
    {
21 12
        $this->calculation = new Urban();
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 12
    public function normalizeNumber(string $number) : string
28
    {
29 12
        $this->defineStrategy($number);
30
31 12
        $number = $this->calculation->normalizeNumber($number);
32
33 12
        return $number;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 12
    public function getState() : string
40
    {
41 12
        return $this->calculation->getState();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 12
    public function extractBaseNumber(string $number) : string
48
    {
49 12
        return $this->calculation->extractBaseNumber($number);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 12
    public function extractCheckerDigit(string $number) : string
56
    {
57 12
        return $this->calculation->extractCheckerDigit($number);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 12
    public function getLength() : int
64
    {
65 12
        return $this->calculation->getLength();
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 4
    public function getFormat() : string
72
    {
73 4
        return $this->calculation->getFormat();
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 12
    public function getNumberOfDigits() : int
80
    {
81 12
        return $this->calculation->getNumberOfDigits();
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 4
    public function getRegex() : string
88
    {
89 4
        return $this->calculation->getRegex();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     *
95
     * @see http://www.sintegra.gov.br/Cad_Estados/cad_SP.html
96
     */
97 10
    public function calculateDigit(string $baseNumber) : string
98
    {
99 10
        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 12
    private function defineStrategy(string $number)
108
    {
109 12
        if (strpos($number, 'P') !== false) {
110 4
            $this->calculation = new Rural();
111
        }
112
    }
113
}
114