C116   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 70
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A postValidation() 0 13 3
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 C116 extends Element implements ElementInterface
11
{
12
    const REG = 'C116';
13
    const LEVEL = 4;
14
    const PARENT = 'C110';
15
16
    protected $parameters = [
17
        'COD_MOD' => [
18
            'type' => 'string',
19
            'regex' => '^(59)+$',
20
            'required' => true,
21
            'info' => 'Código do modelo do documento fiscalValor total do estoque',
22
            'format' => ''
23
        ],
24
        'NR_SAT' => [
25
            'type' => 'numeric',
26
            'regex' => '^([0-9]{9})+$',
27
            'required' => true,
28
            'info' => 'Número de Série do equipamento SAT',
29
            'format' => ''
30
        ],
31
        'CHV_CFE' => [
32
            'type' => 'numeric',
33
            'regex' => '^([0-9]{44})?$',
34
            'required' => false,
35
            'info' => 'Chave do Cupom Fiscal Eletrônico',
36
            'format' => ''
37
        ],
38
        'NUM_CFE' => [
39
            'type' => 'numeric',
40
            'regex' => '^([0-9]{6})?$',
41
            'required' => false,
42
            'info' => 'Número do Cupom Fiscal Eletrônico',
43
            'format' => ''
44
        ],
45
        'DT_DOC' => [
46
            'type' => 'string',
47
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
48
            'required' => false,
49
            'info' => 'Data da emissão do documento fiscal',
50
            'format' => ''
51
        ],
52
    ];
53
54
    /**
55
     * Constructor
56
     * @param \stdClass $std
57
     */
58
    public function __construct(\stdClass $std)
59
    {
60
        parent::__construct(self::REG);
61
        $this->std = $this->standarize($std);
62
        $this->postValidation();
63
    }
64
65
66
    public function postValidation()
67
    {
68
        /**
69
         * Verifica a chave do cupom fiscal eletronico
70
         */
71
        if (!empty($this->std->chv_cfe) and !Keys::isValid($this->std->chv_cfe)) {
72
            throw new \InvalidArgumentException("[" . self::REG . "] " .
73
                " Dígito verificador incorreto no campo campo chave do " .
74
                "cupom fiscal eletronico (CHV_CFE)");
75
        }
76
77
        return true;
78
    }
79
}
80