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
03:56 queued 01:10
created

Pis::validate()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 23
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 9.2222
cc 6
nc 6
nop 1
crap 6
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
/**
17
 * Validates a Brazilian PIS/NIS number.
18
 *
19
 * @author Bruno Koga <[email protected]>
20
 * @author Henrique Moody <[email protected]>
21
 */
22
class Pis extends AbstractRule
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 36
    public function isValid($input): bool
28
    {
29 36
        if (!is_scalar($input)) {
30 2
            return false;
31
        }
32
33 34
        $digits = preg_replace('/\D/', '', $input);
34 34
        if (11 != mb_strlen($digits) || preg_match("/^{$digits[0]}{11}$/", $digits)) {
35 13
            return false;
36
        }
37
38 21
        $multipliers = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
39
40 21
        $summation = 0;
41 21
        for ($position = 0; $position < 10; ++$position) {
42 21
            $summation += $digits[$position] * $multipliers[$position];
43
        }
44
45 21
        $checkDigit = (int) $digits[10];
46
47 21
        $modulo = $summation % 11;
48
49 21
        return $checkDigit === (($modulo < 2) ? 0 : 11 - $modulo);
50
    }
51
}
52