Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#850)
by
unknown
06:21
created

Luhn   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 40
c 0
b 0
f 0
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 10 2
A verifyMod10() 0 19 4
1
<?php
2
3
namespace Respect\Validation\Rules;
4
5
class Luhn extends AbstractRule
6
{
7
    public function validate($input)
8
    {
9
        $input = preg_replace('([^0-9])', '', $input);
10
11
        if (empty($input)) {
12
            return false;
13
        }
14
15
        return $this->verifyMod10($input);
16
    }
17
18
    /**
19
     * Returns whether the input matches the Luhn algorithm or not.
20
     *
21
     * @param string $input
22
     *
23
     * @return bool
24
     */
25
    private function verifyMod10($input)
26
    {
27
        $sum = 0;
28
        $input = strrev($input);
29
        for ($i = 0, $inputLength = mb_strlen($input); $i < $inputLength; ++$i) {
30
            $current = mb_substr($input, $i, 1);
31
            if ($i % 2 === 1) {
32
                $current *= 2;
33
                if ($current > 9) {
34
                    $firstDigit = $current % 10;
35
                    $secondDigit = ($current - $firstDigit) / 10;
36
                    $current = $firstDigit + $secondDigit;
37
                }
38
            }
39
            $sum += $current;
40
        }
41
42
        return $sum % 10 === 0;
43
    }
44
}
45