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 (#1087)
by Henrique
09:28
created

Cpf   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 10
dl 0
loc 27
c 0
b 0
f 0
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isValid() 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
use function mb_strlen;
17
use function preg_match;
18
use function preg_replace;
19
20
/**
21
 * Validates whether the input is a CPF (Brazilian Natural Persons Register) number.
22
 *
23
 * @author Alexandre Gomes Gaigalas <[email protected]>
24
 * @author Henrique Moody <[email protected]>
25
 * @author Jair Henrique <[email protected]>
26
 * @author Jayson Reis <[email protected]>
27
 * @author Jean Pimentel <[email protected]>
28
 * @author William Espindola <[email protected]>
29
 */
30
final class Cpf extends AbstractRule
31
{
32
    /**
33
     * {@inheritdoc}
34
     */
35 28
    public function isValid($input): bool
36
    {
37
        // Code ported from jsfromhell.com
38 28
        $c = preg_replace('/\D/', '', $input);
39
40 28
        if (11 != mb_strlen($c) || preg_match("/^{$c[0]}{11}$/", $c)) {
41 11
            return false;
42
        }
43
44 18
        for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
45
46 18
        if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
47 4
            return false;
48
        }
49
50 14
        for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
51
52 14
        if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
53 3
            return false;
54
        }
55
56 11
        return true;
57
    }
58
}
59