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 (#732)
by Henrique
09:45 queued 04:52
created

PlVatin::validate()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 13
cts 13
cp 1
rs 8.7972
cc 4
eloc 12
nc 4
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\Locale;
13
14
use Respect\Validation\Rules\AbstractRule;
15
16
/**
17
 * Validator for Polish VAT identification number (NIP).
18
 *
19
 * @link https://en.wikipedia.org/wiki/VAT_identification_number
20
 */
21
final class PlVatin extends AbstractRule
22
{
23 11
    public function validate($input)
24
    {
25 11
        if (!is_scalar($input)) {
26 2
            return false;
27
        }
28
29 9
        if (!preg_match('/^\d{10}$/', (string) $input)) {
30 2
            return false;
31
        }
32
33 7
        $weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
34
35 7
        $targetControlNumber = $input[9];
36 7
        $calculateControlNumber = 0;
37
38 7
        for ($i = 0; $i < 9; ++$i) {
39 7
            $calculateControlNumber += $input[$i] * $weights[$i];
40 7
        }
41
42 7
        $calculateControlNumber = $calculateControlNumber % 11;
43
44 7
        return $targetControlNumber == $calculateControlNumber;
45
    }
46
}
47