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

StateRegistration::extractCheckerDigit()   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;
4
5
use Brazanation\Documents\StateRegistration\StateInterface;
6
7
/**
8
 * Class StateRegistration
9
 *
10
 * @package Brazanation\Documents
11
 *
12
 * @method StateRegistration AC($number)
13
 */
14
final class StateRegistration extends AbstractDocument implements DocumentInterface
15
{
16
    /**
17
     * @var StateInterface
18
     */
19
    private $state;
20
21
    /**
22
     * StateRegistration constructor.
23
     *
24
     * @param string         $number
25
     * @param StateInterface $state
26
     */
27 476
    public function __construct($number, StateInterface $state)
28
    {
29 476
        $number = $state->normalizeNumber($number);
30 476
        $this->state = $state;
31 476
        parent::__construct($number, $state->getLength(), $state->getNumberOfDigits(), $state->getState());
32 383
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 398
    protected function extractBaseNumber($number)
38
    {
39 398
        return $this->state->extractBaseNumber($number);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 476
    protected function extractCheckerDigit($number)
46
    {
47 476
        return $this->state->extractCheckerDigit($number);
48
    }
49
50
    /**
51
     * Voter does not has a specific format.
52
     *
53
     * @return string Returns only numbers.
54
     */
55 41
    public function format()
56
    {
57 41
        return preg_replace($this->state->getRegex(), $this->state->getFormat(), "{$this}");
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 398
    public function calculateDigit($baseNumber)
64
    {
65 398
        $digit = $this->state->calculateDigit($baseNumber);
66
67 398
        return "{$digit}";
68
    }
69
}
70