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 — 0.9 (#694)
by
unknown
03:32
created

NfeAccessKey::validate()   C

Complexity

Conditions 8
Paths 41

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 8

Importance

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