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 (#691)
by
unknown
07:33
created

Cnh::validate()   C

Complexity

Conditions 7
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
ccs 19
cts 19
cp 1
rs 6.7272
c 1
b 0
f 0
cc 7
eloc 15
nc 3
nop 1
crap 7
1
<?php
2
namespace Respect\Validation\Rules;
3
4
class Cnh extends AbstractRule
5
{
6 96
    public function validate($input)
7
    {
8 96
        $ret = false;
9
10 96
        if ((strlen($input = preg_replace('/[^\d]/', '', $input)) == 11)
11 96
            && (str_repeat($input[1], 11) != $input)) {
12 48
            $dsc = 0;
13 48
            for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) {
14 48
                $v += (int) $input[$i] * $j;
15 48
            }
16
17 48
            if (($vl1 = $v % 11) >= 10) {
18 4
                $vl1 = 0;
19 4
                $dsc = 2;
20 4
            }
21
22 48
            for ($i = 0, $j = 1, $v = 0; $i < 9; ++$i, ++$j) {
23 48
                $v += (int) $input[$i] * $j;
24 48
            }
25
26 48
            $vl2 = ($x = ($v % 11)) >= 10 ? 0 : $x - $dsc;
27 48
            $ret = sprintf('%d%d', $vl1, $vl2) == substr($input, -2);
28 48
        }
29
30 96
        return $ret;
31
    }
32
}
33