Completed
Pull Request — master (#5)
by
unknown
01:43
created

Modulo97::readNumber()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace byrokrat\checkdigit;
6
7
/**
8
 * Modulo97 calculator
9
 */
10
class Modulo97 extends Base implements Calculator
11
{
12
    /**
13
     * Check if the last two digits of number are valid modulo 97 check digits
14
     *
15
     * @throws InvalidStructureException If $number is not numerical
16
     */
17 5
    public function isValid(string $number): bool
18
    {
19 5
        $this->validateNumber($number);
20
        return bcmod($number, '97') === '1';
21
    }
22
23
    /**
24
     * Calculate the modulo 97 check digits for number
25
     *
26
     * @throws InvalidStructureException If $number is not numerical
27
     */
28 5
    public function calculateCheckDigit(string $number): string
29
    {
30 5
        $this->validateNumber($number);
31
        return (string)(98 - bcmod($number.'00', '97'));
32
    }
33
}
34