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

Tocantins::calculateDigit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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