D350   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 193
Duplicated Lines 8.29 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A postValidation() 16 16 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\Contribuicoes;
4
5
use NFePHP\EFD\Common\Element;
6
use NFePHP\EFD\Common\ElementInterface;
7
8
class D350 extends Element implements ElementInterface
9
{
10
    const REG = 'D350';
11
    const LEVEL = 3;
12
    const PARENT = 'D300';
13
14
    protected $parameters = [
15
        'COD_MOD' => [
16
            'type' => 'string',
17
            'regex' => '^(2E|13|14|15|16)$',
18
            'required' => false,
19
            'info' => 'Código do modelo do documento fiscal, conforme a Tabela 4.1.1 ',
20
            'format' => ''
21
        ],
22
        'ECF_MOD' => [
23
            'type' => 'string',
24
            'regex' => '^.{0,20}$',
25
            'required' => false,
26
            'info' => 'Modelo do equipamento ',
27
            'format' => ''
28
        ],
29
        'ECF_FAB' => [
30
            'type' => 'string',
31
            'regex' => '^.{0,21}$',
32
            'required' => false,
33
            'info' => 'Número de série de fabricação do ECF ',
34
            'format' => ''
35
        ],
36
        'DT_DOC' => [
37
            'type' => 'string',
38
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
39
            'required' => false,
40
            'info' => 'Data do movimento a que se refere a Redução Z ',
41
            'format' => ''
42
        ],
43
        'CRO' => [
44
            'type' => 'numeric',
45
            'regex' => '^([1-9]{1})(\d{0,2})$',
46
            'required' => false,
47
            'info' => 'Posição do Contador de Reinício de Operação ',
48
            'format' => ''
49
        ],
50
        'CRZ' => [
51
            'type' => 'numeric',
52
            'regex' => '^([1-9]{1})(\d{0,5})$',
53
            'required' => false,
54
            'info' => 'Posição do Contador de Redução Z ',
55
            'format' => ''
56
        ],
57
        'NUM_COO_FIN' => [
58
            'type' => 'numeric',
59
            'regex' => '^([1-9]{1})(\d{0,5})$',
60
            'required' => false,
61
            'info' => 'Número do Contador de Ordem de Operação do último documento emitido no dia. (Número ' .
62
                'do COO na Redução Z) ',
63
            'format' => ''
64
        ],
65
        'GT_FIN' => [
66
            'type' => 'numeric',
67
            'regex' => '^\d+(\.\d*)?|\.\d+$',
68
            'required' => false,
69
            'info' => 'Valor do Grande Total final ',
70
            'format' => '15v2'
71
        ],
72
        'VL_BRT' => [
73
            'type' => 'numeric',
74
            'regex' => '^\d+(\.\d*)?|\.\d+$',
75
            'required' => false,
76
            'info' => 'Valor da venda bruta ',
77
            'format' => '15v2'
78
        ],
79
        'CST_PIS' => [
80
            'type' => 'string',
81
            'regex' => '^((0[1-9])|49|99)$',
82
            'required' => false,
83
            'info' => 'Código da Situação Tributária referente ao PIS/PASEP ',
84
            'format' => ''
85
        ],
86
        'VL_BC_PIS' => [
87
            'type' => 'numeric',
88
            'regex' => '^\d+(\.\d*)?|\.\d+$',
89
            'required' => false,
90
            'info' => 'Valor da base de cálculo do PIS/PASEP ',
91
            'format' => '15v2'
92
        ],
93
        'ALIQ_PIS' => [
94
            'type' => 'numeric',
95
            'regex' => '^\d+(\.\d*)?|\.\d+$',
96
            'required' => false,
97
            'info' => 'Alíquota do PIS/PASEP (em percentual) ',
98
            'format' => '8v4'
99
        ],
100
        'QUANT_BC_PIS' => [
101
            'type' => 'numeric',
102
            'regex' => '^\d+(\.\d*)?|\.\d+$',
103
            'required' => false,
104
            'info' => 'Quantidade – Base de cálculo PIS/PASEP ',
105
            'format' => '15v3'
106
        ],
107
        'ALIQ_PIS_QUANT' => [
108
            'type' => 'numeric',
109
            'regex' => '^\d+(\.\d*)?|\.\d+$',
110
            'required' => false,
111
            'info' => 'Alíquota do PIS/PASEP (em reais) ',
112
            'format' => '15v4'
113
        ],
114
        'VL_PIS' => [
115
            'type' => 'numeric',
116
            'regex' => '^\d+(\.\d*)?|\.\d+$',
117
            'required' => false,
118
            'info' => 'Valor do PIS/PASEP ',
119
            'format' => '15v2'
120
        ],
121
        'CST_COFINS' => [
122
            'type' => 'string',
123
            'regex' => '^((5[0-6])|(6[0-6])|(7[0-5])|98|99)$',
124
            'required' => false,
125
            'info' => 'Código da Situação Tributária referente a COFINS ',
126
            'format' => ''
127
        ],
128
        'VL_BC_COFINS' => [
129
            'type' => 'numeric',
130
            'regex' => '^\d+(\.\d*)?|\.\d+$',
131
            'required' => false,
132
            'info' => 'Valor da base de cálculo da COFINS ',
133
            'format' => '15v2'
134
        ],
135
        'ALIQ_COFINS' => [
136
            'type' => 'numeric',
137
            'regex' => '^\d+(\.\d*)?|\.\d+$',
138
            'required' => false,
139
            'info' => 'Alíquota da COFINS (em percentual) ',
140
            'format' => '8v4'
141
        ],
142
        'QUANT_BC_COFINS' => [
143
            'type' => 'numeric',
144
            'regex' => '^\d+(\.\d*)?|\.\d+$',
145
            'required' => false,
146
            'info' => 'Quantidade – Base de cálculo da COFINS ',
147
            'format' => '15v3'
148
        ],
149
        'ALIQ_COFINS_QUANT' => [
150
            'type' => 'numeric',
151
            'regex' => '^\d+(\.\d*)?|\.\d+$',
152
            'required' => false,
153
            'info' => 'Alíquota da COFINS (em reais) ',
154
            'format' => '15v4'
155
        ],
156
        'VL_COFINS' => [
157
            'type' => 'numeric',
158
            'regex' => '^\d+(\.\d*)?|\.\d+$',
159
            'required' => false,
160
            'info' => 'Valor da COFINS ',
161
            'format' => '15v2'
162
        ],
163
        'COD_CTA' => [
164
            'type' => 'string',
165
            'regex' => '^.{0,255}$',
166
            'required' => false,
167
            'info' => 'Código da conta analítica contábil debitada/creditada ',
168
            'format' => ''
169
        ],
170
171
    ];
172
173
    /**
174
     * Constructor
175
     * @param \stdClass $std
176
     */
177
    public function __construct(\stdClass $std)
178
    {
179
        parent::__construct(self::REG);
180
        $this->std = $this->standarize($std);
181
        $this->postValidation();
182
    }
183
184 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...
185
    {
186
        $multiplicacao = $this->values->vl_bc_pis * $this->values->aliq_pis;
187
        if (number_format($this->values->vl_pis, 2) != number_format($multiplicacao / 100, 2)) {
188
            throw new \InvalidArgumentException("[" . self::REG . "] " .
189
                "O campo VL_PIS deve de ser o calculo da multiplicacao " .
190
                "da base de calculo do PIS com a aliquota do PIS, o resultado dividido por 100");
191
        }
192
193
        $multiplicacao = $this->values->vl_bc_cofins * $this->values->aliq_cofins;
194
        if (number_format($this->values->vl_cofins, 2) != number_format($multiplicacao / 100, 2)) {
195
            throw new \InvalidArgumentException("[" . self::REG . "] " .
196
                "O campo VL_COFINS deve de ser o calculo da multiplicacao " .
197
                "da base de calculo do cofins com a aliquota do cofins, o resultado dividido por 100");
198
        }
199
    }
200
}
201