Completed
Pull Request — master (#19)
by Antonio Oertel
03:14
created

SaoPaulo   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 12
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 104
ccs 27
cts 27
cp 1
rs 10

11 Methods

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