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
02:56
created

Cpf::isValid()   B

Complexity

Conditions 9
Paths 11

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 9

Importance

Changes 0
Metric Value
cc 9
eloc 10
nc 11
nop 1
dl 0
loc 22
ccs 11
cts 11
cp 1
crap 9
rs 8.0555
c 0
b 0
f 0
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