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 (#807)
by Henrique
04:45
created

Pis   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 24 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
namespace Respect\Validation\Rules;
13
14
/**
15
 * Validates a Brazilian PIS/NIS number.
16
 *
17
 * @author Bruno Koga <[email protected]>
18
 * @author Henrique Moody <[email protected]>
19
 */
20
class Pis extends AbstractRule
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 31
    public function validate($input)
26
    {
27 31
        if (!is_scalar($input)) {
28 2
            return false;
29
        }
30
31 29
        $digits = preg_replace('/\D/', '', $input);
32 29
        if (mb_strlen($digits) != 11 || preg_match("/^{$digits[0]}{11}$/", $digits)) {
33 11
            return false;
34
        }
35
36 18
        $multipliers = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
37
38 18
        $summation = 0;
39 18
        for ($position = 0; $position < 10; ++$position) {
40 18
            $summation += $digits[$position] * $multipliers[$position];
41
        }
42
43 18
        $checkDigit = (int) $digits[10];
44
45 18
        $modulo = $summation % 11;
46
47 18
        return $checkDigit === (($modulo < 2) ? 0 : 11 - $modulo);
48
    }
49
}
50