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

Modulo10Gtin::calculateSum()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 3
Ratio 30 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 3
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
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