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

Modulo97   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 24
ccs 4
cts 6
cp 0.6667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 5 1
A calculateCheckDigit() 0 5 1
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