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

Passed
Pull Request — master (#1087)
by Henrique
03:56 queued 01:10
created

Cnh   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 11
eloc 14
dl 0
loc 35
c 0
b 0
f 0
ccs 13
cts 15
cp 0.8667
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isValid() 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
use function is_scalar;
17
use function mb_strlen;
18
use function preg_replace;
19
20
/**
21
 * Validates a Brazilian driver's license.
22
 *
23
 * @author Gabriel Pedro <[email protected]>
24
 * @author Henrique Moody <[email protected]>
25
 * @author Kinn Coelho Julião <[email protected]>
26
 * @author William Espindola <[email protected]>
27
 */
28
final class Cnh extends AbstractRule
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33 100
    public function isValid($input): bool
34
    {
35 100
        if (!is_scalar($input)) {
36 2
            return false;
37
        }
38
39
        // Canonicalize input
40 98
        $input = preg_replace('{\D}', '', (string) $input);
41
42
        // Validate length and invalid numbers
43 98
        if ((11 != mb_strlen($input)) || (0 === (int) $input)) {
44 74
            return false;
45
        }
46
47
        // Validate check digits using a modulus 11 algorithm
48 25
        for ($c = $s1 = $s2 = 0, $p = 9; $c < 9; $c++, $p--) {
49 25
            $s1 += (int) $input[$c] * $p;
50 25
            $s2 += (int) $input[$c] * (10 - $p);
51
        }
52
53 25
        if ($input[9] != (($dv1 = $s1 % 11) > 9) ? 0 : $dv1) {
54
            return false;
55
        }
56
57 25
        if ($input[10] != (((($dv2 = ($s2 % 11) - (($dv1 > 9) ? 2 : 0)) < 0)
58 25
                ? $dv2 + 11 : $dv2) > 9) ? 0 : $dv2) {
59
            return false;
60
        }
61
62 25
        return true;
63
    }
64
}
65