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

Passed
Pull Request — master (#1087)
by Henrique
09:28
created

NfeAccessKey::validate()   B

Complexity

Conditions 8
Paths 41

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 8

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 21
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 8.4444
cc 8
nc 41
nop 1
crap 8
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
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
/**
17
 * Rule restrict to Brasil.
18
 *
19
 * Valida chave de acesso de NFe.
20
 * Mais especificamente, relacionada ao DANFE.
21
 */
22
class NfeAccessKey extends AbstractRule
23
{
24
    /**
25
     * @see Manual de Integração do Contribuinte v4.0.1 (http://www.nfe.fazenda.gov.br)
26
     *
27
     * @param string $aK access key
28
     *
29
     * @return bool
30
     */
31 20
    public function isValid($aK): bool
32
    {
33 20
        if (44 !== mb_strlen($aK)) {
34 10
            return false;
35
        }
36
37 10
        $w = [];
38 10
        for ($i = 0, $z = 5, $m = 43; $i <= $m; ++$i) {
39 10
            $z = ($i < $m) ? 1 == ($z - 1) ? 9 : ($z - 1) : 0;
40 10
            $w[] = $z;
41
        }
42
43 10
        for ($i = 0, $s = 0, $k = 44; $i < $k; ++$i) {
44 10
            $s += $aK[$i]
45 10
            * $w[$i];
46
        }
47
48 10
        $s -= (11 * floor($s / 11));
49 10
        $v = (0 == $s || 1 == $s) ? 0 : (11 - $s);
0 ignored issues
show
introduced by
The condition 0 == $s is always true.
Loading history...
50
51 10
        return $v == $aK[43];
52
    }
53
}
54