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 (#735)
by Julián
04:37
created

Cnh   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 34
ccs 14
cts 16
cp 0.875
rs 10

1 Method

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