G130::postValidation()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 0
crap 12
1
<?php
2
3
namespace NFePHP\EFD\Elements\ICMSIPI;
4
5
use NFePHP\EFD\Common\Element;
6
use NFePHP\EFD\Common\ElementInterface;
7
use \stdClass;
8
use NFePHP\Common\Keys;
9
10
class G130 extends Element implements ElementInterface
11
{
12
    const REG = 'G130';
13
    const LEVEL = 4;
14
    const PARENT = 'G100';
15
16
    protected $parameters = [
17
        'IND_EMIT' => [
18
            'type' => 'string',
19
            'regex' => '^(0|1)$',
20
            'required' => true,
21
            'info' => 'Indicador do emitente do documento fiscal ' .
22
                ' 0- Emissão própria ' .
23
                ' 1- Terceiros ',
24
            'format' => ''
25
        ],
26
        'COD_PART' => [
27
            'type' => 'string',
28
            'regex' => '^.{1,60}$',
29
            'required' => true,
30
            'info' => 'Código do participante  ' .
31
                ' - do emitente do documento ou do remetente das mercadorias, no caso de entradas ' .
32
                ' - do adquirente, no caso de saídas ',
33
            'format' => ''
34
        ],
35
        'COD_MOD' => [
36
            'type' => 'string',
37
            'regex' => '^.{2}$',
38
            'required' => true,
39
            'info' => 'Código do modelo de documento fiscal, conforme tabela 4.1.1 ',
40
            'format' => ''
41
        ],
42
        'SERIE' => [
43
            'type' => 'string',
44
            'regex' => '^.{0,3}$',
45
            'required' => false,
46
            'info' => 'Série do documento fiscal ',
47
            'format' => ''
48
        ],
49
        'NUM_DOC' => [
50
            'type' => 'numeric',
51
            'regex' => '^(\d{1,9})$',
52
            'required' => true,
53
            'info' => 'Número de documento fiscal ',
54
            'format' => ''
55
        ],
56
        'CHV_NFE_CTE' => [
57
            'type' => 'numeric',
58
            'regex' => '^([0-9]{44})?$',
59
            'required' => false,
60
            'info' => 'Chave do documento fiscal eletrônico ',
61
            'format' => ''
62
        ],
63
        'DT_DOC' => [
64
            'type' => 'string',
65
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
66
            'required' => true,
67
            'info' => 'Data da emissão do documento fiscal ',
68
            'format' => ''
69
        ],
70
        'NUM_DA' => [
71
            'type'     => 'string',
72
            'regex'    => '^[0-9]{0}$',
73
            'required' => true,
74
            'info'     => 'Número do documento de arrecadação estadual, se houver',
75
            'format'   => ''
76
        ]
77
    ];
78
79
    /**
80
     * Constructor
81
     * @param \stdClass $std
82
     */
83
    public function __construct(\stdClass $std)
84
    {
85
        parent::__construct(self::REG);
86
        $this->std = $this->standarize($std);
87
        $this->postValidation();
88
    }
89
90
    public function postValidation()
91
    {
92
        if (!empty($this->std->chv_nfe_cte) and !Keys::isValid($this->std->chv_nfe_cte)) {
93
            throw new \InvalidArgumentException("[" . self::REG . "] " .
94
                " Dígito verificador incorreto no campo chave do " .
95
                " campo CHV_NFE_CTE");
96
        }
97
    }
98
}
99