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

Pesel::validate()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 8.7624
cc 5
eloc 12
nc 3
nop 1
crap 5
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
class Pesel extends AbstractRule
15
{
16 15
    public function validate($input)
17
    {
18 15
        if (!is_numeric($input)
19 15
            || !filter_var($input, FILTER_VALIDATE_INT)
20 15
            || strlen($input) != 11) {
21 6
            return false;
22
        }
23
24 9
        $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
25
26 9
        $targetControlNumber = $input[10];
27 9
        $calculateControlNumber = 0;
28
29 9
        for ($i = 0; $i < 10; $i++) {
30 9
            $calculateControlNumber += $input[$i] * $weights[$i];
31 9
        }
32
33 9
        $calculateControlNumber = (10 - $calculateControlNumber % 10) % 10;
34
35 9
        return $targetControlNumber == $calculateControlNumber;
36
    }
37
}
38