D100::__construct()   A
last analyzed

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 6
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\Contribuicoes;
4
5
use NFePHP\Common\Keys;
6
use NFePHP\EFD\Common\Element;
7
use NFePHP\EFD\Common\ElementInterface;
8
9
class D100 extends Element implements ElementInterface
10
{
11
    const REG = 'D100';
12
    const LEVEL = 3;
13
    const PARENT = 'D001';
14
15
    protected $parameters = [
16
        'IND_OPER' => [
17
            'type' => 'string',
18
            'regex' => '^(0)$',
19
            'required' => false,
20
            'info' => 'Indicador do tipo de operação ' .
21
                ' 0- Aquisição ',
22
            'format' => ''
23
        ],
24
        'IND_EMIT' => [
25
            'type' => 'string',
26
            'regex' => '^(0|1)$',
27
            'required' => false,
28
            'info' => 'Indicador do emitente do documento fiscal ' .
29
                ' 0- Emissão Própria ' .
30
                ' 1- Emissão por Terceiros ',
31
            'format' => ''
32
        ],
33
        'COD_PART' => [
34
            'type' => 'string',
35
            'regex' => '^.{0,60}$',
36
            'required' => false,
37
            'info' => 'Código do participante (campo 02 do Registro 0150). ',
38
            'format' => ''
39
        ],
40
        'COD_MOD' => [
41
            'type' => 'string',
42
            'regex' => '^(07|08|8B|09|10|11|26|27|57|63|67)$',
43
            'required' => false,
44
            'info' => 'Código do modelo do documento fiscal, conforme a Tabela 4.1.1 ',
45
            'format' => ''
46
        ],
47
        'COD_SIT' => [
48
            'type' => 'numeric',
49
            'regex' => '^(00|01|02|03|06|07|08)$',
50
            'required' => false,
51
            'info' => 'Código da situação do documento fiscal, conforme a Tabela 4.1.2 ',
52
            'format' => ''
53
        ],
54
        'SER' => [
55
            'type' => 'string',
56
            'regex' => '^.{0,4}$',
57
            'required' => false,
58
            'info' => 'Série do documento fiscal ',
59
            'format' => ''
60
        ],
61
        'SUB' => [
62
            'type' => 'string',
63
            'regex' => '^.{0,3}$',
64
            'required' => false,
65
            'info' => 'Subsérie do documento fiscal ',
66
            'format' => ''
67
        ],
68
        'NUM_DOC' => [
69
            'type' => 'numeric',
70
            'regex' => '^(\d{0,9})$',
71
            'required' => false,
72
            'info' => 'Número do documento fiscal ',
73
            'format' => ''
74
        ],
75
        'CHV_CTE' => [
76
            'type' => 'numeric',
77
            'regex' => '^([0-9]{44})?$',
78
            'required' => false,
79
            'info' => 'Chave do Conhecimento de Transporte Eletrônico ',
80
            'format' => ''
81
        ],
82
        'DT_DOC' => [
83
            'type' => 'string',
84
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
85
            'required' => false,
86
            'info' => 'Data de referência/emissão dos documentos fiscais ',
87
            'format' => ''
88
        ],
89
        'DT_A_P' => [
90
            'type' => 'string',
91
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
92
            'required' => false,
93
            'info' => 'Data da aquisição ou da prestação do serviço ',
94
            'format' => ''
95
        ],
96
        'TP_CTE' => [
97
            'type' => 'numeric',
98
            'regex' => '^(\d{1})$',
99
            'required' => false,
100
            'info' => 'Tipo de Conhecimento de Transporte Eletrônico conforme definido no Manual de Integração ' .
101
                'do CT-e ',
102
            'format' => ''
103
        ],
104
        'CHV_CTE_REF' => [
105
            'type' => 'numeric',
106
            'regex' => '^([0-9]{44})?$',
107
            'required' => false,
108
            'info' => 'Chave do CT-e de referência cujos valores foram complementados (opção “1” do campo ' .
109
                'anterior) ou cujo débito foi anulado (opção “2” do campo anterior). ',
110
            'format' => ''
111
        ],
112
        'VL_DOC' => [
113
            'type' => 'numeric',
114
            'regex' => '^\d+(\.\d*)?|\.\d+$',
115
            'required' => false,
116
            'info' => 'Valor total do documento fiscal ',
117
            'format' => '15v2'
118
        ],
119
        'VL_DESC' => [
120
            'type' => 'numeric',
121
            'regex' => '^\d+(\.\d*)?|\.\d+$',
122
            'required' => false,
123
            'info' => 'Valor total do desconto ',
124
            'format' => '15v2'
125
        ],
126
        'IND_FRT' => [
127
            'type' => 'string',
128
            'regex' => '^(0|1|2|9)$',
129
            'required' => false,
130
            'info' => 'Indicador do tipo do frete ' .
131
                ' 0- Por conta de terceiros ' .
132
                ' 1- Por conta do emitente ' .
133
                ' 2- Por conta do destinatário ' .
134
                ' 9- Sem cobrança de frete. ',
135
            'format' => ''
136
        ],
137
        'VL_SERV' => [
138
            'type' => 'numeric',
139
            'regex' => '^\d+(\.\d*)?|\.\d+$',
140
            'required' => false,
141
            'info' => 'Valor total da prestação de serviço ',
142
            'format' => '15v2'
143
        ],
144
        'VL_BC_ICMS' => [
145
            'type' => 'numeric',
146
            'regex' => '^\d+(\.\d*)?|\.\d+$',
147
            'required' => false,
148
            'info' => 'Valor da base de cálculo do ICMS ',
149
            'format' => '15v2'
150
        ],
151
        'VL_ICMS' => [
152
            'type' => 'numeric',
153
            'regex' => '^\d+(\.\d*)?|\.\d+$',
154
            'required' => false,
155
            'info' => 'Valor do ICMS ',
156
            'format' => '15v2'
157
        ],
158
        'VL_NT' => [
159
            'type' => 'numeric',
160
            'regex' => '^\d+(\.\d*)?|\.\d+$',
161
            'required' => false,
162
            'info' => 'Valor não-tributado do ICMS ',
163
            'format' => '15v2'
164
        ],
165
        'COD_INF' => [
166
            'type' => 'string',
167
            'regex' => '^.{0,6}$',
168
            'required' => false,
169
            'info' => 'Código da informação complementar do documento fiscal (campo 02 do Registro 0450) ',
170
            'format' => ''
171
        ],
172
        'COD_CTA' => [
173
            'type' => 'string',
174
            'regex' => '^.{0,255}$',
175
            'required' => false,
176
            'info' => 'Código da conta analítica contábil debitada/creditada ',
177
            'format' => ''
178
        ],
179
180
    ];
181
182
    /**
183
     * Constructor
184
     * @param \stdClass $std
185
     */
186
    public function __construct(\stdClass $std)
187
    {
188
        parent::__construct(self::REG);
189
        $this->std = $this->standarize($std);
190
        $this->postValidation();
191
    }
192
193
    public function postValidation()
194
    {
195 View Code Duplication
        if (!empty($this->std->chv_cte) and !Keys::isValid($this->std->chv_cte)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
196
            throw new \InvalidArgumentException("[" . self::REG . "] " .
197
                " Dígito verificador incorreto no campo chave do " .
198
                " campo CHV_CTE");
199
        }
200
201
        if (!empty($this->std->chv_cte_ref) and !Keys::isValid($this->std->chv_cte_ref)) {
202
            throw new \InvalidArgumentException("[" . self::REG . "] " .
203
                " Dígito verificador incorreto no campo chave do " .
204
                " campo CHV_CTE_REF");
205
        }
206
    }
207
}
208