Completed
Pull Request — master (#274)
by
unknown
10:53
created

C465::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NFePHP\EFD\Elements\ICMSIPI;
4
5
use NFePHP\Common\Keys;
6
use NFePHP\EFD\Common\Element;
7
use NFePHP\EFD\Common\ElementInterface;
8
use \stdClass;
9
10
class C465 extends Element implements ElementInterface
11
{
12
    const REG = 'C465';
13
    const LEVEL = 5;
14
    const PARENT = 'C460';
15
16
    protected $parameters = [
17
        'CHV_CFE' => [
18
            'type' => 'numeric',
19
            'regex' => '^([0-9]{44})?$',
20
            'required' => true,
21
            'info' => 'Chave do Cupom Fiscal Eletrônico',
22
            'format' => ''
23
        ],
24
        'NUM_CCF' => [
25
            'type' => 'numeric',
26
            'regex' => '^(\d{1,9})$',
27
            'required' => true,
28
            'info' => 'Número do Contador de Cupom Fiscal',
29
            'format' => ''
30
        ],
31
    ];
32
33
    /**
34
     * Constructor
35
     * @param \stdClass $std
36
     */
37
    public function __construct(\stdClass $std)
38
    {
39
        parent::__construct(self::REG);
40
        $this->std = $this->standarize($std);
41
        $this->postValidation();
42
    }
43
44
    public function postValidation()
45
    {
46
47
        /**
48
         * Verifica a chave cfe
49
         */
50
        if ($this->std->chv_cfe and !Keys::isValid($this->std->chv_cfe)) {
51
            throw new \InvalidArgumentException("[" . self::REG . "] " .
52
                " Dígito verificador incorreto no da Chave " .
53
                "do Cupom Fiscal Eletrônico (CHV_CFE)");
54
        }
55
    }
56
}
57