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

Cnpj   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D validate() 0 31 10
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 Cnpj extends AbstractRule
17
{
18 33
    public function validate($input): bool
19
    {
20 33
        if (!is_scalar($input)) {
21 1
            return false;
22
        }
23
24
        // Code ported from jsfromhell.com
25 32
        $cleanInput = preg_replace('/\D/', '', $input);
26 32
        $b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
27
28 32
        if ($cleanInput < 1) {
29 1
            return false;
30
        }
31
32 31
        if (14 != mb_strlen($cleanInput)) {
33 5
            return false;
34
        }
35
36 26
        for ($i = 0, $n = 0; $i < 12; $n += $cleanInput[$i] * $b[++$i]);
37
38 26
        if ($cleanInput[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
39 14
            return false;
40
        }
41
42 12
        for ($i = 0, $n = 0; $i <= 12; $n += $cleanInput[$i] * $b[$i++]);
43
44 12
        if ($cleanInput[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
45 1
            return false;
46
        }
47
48 11
        return true;
49
    }
50
}
51