Completed
Push — master ( db1663...ff0e65 )
by Roberto
13:35 queued 10s
created

C175   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 164
Duplicated Lines 3.66 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 6
loc 164
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B postValidation() 6 21 8

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 C175 extends Element implements ElementInterface
10
{
11
    const REG = 'C175';
12
    const LEVEL = 4;
13
    const PARENT = 'C170';
14
15
    protected $parameters = [
16
        'CFOP' => [
17
            'type' => 'numeric',
18
            'regex' => '^(\d{4})$',
19
            'required' => false,
20
            'info' => 'Código fiscal de operação e prestação',
21
            'format' => ''
22
        ],
23
        'VL_OPR' => [
24
            'type' => 'numeric',
25
            'regex' => '^\d+(\.\d*)?|\.\d+$',
26
            'required' => false,
27
            'info' => 'Valor da operação na combinação de CFOP, CST e alíquotas, 
28
            correspondente ao somatório do valor das mercadorias e produtos 
29
            constantes no documento.',
30
            'format' => '15v2'
31
        ],
32
        'VL_DESC' => [
33
            'type' => 'numeric',
34
            'regex' => '^\d+(\.\d*)?|\.\d+$',
35
            'required' => false,
36
            'info' => 'Valor do desconto comercial / exclusão da base de cálculo do PIS/PASEP e da COFINS',
37
            'format' => '15v2'
38
        ],
39
        'CST_PIS' => [
40
            'type' => 'numeric',
41
            'regex' => '^((0[1-9])|49|99)$',
42
            'required' => false,
43
            'info' => 'Código da Situação Tributária referente ao PIS/PASEP, conforme a Tabela indicada no item 4.3.3.',
44
            'format' => ''
45
        ],
46
        'VL_BC_PIS' => [
47
            'type' => 'numeric',
48
            'regex' => '^\d+(\.\d*)?|\.\d+$',
49
            'required' => false,
50
            'info' => 'Valor da base de cálculo do PIS/PASEP (em valor)',
51
            'format' => '15v2'
52
        ],
53
        'ALIQ_PIS' => [
54
            'type' => 'numeric',
55
            'regex' => '^\d+(\.\d*)?|\.\d+$',
56
            'required' => false,
57
            'info' => 'Alíquota do PIS/PASEP (em percentual)',
58
            'format' => '8v4'
59
        ],
60
        'QUANT_BC_PIS' => [
61
            'type' => 'numeric',
62
            'regex' => '^\d+(\.\d*)?|\.\d+$',
63
            'required' => false,
64
            'info' => 'Base de cálculo PIS/PASEP (em quantidade)',
65
            'format' => '15v3'
66
        ],
67
        'ALIQ_PIS_QUANT' => [
68
            'type' => 'numeric',
69
            'regex' => '^\d+(\.\d*)?|\.\d+$',
70
            'required' => false,
71
            'info' => 'Alíquota do PIS (em reais)',
72
            'format' => '15v4'
73
        ],
74
        'VL_PIS' => [
75
            'type' => 'numeric',
76
            'regex' => '^\d+(\.\d*)?|\.\d+$',
77
            'required' => false,
78
            'info' => 'Valor do PIS/PASEP',
79
            'format' => '15v2'
80
        ],
81
        'CST_COFINS' => [
82
            'type' => 'numeric',
83
            'regex' => '^(\d{2})$',
84
            'required' => false,
85
            'info' => 'Código da Situação Tributária referente a Cofins, conforme a Tabela indicada no item 4.3.4.',
86
            'format' => ''
87
        ],
88
        'VL_BC_COFINS' => [
89
            'type' => 'numeric',
90
            'regex' => '^\d+(\.\d*)?|\.\d+$',
91
            'required' => false,
92
            'info' => 'Valor da base de cálculo da Cofins',
93
            'format' => '15v2'
94
        ],
95
        'ALIQ_COFINS' => [
96
            'type' => 'numeric',
97
            'regex' => '^\d+(\.\d*)?|\.\d+$',
98
            'required' => false,
99
            'info' => 'Alíquota da Cofins (em percentual)',
100
            'format' => '8v4'
101
        ],
102
        'QUANT_BC_COFINS' => [
103
            'type' => 'numeric',
104
            'regex' => '^\d+(\.\d*)?|\.\d+$',
105
            'required' => false,
106
            'info' => 'Base de cálculo COFINS (em quantidade)',
107
            'format' => '15v3'
108
        ],
109
        'ALIQ_COFINS_QUANT' => [
110
            'type' => 'numeric',
111
            'regex' => '^\d+(\.\d*)?|\.\d+$',
112
            'required' => false,
113
            'info' => 'Alíquota da COFINS (em reais)',
114
            'format' => '15v4'
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
        'INFO_COMPL' => [
131
            'type' => 'string',
132
            'regex' => '^(.*)$',
133
            'required' => false,
134
            'info' => 'Informação complementar',
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
    public function postValidation()
152
    {
153
        if (empty($this->values->vl_cofins)) {
154
            return;
155
        }
156
        $multiplicacao = null;
157 View Code Duplication
        if (!empty($this->values->vl_bc_cofins) && !empty($this->values->aliq_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...
158
            $multiplicacao = $this->values->vl_bc_cofins * $this->values->aliq_cofins;
159
        }
160 View Code Duplication
        if (!empty($this->values->quant_bc_cofins) && !empty($this->values->aliq_cofins_quant)) {
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...
161
            $multiplicacao = $this->values->quant_bc_cofins * $this->values->aliq_cofins_quant;
162
        }
163
        if ($multiplicacao == null) {
164
            return;
165
        }
166
        if (number_format($this->values->vl_cofins, 2) != number_format($multiplicacao, 2)) {
167
            throw new \InvalidArgumentException("[" . self::REG . "] " .
168
                "O campo VL_COFINS deve de ser o calculo da multiplicacao " .
169
                "da base de calculo do cofins com a aliquota do cofins");
170
        }
171
    }
172
}
173