C500   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 261
Duplicated Lines 4.21 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 11
loc 261
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A postValidation() 11 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 C500 extends Element implements ElementInterface
10
{
11
    const REG = 'C500';
12
    const LEVEL = 2;
13
    const PARENT = 'C001';
14
15
    protected $parameters = [
16
        'IND_OPER' => [
17
            'type' => 'string',
18
            'regex' => '^.{1}$',
19
            'required' => true,
20
            'info' => 'Indicador do tipo de operação',
21
            'format' => ''
22
        ],
23
        'IND_EMIT' => [
24
            'type' => 'string',
25
            'regex' => '^.{1}$',
26
            'required' => true,
27
            'info' => 'Indicador do emitente do documento fiscal',
28
            'format' => ''
29
        ],
30
        'COD_PART' => [
31
            'type' => 'string',
32
            'regex' => '^.{1,60}$',
33
            'required' => true,
34
            'info' => 'Código do participante (campo 02 do Registro 0150)',
35
            'format' => ''
36
        ],
37
        'COD_MOD' => [
38
            'type' => 'string',
39
            'regex' => '^.{2}$',
40
            'required' => true,
41
            'info' => 'Código do modelo conforme a Tabela 4.1.1',
42
            'format' => ''
43
        ],
44
        'COD_SIT' => [
45
            'type' => 'numeric',
46
            'regex' => '^(\d{2})$',
47
            'required' => true,
48
            'info' => 'Código da situação conforme a Tabela 4.1.2',
49
            'format' => ''
50
        ],
51
        'SER' => [
52
            'type' => 'string',
53
            'regex' => '^.{0,4}$',
54
            'required' => false,
55
            'info' => 'Série do documento fiscal',
56
            'format' => ''
57
        ],
58
        'SUB' => [
59
            'type' => 'numeric',
60
            'regex' => '^(\d{1,3})$',
61
            'required' => false,
62
            'info' => 'Subsérie do documento fiscal',
63
            'format' => ''
64
        ],
65
        'COD_CONS' => [
66
            'type' => 'string',
67
            'regex' => '^[0-9]{2}$',
68
            'required' => false,
69
            'info' => 'Código de classe de consumo de energia elétrica ou gás',
70
            'format' => ''
71
        ],
72
        'NUM_DOC' => [
73
            'type' => 'numeric',
74
            'regex' => '^(\d{1,9})$',
75
            'required' => true,
76
            'info' => 'Número do documento fiscal',
77
            'format' => ''
78
        ],
79
        'DT_DOC' => [
80
            'type' => 'string',
81
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
82
            'required' => true,
83
            'info' => 'Data da emissão do documento fiscal',
84
            'format' => ''
85
        ],
86
        'DT_E_S' => [
87
            'type' => 'string',
88
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
89
            'required' => true,
90
            'info' => 'Data da entrada ou da saída',
91
            'format' => ''
92
        ],
93
        'VL_DOC' => [
94
            'type' => 'numeric',
95
            'regex' => '^\d+(\.\d*)?|\.\d+$',
96
            'required' => true,
97
            'info' => 'Valor total do documento fiscal',
98
            'format' => '15v2'
99
        ],
100
        'VL_DESC' => [
101
            'type' => 'numeric',
102
            'regex' => '^\d+(\.\d*)?|\.\d+$',
103
            'required' => false,
104
            'info' => 'Valor total do desconto',
105
            'format' => '15v2'
106
        ],
107
        'VL_FORN' => [
108
            'type' => 'numeric',
109
            'regex' => '^\d+(\.\d*)?|\.\d+$',
110
            'required' => true,
111
            'info' => 'Valor total fornecido/consumido',
112
            'format' => '15v2'
113
        ],
114
        'VL_SERV_NT' => [
115
            'type' => 'numeric',
116
            'regex' => '^\d+(\.\d*)?|\.\d+$',
117
            'required' => false,
118
            'info' => 'Valor total dos serviços não-tributados pelo ICMS',
119
            'format' => '15v2'
120
        ],
121
        'VL_TERC' => [
122
            'type' => 'numeric',
123
            'regex' => '^\d+(\.\d*)?|\.\d+$',
124
            'required' => false,
125
            'info' => 'Valor total cobrado em nome de terceiros',
126
            'format' => '15v2'
127
        ],
128
        'VL_DA' => [
129
            'type' => 'numeric',
130
            'regex' => '^\d+(\.\d*)?|\.\d+$',
131
            'required' => false,
132
            'info' => 'Valor total de despesas acessórias indicadas no',
133
            'format' => '15v2'
134
        ],
135
        'VL_BC_ICMS' => [
136
            'type' => 'numeric',
137
            'regex' => '^\d+(\.\d*)?|\.\d+$',
138
            'required' => false,
139
            'info' => 'Valor acumulado da base de cálculo do ICMS',
140
            'format' => '15v2'
141
        ],
142
        'VL_ICMS' => [
143
            'type' => 'numeric',
144
            'regex' => '^\d+(\.\d*)?|\.\d+$',
145
            'required' => false,
146
            'info' => 'Valor acumulado do ICMS',
147
            'format' => '15v2'
148
        ],
149
        'VL_BC_ICMS_ST' => [
150
            'type' => 'numeric',
151
            'regex' => '^\d+(\.\d*)?|\.\d+$',
152
            'required' => false,
153
            'info' => 'Valor acumulado da base de cálculo do ICMS substituição tributária',
154
            'format' => '15v2'
155
        ],
156
        'VL_ICMS_ST' => [
157
            'type' => 'numeric',
158
            'regex' => '^\d+(\.\d*)?|\.\d+$',
159
            'required' => false,
160
            'info' => 'Valor acumulado substituição tributária',
161
            'format' => '15v2'
162
        ],
163
        'COD_INF' => [
164
            'type' => 'string',
165
            'regex' => '^.{0,6}$',
166
            'required' => false,
167
            'info' => 'Código da informação complementar do documento fiscal (campo 02 do Registro 0450)',
168
            'format' => ''
169
        ],
170
        'VL_PIS' => [
171
            'type' => 'numeric',
172
            'regex' => '^\d+(\.\d*)?|\.\d+$',
173
            'required' => false,
174
            'info' => 'Valor do PIS',
175
            'format' => '15v2'
176
        ],
177
        'VL_COFINS' => [
178
            'type' => 'numeric',
179
            'regex' => '^\d+(\.\d*)?|\.\d+$',
180
            'required' => false,
181
            'info' => 'Valor da COFINS',
182
            'format' => '15v2'
183
        ],
184
        'TP_LIGACAO' => [
185
            'type' => 'numeric',
186
            'regex' => '^([1-3]{1})$',
187
            'required' => false,
188
            'info' => 'Código de tipo de Ligação',
189
            'format' => ''
190
        ],
191
        'COD_GRUPO_TENSAO' => [
192
            'type' => 'string',
193
            'regex' => '^([0-1]{1})([0-9]{1})$',
194
            'required' => false,
195
            'info' => 'Código de grupo de tensão',
196
            'format' => ''
197
        ],
198
        'CHV_DOCe' => [
199
            'type' => 'numeric',
200
            'regex' => '^[0-9]{44}$',
201
            'required' => false,
202
            'info'     => 'Chave da Nota Fiscal de Energia Elétrica Eletrônica',
203
            'format'   => ''
204
        ],
205
        'FIN_DOCe' => [
206
            'type' => 'string',
207
            'regex' => '^(0|1|3)$',
208
            'required' => false,
209
            'info'     => 'Finalidade da emissão do documento eletrônico:'
210
            . '1 - Normal'
211
            . '2 - Substituição'
212
            . '3 - Normal com ajuste',
213
            'format'   => ''
214
        ],
215
        'CHV_DOCe_REF' => [
216
            'type' => 'numeric',
217
            'regex' => '^[0-9]{44}$',
218
            'required' => false,
219
            'info'     => 'Chave da nota referenciada, substituída.',
220
            'format'   => ''
221
        ],
222
        'IND_DEST' => [
223
            'type'     => 'numeric',
224
            'regex' => '^(0|1|9)$',
225
            'required' => false,
226
            'info'     => 'Indicador do Destinatário/Acessante:'
227
            . '1 - Contribuinte do ICMS;'
228
            . '2 - Contribuinte Isento de Inscrição no Cadastro de Contribuintes do ICMS;'
229
            . '9 - Não Contribuinte.',
230
            'format'   => ''
231
        ],
232
        'COD_MUN_DEST' => [
233
            'type'     => 'numeric',
234
            'regex' => '^[0-9]{7}$',
235
            'required' => false,
236
            'info'     => 'Código do município do destinatário conforme a tabela do IBGE.',
237
            'format'   => ''
238
        ],
239
        'COD_CTA' => [
240
            'type'     => 'string',
241
            'regex'    => '^.{1,60}$',
242
            'required' => false,
243
            'info'     => 'Código da conta analítica contábil debitada/creditada',
244
            'format'   => ''
245
        ]
246
    ];
247
248
    /**
249
     * Constructor
250
     * @param \stdClass $std
251
     */
252
    public function __construct(\stdClass $std)
253
    {
254
        parent::__construct(self::REG);
255
        $this->std = $this->standarize($std);
256
    }
257
258 View Code Duplication
    public function postValidation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
259
    {
260
        if ($this->values->vl_doc <= 0) {
261
            throw new \InvalidArgumentException("[" . self::REG . "] " .
262
                " O do campo VL_DOC deve ser maior do que 0");
263
        }
264
        if ($this->values->vl_forn <= 0) {
265
            throw new \InvalidArgumentException("[" . self::REG . "] " .
266
                " O do campo VL_FORN deve ser maior do que 0");
267
        }
268
    }
269
}
270