Completed
Push — master ( c29bcc...91a13a )
by Hannes
24s queued 22s
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 implements Calculator
11
{
12
    use AssertionsTrait;
13
14
    /**
15
     * Check if the last two digits of number are valid modulo 97 check digits
16
     *
17
     * @throws InvalidStructureException If $number is not numerical
18
     */
19 6
    public function isValid(string $number): bool
20
    {
21 6
        $this->assertNumber($number);
22 1
        return bcmod($number, '97') === '1';
23
    }
24
25
    /**
26
     * Calculate the modulo 97 check digits for number
27
     *
28
     * @throws InvalidStructureException If $number is not numerical
29
     */
30 6
    public function calculateCheckDigit(string $number): string
31
    {
32 6
        $this->assertNumber($number);
33 1
        return (string)(98 - bcmod($number.'00', '97'));
34
    }
35
}
36