A170   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 171
Duplicated Lines 8.19 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 14
loc 171
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A roundFloat() 0 4 1
A postValidation() 14 18 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
use \stdClass;
8
9
class A170 extends Element implements ElementInterface
10
{
11
    const REG = 'A170';
12
    const LEVEL = 4;
13
    const PARENT = 'A100';
14
15
    protected $parameters = [
16
        'NUM_ITEM' => [
17
            'type' => 'numeric',
18
            'regex' => '^([1-9]{1})(\d{0,3})$',
19
            'required' => false,
20
            'info' => 'Número seqüencial do item no documento fiscal',
21
            'format' => ''
22
        ],
23
        'COD_ITEM' => [
24
            'type' => 'string',
25
            'regex' => '^.{0,60}$',
26
            'required' => false,
27
            'info' => 'Código do item (campo 02 do Registro 0200)',
28
            'format' => ''
29
        ],
30
        'DESCR_COMPL' => [
31
            'type' => 'string',
32
            'regex' => '^(.*)$',
33
            'required' => false,
34
            'info' => 'Descrição complementar do item como adotado no documento fiscal',
35
            'format' => ''
36
        ],
37
        'VL_ITEM' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => false,
41
            'info' => 'Valor total do item (mercadorias ou serviços)',
42
            'format' => '15v2'
43
        ],
44
        'VL_DESC' => [
45
            'type' => 'numeric',
46
            'regex' => '^\d+(\.\d*)?|\.\d+$',
47
            'required' => false,
48
            'info' => 'Valor do desconto comercial / exclusão da base de cálculo do PIS/PASEP e da COFINS',
49
            'format' => '15v2'
50
        ],
51
        'NAT_BC_CRED' => [
52
            'type' => 'string',
53
            'regex' => '^.{2}$',
54
            'required' => false,
55
            'info' => 'Código da base de cálculo do crédito, conforme a Tabela indicada no item 4.3.7, 
56
            caso seja informado código representativo de crédito no Campo 09 (CST_PIS) 
57
            ou no Campo 13 (CST_COFINS).',
58
            'format' => ''
59
        ],
60
        'IND_ORIG_CRED' => [
61
            'type' => 'string',
62
            'regex' => '^(0|1)$',
63
            'required' => false,
64
            'info' => 'Indicador da origem do crédito: 0 – Operação no Mercado Interno',
65
            'format' => ''
66
        ],
67
        'CST_PIS' => [
68
            'type' => 'numeric',
69
            'regex' => '^(\d{2})$',
70
            'required' => false,
71
            'info' => 'Código da Situação Tributária referente ao PIS/PASEP – Tabela 4.3.3.',
72
            'format' => ''
73
        ],
74
        'VL_BC_PIS' => [
75
            'type' => 'numeric',
76
            'regex' => '^\d+(\.\d*)?|\.\d+$',
77
            'required' => false,
78
            'info' => 'Valor da base de cálculo do PIS/PASEP.',
79
            'format' => '15v2'
80
        ],
81
        'ALIQ_PIS' => [
82
            'type' => 'numeric',
83
            'regex' => '^\d+(\.\d*)?|\.\d+$',
84
            'required' => false,
85
            'info' => 'Alíquota do PIS/PASEP (em percentual)',
86
            'format' => '15v2'
87
        ],
88
        'VL_PIS' => [
89
            'type' => 'numeric',
90
            'regex' => '^\d+(\.\d*)?|\.\d+$',
91
            'required' => false,
92
            'info' => 'Valor do PIS/PASEP',
93
            'format' => '15v2'
94
        ],
95
        'CST_COFINS' => [
96
            'type' => 'numeric',
97
            'regex' => '^(\d{2})$',
98
            'required' => false,
99
            'info' => 'Código da Situação Tributária referente ao COFINS – Tabela 4.3.4.',
100
            'format' => ''
101
        ],
102
        'VL_BC_COFINS' => [
103
            'type' => 'numeric',
104
            'regex' => '^\d+(\.\d*)?|\.\d+$',
105
            'required' => false,
106
            'info' => 'Valor da base de cálculo da COFINS',
107
            'format' => '15v2'
108
        ],
109
        'ALIQ_COFINS' => [
110
            'type' => 'numeric',
111
            'regex' => '^\d+(\.\d*)?|\.\d+$',
112
            'required' => false,
113
            'info' => 'Alíquota do COFINS (em percentual)',
114
            'format' => '6v2'
115
        ],
116
        'VL_COFINS' => [
117
            'type' => 'numeric',
118
            'regex' => '^\d+(\.\d*)?|\.\d+$',
119
            'required' => false,
120
            'info' => 'Valor da COFINS',
121
            'format' => '15v2'
122
        ],
123
        'COD_CTA' => [
124
            'type' => 'string',
125
            'regex' => '^.{0,255}$',
126
            'required' => false,
127
            'info' => 'Código da conta analítica contábil debitada/creditada',
128
            'format' => ''
129
        ],
130
        'COD_CCUS' => [
131
            'type' => 'string',
132
            'regex' => '^.{0,255}$',
133
            'required' => false,
134
            'info' => 'Código do centro de custos',
135
            'format' => ''
136
        ],
137
138
    ];
139
140
    /**
141
     * Constructor
142
     * @param \stdClass $std
143
     */
144
    public function __construct(\stdClass $std)
145
    {
146
        parent::__construct(self::REG);
147
        $this->std = $this->standarize($std);
148
        $this->postValidation();
149
    }
150
151
    /**
152
     * Arre
153
     * @param float $valor
154
     * @return float|int
155
     */
156
    private function roundFloat($valor)
157
    {
158
        return (float)number_format($valor, 2);
159
    }
160
161
    public function postValidation()
162
    {
163 View Code Duplication
        if ($this->roundFloat($this->values->vl_pis) !=
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...
164
            $this->roundFloat(($this->values->vl_bc_pis * $this->values->aliq_pis) / 100)) {
165
            throw new \InvalidArgumentException("[" . self::REG . "] " .
166
                "valor do campo “VL_PIS” deve corresponder ao valor da base de cálculo (VL_BC_PIS) multiplicado " .
167
                "pela alíquota aplicável ao item (ALIQ_PIS). No caso de aplicação da alíquota " .
168
                "do campo 07, o resultado deverá ser dividido pelo valor “100”.");
169
        }
170
171 View Code Duplication
        if ($this->roundFloat($this->values->vl_cofins) !=
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...
172
            $this->roundFloat(($this->values->vl_bc_cofins * $this->values->aliq_cofins) / 100)) {
173
            throw new \InvalidArgumentException("[" . self::REG . "] " .
174
                "o valor do campo “VL_COFINS” deve corresponder ao valor da base de cálculo (VL_BC_COFINS) " .
175
                "multiplicado pela alíquota aplicável ao item (ALIQ_COFINS). No caso de aplicação da alíquota " .
176
                "do campo 07, o resultado deverá ser dividido pelo valor “100”.");
177
        }
178
    }
179
}
180