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
Push — 1.0 ( 527b18...e4ae02 )
by Henrique
17:29
created

Cnpj   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 35
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

1 Method

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