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 — 1.1 ( fca464...0e73bc )
by Henrique
09:36 queued 06:14
created

NfeAccessKey::validate()   B

Complexity

Conditions 8
Paths 41

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 8

Importance

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