Completed
Push — master ( c29bcc...91a13a )
by Hannes
24s queued 22s
created

Modulo10Gtin::calculateCheckDigit()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 23

Duplication

Lines 3
Ratio 13.04 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
dl 3
loc 23
ccs 12
cts 12
cp 1
rs 9.2408
c 0
b 0
f 0
cc 5
nc 7
nop 1
crap 5
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace byrokrat\checkdigit;
6
7
/**
8
 * Modulo10 calculator, variant used for GTIN (EAN, UPC, ISBN-13, JAN and ITF) barcodes
9
 */
10
class Modulo10Gtin extends Modulo10
11
{
12 2
    protected function calculateSum(string $number): int
13
    {
14 2
        $sum = 0;
15
16 2 View Code Duplication
        foreach (array_reverse(str_split($number)) as $pos => $digit) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17 2
            $sum += $digit * ($pos % 2 ? 1 : 3);
18
        }
19
20 2
        return $sum;
21
    }
22
}
23