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

StateRegistration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 5
c 3
b 1
f 2
lcom 1
cbo 2
dl 0
loc 56
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A extractBaseNumber() 0 4 1
A extractCheckerDigit() 0 4 1
A format() 0 4 1
A calculateDigit() 0 6 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