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 (#923)
by lee
03:57
created

Cnh   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 32
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C validate() 0 30 11
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
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
class Cnh extends AbstractRule
17
{
18 101
    public function validate($input): bool
19
    {
20 101
        if (!is_scalar($input)) {
21 2
            return false;
22
        }
23
24
        // Canonicalize input
25 99
        $input = preg_replace('{\D}', '', (string) $input);
26
27
        // Validate length and invalid numbers
28 99
        if ((11 != mb_strlen($input)) || (0 == intval($input))) {
29 73
            return false;
30
        }
31
32
        // Validate check digits using a modulus 11 algorithm
33 26
        for ($c = $s1 = $s2 = 0, $p = 9; $c < 9; $c++, $p--) {
34 26
            $s1 += intval($input[$c]) * $p;
35 26
            $s2 += intval($input[$c]) * (10 - $p);
36
        }
37
38 26
        if ($input[9] != (($dv1 = $s1 % 11) > 9) ? 0 : $dv1) {
39 1
            return false;
40
        }
41
42 25
        if ($input[10] != (((($dv2 = ($s2 % 11) - (($dv1 > 9) ? 2 : 0)) < 0)
43 25
                ? $dv2 + 11 : $dv2) > 9) ? 0 : $dv2) {
44 1
            return false;
45
        }
46
47 24
        return true;
48
    }
49
}
50