C810   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 115
ccs 0
cts 15
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 9 2
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 C810 extends Element implements ElementInterface
10
{
11
    const REG = 'C810';
12
    const LEVEL = 4;
13
    const PARENT = 'C800';
14
15
    protected $parameters = [
16
        'CFOP' => [
17
            'type' => 'numeric',
18
            'regex' => '^(\d{0,4})$',
19
            'required' => false,
20
            'info' => 'Código fiscal de operação e prestação',
21
            'format' => ''
22
        ],
23
        'VL_ITEM' => [
24
            'type' => 'numeric',
25
            'regex' => '^\d+(\.\d*)?|\.\d+$',
26
            'required' => false,
27
            'info' => 'Valor total dos itens',
28
            'format' => '15v2'
29
        ],
30
        'COD_ITEM' => [
31
            'type' => 'string',
32
            'regex' => '^.{0,60}$',
33
            'required' => false,
34
            'info' => 'Código do item (campo 02 do Registro 0200)',
35
            'format' => ''
36
        ],
37
        'CST_PIS' => [
38
            'type' => 'numeric',
39
            'regex' => '^((0[1-9])|49|99)$',
40
            'required' => false,
41
            'info' => 'Código da Situação Tributária referente ao PIS/PASEP',
42
            'format' => ''
43
        ],
44
        'VL_BC_PIS' => [
45
            'type' => 'numeric',
46
            'regex' => '^\d+(\.\d*)?|\.\d+$',
47
            'required' => false,
48
            'info' => 'Valor da base de cálculo do PIS/PASEP',
49
            'format' => '15v2'
50
        ],
51
        'ALIQ_PIS' => [
52
            'type' => 'numeric',
53
            'regex' => '^\d+(\.\d*)?|\.\d+$',
54
            'required' => false,
55
            'info' => 'Alíquota do PIS/PASEP (em percentual)',
56
            'format' => '8v4'
57
        ],
58
        'VL_PIS' => [
59
            'type' => 'numeric',
60
            'regex' => '^\d+(\.\d*)?|\.\d+$',
61
            'required' => false,
62
            'info' => 'Valor do PIS/PASEP',
63
            'format' => '15v2'
64
        ],
65
        'CST_COFINS' => [
66
            'type' => 'numeric',
67
            'regex' => '^(\d{2})$',
68
            'required' => false,
69
            'info' => 'Código da Situação Tributária referente a COFINS',
70
            'format' => ''
71
        ],
72
        'VL_BC_COFINS' => [
73
            'type' => 'numeric',
74
            'regex' => '^\d+(\.\d*)?|\.\d+$',
75
            'required' => false,
76
            'info' => 'Valor da base de cálculo da COFINS',
77
            'format' => '15v2'
78
        ],
79
        'ALIQ_COFINS' => [
80
            'type' => 'numeric',
81
            'regex' => '^\d+(\.\d*)?|\.\d+$',
82
            'required' => false,
83
            'info' => 'Alíquota da COFINS (em percentual)',
84
            'format' => '8v4'
85
        ],
86
        'VL_COFINS' => [
87
            'type' => 'numeric',
88
            'regex' => '^\d+(\.\d*)?|\.\d+$',
89
            'required' => false,
90
            'info' => 'Valor da COFINS',
91
            'format' => '15v2'
92
        ],
93
        'COD_CTA' => [
94
            'type' => 'string',
95
            'regex' => '^.{0,255}$',
96
            'required' => false,
97
            'info' => 'Código da conta analítica contábil debitada/creditada',
98
            'format' => ''
99
        ],
100
101
    ];
102
103
    /**
104
     * Constructor
105
     * @param \stdClass $std
106
     */
107
    public function __construct(\stdClass $std)
108
    {
109
        parent::__construct(self::REG);
110
        $this->std = $this->standarize($std);
111
        $this->postValidation();
112
    }
113
114
    public function postValidation()
115
    {
116
        $multiplicacao = $this->values->vl_bc_pis * $this->values->aliq_pis;
117
        if (number_format($this->values->vl_pis, 2) != number_format($multiplicacao / 100, 2)) {
118
            throw new \InvalidArgumentException("[" . self::REG . "] " .
119
                "O campo VL_PIS deve de ser o calculo da multiplicacao " .
120
                "da base de calculo do PIS com a aliquota do PIS, o resultado dividido por 100");
121
        }
122
    }
123
}
124