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 — 0.9 (#692)
by
unknown
02:58
created

CreditCard::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
namespace Respect\Validation\Rules;
3
4
class CreditCard extends AbstractRule
5
{
6 10
    public function validate($input)
7
    {
8 10
        $input = preg_replace('([^0-9])', '', $input);
9 10
        if (!empty($input)) {
10 8
            return $this->verifyMod10($input);
11
        }
12
13 2
        return false;
14
    }
15
16 8
    private function verifyMod10($input)
17
    {
18 8
        $sum = 0;
19 8
        $input = strrev($input);
20 8
        for ($i = 0; $i < strlen($input); $i++) {
21 8
            $current = substr($input, $i, 1);
22 8
            if ($i % 2 == 1) {
23 7
                $current *= 2;
24 7
                if ($current > 9) {
25 5
                    $firstDigit = $current % 10;
26 5
                    $secondDigit = ($current - $firstDigit) / 10;
27 5
                    $current = $firstDigit + $secondDigit;
28 5
                }
29 7
            }
30 8
            $sum += $current;
31 8
        }
32
33 8
        return ($sum % 10 == 0);
34
    }
35
}
36