C385   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 98
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
A postValidation() 0 13 3
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 C385 extends Element implements ElementInterface
10
{
11
    const REG = 'C385';
12
    const LEVEL = 4;
13
    const PARENT = 'C380';
14
15
    protected $parameters = [
16
        'CST_COFINS' => [
17
            'type' => 'numeric',
18
            'regex' => '^((0[1-9])|49|99)$',
19
            'required' => false,
20
            'info' => 'Código da Situação Tributária referente a COFINS.',
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
        'VL_ITEM' => [
31
            'type' => 'numeric',
32
            'regex' => '^\d+(\.\d*)?|\.\d+$',
33
            'required' => false,
34
            'info' => 'Valor total dos itens',
35
            'format' => '15v2'
36
        ],
37
        'VL_BC_COFINS' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => false,
41
            'info' => 'Valor da base de cálculo da COFINS',
42
            'format' => '15v2'
43
        ],
44
        'ALIQ_COFINS' => [
45
            'type' => 'numeric',
46
            'regex' => '^\d+(\.\d*)?|\.\d+$',
47
            'required' => false,
48
            'info' => 'Alíquota da COFINS (em percentual)',
49
            'format' => '8v4'
50
        ],
51
        'QUANT_BC_COFINS' => [
52
            'type' => 'numeric',
53
            'regex' => '^\d+(\.\d*)?|\.\d+$',
54
            'required' => false,
55
            'info' => 'Quantidade – Base de cálculo da COFINS',
56
            'format' => '15v3'
57
        ],
58
        'ALIQ_COFINS_QUANT' => [
59
            'type' => 'numeric',
60
            'regex' => '^\d+(\.\d*)?|\.\d+$',
61
            'required' => false,
62
            'info' => 'Alíquota da COFINS (em reais)',
63
            'format' => '15v4'
64
        ],
65
        'VL_COFINS' => [
66
            'type' => 'numeric',
67
            'regex' => '^\d+(\.\d*)?|\.\d+$',
68
            'required' => false,
69
            'info' => 'Valor da COFINS',
70
            'format' => '15v2'
71
        ],
72
        'COD_CTA' => [
73
            'type' => 'string',
74
            'regex' => '^.{0,255}$',
75
            'required' => false,
76
            'info' => 'Código da conta analítica contábil debitada/creditada',
77
            'format' => ''
78
        ],
79
80
    ];
81
82
    /**
83
     * Constructor
84
     * @param \stdClass $std
85
     */
86
    public function __construct(\stdClass $std)
87
    {
88
        parent::__construct(self::REG);
89
        $this->std = $this->standarize($std);
90
        $this->postValidation();
91
    }
92
93
    public function postValidation()
94
    {
95
        $multiplicacao = $this->values->vl_bc_cofins * $this->values->aliq_cofins;
96
        if ($this->values->quant_bc_cofins > 0) {
97
            $multiplicacao = $this->values->quant_bc_cofins * $this->values->aliq_cofins_quant;
98
        }
99
100
        if (number_format($this->values->vl_cofins, 2) != number_format($multiplicacao, 2)) {
101
            throw new \InvalidArgumentException("[" . self::REG . "] " .
102
                "O campo VL_COFINS deve de ser o calculo da multiplicacao " .
103
                "da base de calculo do cofins com a aliquota do cofins");
104
        }
105
    }
106
}
107