C115::postValidation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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
9
class C115 extends Element implements ElementInterface
10
{
11
    const REG = 'C115';
12
    const LEVEL = 4;
13
    const PARENT = 'C110';
14
15
    protected $parameters = [
16
        'IND_CARGA' => [
17
            'type' => 'numeric',
18
            'regex' => '^(0|1|2|3|4|5|9)+$',
19
            'required' => true,
20
            'info' => 'Indicador do tipo de transporte',
21
            'format' => ''
22
        ],
23
        'CNPJ_COL' => [
24
            'type' => 'string',
25
            'regex' => '^[0-9]{14}$',
26
            'required' => false,
27
            'info' => 'Número do CNPJ do contribuinte do local de coleta',
28
            'format' => ''
29
        ],
30
        'IE_COL' => [
31
            'type' => 'string',
32
            'regex' => '^[0-9]{2,14}$',
33
            'required' => false,
34
            'info' => 'Inscrição Estadual do contribuinte do local de coleta',
35
            'format' => ''
36
        ],
37
        'CPF_COL' => [
38
            'type' => 'string',
39
            'regex' => '^[0-9]{11}$',
40
            'required' => true,
41
            'info' => 'CPF do contribuinte do local de coleta das mercadorias',
42
            'format' => ''
43
        ],
44
        'COD_MUN_COL' => [
45
            'type' => 'numeric',
46
            'regex' => '^([0-9]{7})$',
47
            'required' => true,
48
            'info' => 'Código do Município do local de coleta',
49
            'format' => ''
50
        ],
51
        'CNPJ_ENTG' => [
52
            'type' => 'string',
53
            'regex' => '^[0-9]{14}$',
54
            'required' => false,
55
            'info' => 'Número do CNPJ do contribuinte do local de entrega',
56
            'format' => ''
57
        ],
58
        'IE_ENTG' => [
59
            'type' => 'string',
60
            'regex' => '^[0-9]{2,14}$',
61
            'required' => false,
62
            'info' => 'Inscrição Estadual do contribuinte do local de entrega',
63
            'format' => ''
64
        ],
65
        'CPF_ENTG' => [
66
            'type' => 'string',
67
            'regex' => '^[0-9]{11}$',
68
            'required' => true,
69
            'info' => 'Cpf do contribuinte do local de entrega',
70
            'format' => ''
71
        ],
72
        'COD_MUN_ENTG' => [
73
            'type' => 'numeric',
74
            'regex' => '^([0-9]{7})$',
75
            'required' => true,
76
            'info' => 'Código do Município do local de entrega',
77
            'format' => ''
78
        ],
79
    ];
80
81
    /**
82
     * Constructor
83
     * @param \stdClass $std
84
     */
85
    public function __construct(\stdClass $std)
86
    {
87
        parent::__construct(self::REG);
88
        $this->std = $this->standarize($std);
89
        $this->postValidation();
90
    }
91
92
93
    /**
94
     * Aqui são colocadas validações adicionais que requerem mais logica
95
     * e processamento
96
     * Deve ser usado apenas quando necessário
97
     * @throws \InvalidArgumentException
98
     */
99
    public function postValidation()
100
    {
101
        if (!$this->std->cnpj_entg xor $this->std->cpf_entg) {
102
            throw new \InvalidArgumentException("[" . self::REG . "] " .
103
                "Deve ser informado apenas o CNPJ (CNPJ_ENTG) ou o CPF (CPF_ENTG)");
104
        }
105
    }
106
}
107