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
Push — master ( c82842...b8da3a )
by Henrique
05:59
created

Pesel::validate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

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