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 (#941)
by Henrique
03:04 queued 45s
created

Cpf::validate()   C

Complexity

Conditions 9
Paths 11

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 9.0608

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 10
cts 11
cp 0.9091
rs 6.412
c 0
b 0
f 0
cc 9
eloc 10
nc 11
nop 1
crap 9.0608
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 Cpf extends AbstractRule
17
{
18 17
    public function validate($input): bool
19
    {
20
        // Code ported from jsfromhell.com
21 17
        $c = preg_replace('/\D/', '', $input);
22
23 17
        if (11 != mb_strlen($c) || preg_match("/^{$c[0]}{11}$/", $c)) {
24 10
            return false;
25
        }
26
27 7
        for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
28
29 7
        if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
30 4
            return false;
31
        }
32
33 3
        for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
34
35 3
        if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
36 3
            return false;
37
        }
38
39
        return true;
40
    }
41
}
42