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 — 0.9 (#692)
by
unknown
02:58
created

Cnpj::validate()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 5.7377
cc 8
eloc 12
nc 11
nop 1
crap 8
1
<?php
2
namespace Respect\Validation\Rules;
3
4
class Cnpj extends AbstractRule
5
{
6 24
    public function validate($input)
7
    {
8
        //Code ported from jsfromhell.com
9 24
        $c = preg_replace('/\D/', '', $input);
10 24
        $b = array(6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2);
11
12 24
        if (strlen($c) != 14) {
13 11
            return false;
14
        }
15
16 13
        for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]);
17
18 13
        if ($c[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
19 1
            return false;
20
        }
21
22 12
        for ($i = 0, $n = 0; $i <= 12; $n += $c[$i] * $b[$i++]);
23
24 12
        if ($c[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
25 1
            return false;
26
        }
27
28 11
        return true;
29
    }
30
}
31