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 (#957)
by Henrique
02:12
created

Cpf   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 24
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C validate() 0 22 9
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