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 (#868)
by Henrique
08:02
created

Luhn   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 22 5
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Respect\Validation\Rules;
13
14
/**
15
 * @link https://en.wikipedia.org/wiki/Luhn_algorithm
16
 */
17
class Luhn extends AbstractRule
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function validate($input)
23
    {
24
        if (!(new Digit())->validate($input)) {
25
            return false;
26
        }
27
28
        $sum = 0;
29
        $numDigits = strlen($input);
30
        $parity = $numDigits % 2;
31
        for ($i = 0; $i < $numDigits; $i++) {
32
            $digit = substr($input, $i, 1);
33
            if ($parity == ($i % 2)) {
34
                $digit <<= 1;
35
                if (9 < $digit) {
36
                    $digit = $digit - 9;
37
                }
38
            }
39
            $sum += $digit;
40
        }
41
42
        return (0 == ($sum % 10));
43
    }
44
}
45