|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Brazanation\Documents; |
|
4
|
|
|
|
|
5
|
|
|
final class Renavam extends AbstractDocument |
|
6
|
|
|
{ |
|
7
|
|
|
const LENGTH = 11; |
|
8
|
|
|
|
|
9
|
|
|
const LABEL = 'Renavam'; |
|
10
|
|
|
|
|
11
|
|
|
const REGEX = '/^([\d]{4})([\d]{6})([\d]{1})$/'; |
|
12
|
|
|
|
|
13
|
|
|
const NUMBER_OF_DIGITS = 1; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Renavam constructor. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $renavam Only accept numbers |
|
19
|
|
|
*/ |
|
20
|
18 |
|
public function __construct($renavam) |
|
21
|
|
|
{ |
|
22
|
18 |
|
$renavam = preg_replace('/\D/', '', $renavam); |
|
23
|
18 |
|
$renavam = $this->padNumber($renavam); |
|
24
|
18 |
|
parent::__construct($renavam, self::LENGTH, self::NUMBER_OF_DIGITS, self::LABEL); |
|
25
|
8 |
|
} |
|
26
|
|
|
|
|
27
|
9 |
|
public static function createFromString($number) |
|
28
|
|
|
{ |
|
29
|
9 |
|
return parent::tryCreateFromString(self::class, $number, self::LENGTH, self::NUMBER_OF_DIGITS, self::LABEL); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Pad left a number to length(11) with 0(ZERO) |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $number |
|
36
|
|
|
* |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
18 |
|
private function padNumber($number) |
|
40
|
|
|
{ |
|
41
|
18 |
|
if (empty($number)) { |
|
42
|
4 |
|
return ''; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
14 |
|
return str_pad($number, self::LENGTH, 0, STR_PAD_LEFT); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function format() |
|
52
|
|
|
{ |
|
53
|
2 |
|
return preg_replace(self::REGEX, '$1.$2-$3', "{$this}"); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
10 |
|
public function calculateDigit($baseNumber) |
|
60
|
|
|
{ |
|
61
|
10 |
|
$calculator = new DigitCalculator($baseNumber); |
|
62
|
|
|
//$calculator->withMultipliers([3, 2, 9, 8, 7, 6, 5, 4, 3, 2]); |
|
|
|
|
|
|
63
|
10 |
|
$calculator->withMultipliers([2, 3, 4, 5, 6, 7, 8, 9, 2, 3]); |
|
64
|
10 |
|
$calculator->replaceWhen('0', 10); |
|
65
|
10 |
|
$calculator->withModule(DigitCalculator::MODULE_11); |
|
66
|
10 |
|
$calculator->multiplySumBy(10); |
|
67
|
10 |
|
$digit = $calculator->calculate(); |
|
68
|
|
|
|
|
69
|
10 |
|
return "{$digit}"; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.