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:45
created

Pesel::validate()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 27
ccs 15
cts 15
cp 1
rs 8.439
cc 5
eloc 14
nc 5
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 2
            return false;
20
        }
21
22 13
        if (!filter_var($input, FILTER_VALIDATE_INT)) {
23 2
            return false;
24
        }
25
26 11
        if (strlen($input) != 11) {
27 2
            return false;
28
        }
29
30 9
        $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
31
32 9
        $targetControlNumber = $input[10];
33 9
        $calculateControlNumber = 0;
34
35 9
        for ($i = 0; $i < 10; $i++) {
36 9
            $calculateControlNumber += $input[$i] * $weights[$i];
37 9
        }
38
39 9
        $calculateControlNumber = (10 - $calculateControlNumber % 10) % 10;
40
41 9
        return $targetControlNumber == $calculateControlNumber;
42
    }
43
}
44