E310::postValidation()   D
last analyzed

Complexity

Conditions 21
Paths 6

Size

Total Lines 89

Duplication

Lines 18
Ratio 20.22 %

Code Coverage

Tests 0
CRAP Score 462

Importance

Changes 0
Metric Value
dl 18
loc 89
ccs 0
cts 53
cp 0
rs 4.1666
c 0
b 0
f 0
cc 21
nc 6
nop 0
crap 462

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 E310 extends Element implements ElementInterface
10
{
11
    const REG = 'E310';
12
    const LEVEL = 3;
13
    const PARENT = 'E300';
14
15
    protected $parameters = [
16
        'IND_MOV_FCP_DIFAL' => [
17
            'type'     => 'string',
18
            'regex'    => '^[0|1]$',
19
            'required' => true,
20
            'info'     => 'Indicador de movimento: '
21
            .'0 – Sem operações '
22
            .'1 – Com operações',
23
            'format'   => ''
24
        ],
25
        'VL_SLD_CRED_ANT_DIFAL' => [
26
            'type'     => 'numeric',
27
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
28
            'required' => true,
29
            'info'     => 'Valor do "Saldo credor de período anterior – ICMS Diferencial de '
30
            .'Alíquota da UF de Origem/Destino"',
31
            'format'   => '15v2'
32
        ],
33
        'VL_TOT_DEBITOS_DIFAL' => [
34
            'type'     => 'numeric',
35
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
36
            'required' => true,
37
            'info'     => 'Valor total dos débitos por "Saídas e prestações com débito do ICMS '
38
            .'referente ao diferencial de alíquota devido à UF de Origem/Destino"',
39
            'format'   => '15v2'
40
        ],
41
        'VL_OUT_DEB_DIFAL' => [
42
            'type'     => 'numeric',
43
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
44
            'required' => true,
45
            'info'     => 'Valor Total dos ajustes "Outros débitos ICMS Diferencial de Alíquota da UF de '
46
            .'Origem/Destino" e “Estorno de créditos ICMS Diferencial de Alíquota da UF de Origem/Destino',
47
            'format'   => '15v2'
48
        ],
49
        'VL_TOT_CREDITOS_DIFAL' => [
50
            'type'     => 'numeric',
51
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
52
            'required' => true,
53
            'info'     => 'Valor total dos créditos do ICMS referente ao diferencial de alíquota '
54
            .'devido à UF de Origem/Destino',
55
            'format'   => '15v2'
56
        ],
57
        'VL_OUT_CRED_DIFAL' => [
58
            'type'     => 'numeric',
59
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
60
            'required' => true,
61
            'info'     => 'Valor total de Ajustes "Outros créditos ICMS Diferencial de Alíquota da UF de '
62
            .'Origem/Destino" e “Estorno de débitos ICMS Diferencial de Alíquota da UF de Origem/Destino”',
63
            'format'   => '15v2'
64
        ],
65
        'VL_SLD_DEV_ANT_DIFAL' => [
66
            'type'     => 'numeric',
67
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
68
            'required' => true,
69
            'info'     => 'Valor total de Saldo devedor ICMS Diferencial de Alíquota da UF de '
70
            .'Origem/Destino antes das deduções',
71
            'format'   => '15v2'
72
        ],
73
        'VL_DEDUCOES_DIFAL' => [
74
            'type'     => 'numeric',
75
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
76
            'required' => true,
77
            'info'     => 'Valor total dos ajustes "Deduções ICMS Diferencial de Alíquota da UF de Origem/Destino"',
78
            'format'   => '15v2'
79
        ],
80
        'VL_RECOL_DIFAL' => [
81
            'type'     => 'numeric',
82
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
83
            'required' => true,
84
            'info'     => 'Valor recolhido ou a recolher referente ao ICMS Diferencial de Alíquota '
85
            .'da UF de Origem/Destino (08-09)',
86
            'format'   => '15v2'
87
        ],
88
        'VL_SLD_CRED_TRANSPORTAR_DIFAL' => [
89
            'type'     => 'numeric',
90
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
91
            'required' => true,
92
            'info'     => 'Saldo credor a transportar para o período seguinte referente ao ICMS Diferencial '
93
            .'de Alíquota da UF de Origem/Destino',
94
            'format'   => '15v2'
95
        ],
96
        'DEB_ESP_DIFAL' => [
97
            'type'     => 'numeric',
98
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
99
            'required' => true,
100
            'info'     => 'Valores recolhidos ou a recolher, extra- apuração - ICMS Diferencial de Alíquota '
101
            .'da UF de Origem/Destino.',
102
            'format'   => '15v2'
103
        ],
104
        'VL_SLD_CRED_ANT_FCP' => [
105
            'type'     => 'numeric',
106
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
107
            'required' => true,
108
            'info'     => 'Valor do "Saldo credor de período anterior – FCP"',
109
            'format'   => '15v2'
110
        ],
111
        'VL_TOT_DEB_FCP' => [
112
            'type'     => 'numeric',
113
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
114
            'required' => true,
115
            'info'     => 'Valor total dos débitos FCP por "Saídas e prestações”',
116
            'format'   => '15v2'
117
        ],
118
        'VL_OUT_DEB_FCP' => [
119
            'type'     => 'numeric',
120
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
121
            'required' => true,
122
            'info'     => 'Valor total dos ajustes "Outros débitos FCP" e “Estorno de créditos FCP”',
123
            'format'   => '15v2'
124
        ],
125
        'VL_TOT_CRED_FCP' => [
126
            'type'     => 'numeric',
127
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
128
            'required' => true,
129
            'info'     => 'Valor total dos créditos FCP por Entradas',
130
            'format'   => '15v2'
131
        ],
132
        'VL_OUT_CRED_FCP' => [
133
            'type'     => 'numeric',
134
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
135
            'required' => true,
136
            'info'     => 'Valor total de Ajustes "Outros créditos FCP" e “Estorno de débitos FCP”',
137
            'format'   => '15v2'
138
        ],
139
        'VL_SLD_DEV_ANT_FCP' => [
140
            'type'     => 'numeric',
141
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
142
            'required' => true,
143
            'info'     => 'Valor total de Saldo devedor FCP antes das deduções',
144
            'format'   => '15v2'
145
        ],
146
        'VL_DEDUCOES_FCP' => [
147
            'type'     => 'numeric',
148
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
149
            'required' => true,
150
            'info'     => 'Valor total das deduções "FCP"',
151
            'format'   => '15v2'
152
        ],
153
        'VL_RECOL_FCP' => [
154
            'type'     => 'numeric',
155
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
156
            'required' => true,
157
            'info'     => 'Valor recolhido ou a recolher referente ao FCP (18–19)',
158
            'format'   => '15v2'
159
        ],
160
        'VL_SLD_CRED_TRANSPORTAR_FCP' => [
161
            'type'     => 'numeric',
162
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
163
            'required' => true,
164
            'info'     => 'Saldo credor a transportar para o período seguinte referente ao FCP',
165
            'format'   => '15v2'
166
        ],
167
        'DEB_ESP_FCP' => [
168
            'type'     => 'numeric',
169
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
170
            'required' => true,
171
            'info'     => 'Valores recolhidos ou a recolher, extra- apuração - FCP',
172
            'format'   => '15v2'
173
        ]
174
    ];
175
176
    /**
177
     * Constructor
178
     * @param \stdClass $std
179
     */
180
    public function __construct(\stdClass $std)
181
    {
182
        parent::__construct(self::REG);
183
        $this->std = $this->standarize($std);
184
        $this->postValidation();
185
    }
186
187
    public function postValidation()
188
    {
189
        /*
190
         * Campo 08 (VL_SLD_DEV_ANT_DIFAL) Validação: Se (VL_TOT_DEBITOS_DIFAL + VL_OUT_DEB_DIFAL) menos
191
         * (VL_SLD_CRED_ANT_DIFAL + VL_TOT_CREDITOS_DIFAL + VL_OUT_CRED_DIFAL) for maior ou igual a ZERO,
192
         * então o resultado deverá ser igual ao VL_SLD_DEV_ANT_DIFAL; senão VL_SLD_DEV_ANT_DIFAL deve
193
         * ser igual a ZERO.
194
         */
195
        $somatorio = $this->values->vl_tot_debitos_difal
196
                    + $this->values->vl_out_deb_difal
197
                    - $this->values->vl_sld_cred_ant_difal
198
                    - $this->values->vl_tot_creditos_difal
199
                    - $this->values->vl_out_cred_difal;
200
        
201
        if (($somatorio > 0 && $this->values->vl_sld_dev_ant_difal == 0)
202
        || ($somatorio < 0 && $this->values->vl_sld_dev_ant_difal != 0)) {
203
            throw new \InvalidArgumentException("[" . self::REG . "] Se (VL_TOT_DEBITOS_DIFAL + VL_OUT_DEB_DIFAL) "
204
            ."menos (VL_SLD_CRED_ANT_DIFAL + VL_TOT_CREDITOS_DIFAL + VL_OUT_CRED_DIFAL) for maior ou igual a "
205
            ."ZERO, então o resultado deverá ser igual ao VL_SLD_DEV_ANT_DIFAL; senão VL_SLD_DEV_ANT_DIFAL deve "
206
            ."ser igual a ZERO.");
207
        }
208
209
        /*
210
         * Campo 10 (VL_RECOL_DIFAL) Validação: Se (VL_SLD_DEV_ANT_DIFAL menos VL_DEDUCOES_DIFAL) for maior
211
         * ou igual a ZERO, então VL_RECOL_DIFAL é igual ao resultado da equação; senão o VL_RECOL_DIFAL
212
         * deverá ser igual a ZERO.
213
         */
214
        $diferenca = $this->values->vl_sld_dev_ant_difal - $this->values->vl_deducoes_difal;
215
        
216 View Code Duplication
        if (($diferenca > 0 && $this->values->vl_recol_difal == 0)
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...
217
        || ($diferenca < 0 && $this->values->vl_recol_difal != 0)) {
218
            throw new \InvalidArgumentException("[" . self::REG . "] Se (VL_SLD_DEV_ANT_DIFAL menos VL_DEDUCOES_DIFAL) "
219
            ."for maior ou igual a ZERO, então VL_RECOL é igual ao resultado da equação; senão o VL_RECOL deverá "
220
            ."ser igual a ZERO.");
221
        }
222
223
         /*
224
         * Campo 18 (VL_SLD_DEV_ANT_FCP) Validação: Se (VL_TOT_DEB_FCP + VL_OUT_DEB_FCP) menos (VL_SLD_CRED_ANT_FCP
225
         * + VL_TOT_CRED_FCP + VL_OUT_CRED_FCP) for maior ou igual a ZERO, então o resultado deverá ser igual ao
226
         * VL_SLD_DEV_ANT_FCP; senão VL_SLD_DEV_ANT_FCP deve ser igual a ZERO.
227
         */
228
        $somatorio = $this->values->vl_tot_deb_fcp
229
                    + $this->values->vl_out_deb_fcp
230
                    - $this->values->vl_sld_cred_ant_fcp
231
                    - $this->values->vl_tot_cred_fcp
232
                    - $this->values->vl_out_cred_fcp;
233
        
234 View Code Duplication
        if (($somatorio > 0 && $this->values->vl_sld_dev_ant_fcp == 0)
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...
235
        || ($somatorio < 0 && $this->values->vl_sld_dev_ant_fcp != 0)) {
236
            throw new \InvalidArgumentException("[" . self::REG . "] Se (VL_TOT_DEB_FCP + VL_OUT_DEB_FCP) menos "
237
            ."(VL_SLD_CRED_ANT_FCP + VL_TOT_CRED_FCP + VL_OUT_CRED_FCP) for maior ou igual a ZERO, então o "
238
            ."resultado deverá ser igual ao VL_SLD_DEV_ANT_FCP; senão VL_SLD_DEV_ANT_FCP deve ser igual a ZERO.");
239
        }
240
241
        /*
242
        * Campo 20 (VL_RECOL_FCP) Validação: Se (VL_SLD_DEV_ANT_FCP menos VL_DEDUCOES_FCP) for maior
243
        * ou igual a ZERO, então VL_RECOL_FCP é igual ao resultado da equação; senão o VL_RECOL_FCP
244
        * deverá ser igual a ZERO.
245
        */
246
        $diferenca = $this->values->vl_sld_dev_ant_fcp - $this->values->vl_deducoes_fcp;
247
        
248 View Code Duplication
        if (($diferenca > 0 && $this->values->vl_recol_fcp == 0)
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...
249
        || ($diferenca < 0 && $this->values->vl_recol_fcp != 0)) {
250
            throw new \InvalidArgumentException("[" . self::REG . "] Se (VL_SLD_DEV_ANT_FCP menos VL_DEDUCOES_FCP) "
251
            ."for maior ou igual a ZERO, então VL_RECOL_FCP é igual ao resultado da equação; senão o VL_RECOL_FCP "
252
            ."deverá ser igual a ZERO.");
253
        }
254
255
        /*
256
         * Campo 21 (VL_SLD_CRED_TRANSPORTAR_FCP) Validação: Se (VL_SLD_CRED_ANT_FCP + VL_TOT_CRED_FCP
257
         * + VL_OUT_CRED_FCP + VL_DEDUÇÕES_FCP) menos (VL_TOT_DEB_FCP + VL_OUT_DEB_FCP) for maior que ZERO,
258
         * então VL_SLD_CRED_TRANSPORTAR_FCP deve ser igual ao resultado da equação; senão
259
         * VL_SLD_CRED_TRANSPORTAR_FCP será ZERO.
260
         */
261
        $somatorio = $this->values->vl_sld_cred_ant_fcp
262
                    + $this->values->vl_tot_cred_fcp
263
                    + $this->values->vl_out_cred_fcp
264
                    + $this->values->vl_deducoes_fcp
265
                    - $this->values->vl_tot_deb_fcp
266
                    - $this->values->vl_out_deb_fcp;
267
        
268
        if (($somatorio > 0 && $this->values->vl_sld_cred_transportar_fcp == 0)
269
        || ($somatorio < 0 && $this->values->vl_sld_cred_transportar_fcp != 0)) {
270
            throw new \InvalidArgumentException("[" . self::REG . "] Se (VL_SLD_CRED_ANT_FCP + VL_TOT_CRED_FCP "
271
            ."+ VL_OUT_CRED_FCP + VL_DEDUÇÕES_FCP) menos (VL_TOT_DEB_FCP + VL_OUT_DEB_FCP) for maior que ZERO, "
272
            ."então VL_SLD_CRED_TRANSPORTAR_FCP deve ser igual ao resultado da equação; senão "
273
            ."VL_SLD_CRED_TRANSPORTAR_FCP será ZERO.");
274
        }
275
    }
276
}
277