Completed
Push — master ( c756b3...e0ace5 )
by Hannes
19s queued 18s
created

Modulo97::calculateCheckDigit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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 6
    public function isValid(string $number): bool
18
    {
19 6
        $this->assertNumber($number);
20 1
        return bcmod($number, '97') === '1';
21
    }
22
23
    /**
24
     * Calculate the modulo 97 check digits for number
25
     */
26 6
    public function calculateCheckDigit(string $number): string
27
    {
28 6
        $this->assertNumber($number);
29 1
        return (string)(98 - bcmod($number.'00', '97'));
30
    }
31
}
32