Z0111::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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 Z0111 extends Element implements ElementInterface
10
{
11
    const REG = '0111';
12
    const LEVEL = 3;
13
    const PARENT = '0110';
14
15
    protected $parameters = [
16
        'REC_BRU_NCUM_TRIB_MI' => [
17
            'type' => 'numeric',
18
            'regex' => '^\d+(\.\d*)?|\.\d+$',
19
            'required' => false,
20
            'info' => 'Receita Bruta Não-Cumulativa - Tributada no Mercado Interno',
21
            'format' => '15v2'
22
        ],
23
        'REC_BRU_NCUM_NT_MI' => [
24
            'type' => 'numeric',
25
            'regex' => '^\d+(\.\d*)?|\.\d+$',
26
            'required' => false,
27
            'info' => 'Receita Bruta Não-Cumulativa – Não Tributada no Mercado Interno
28
             (Vendas com suspensão, alíquota zero, isenção e sem incidência das contribuições)',
29
            'format' => '15v2'
30
        ],
31
        'REC_BRU_NCUM_EXP' => [
32
            'type' => 'numeric',
33
            'regex' => '^\d+(\.\d*)?|\.\d+$',
34
            'required' => false,
35
            'info' => 'Receita Bruta Não-Cumulativa – Exportação',
36
            'format' => '15v2'
37
        ],
38
        'REC_BRU_CUM' => [
39
            'type' => 'numeric',
40
            'regex' => '^\d+(\.\d*)?|\.\d+$',
41
            'required' => false,
42
            'info' => 'Receita Bruta Cumulativa',
43
            'format' => '15v2'
44
        ],
45
        'REC_BRU_TOTAL' => [
46
            'type' => 'numeric',
47
            'regex' => '^\d+(\.\d*)?|\.\d+$',
48
            'required' => false,
49
            'info' => 'Receita Bruta Total',
50
            'format' => '15v2'
51
        ],
52
53
    ];
54
55
    /**
56
     * Constructor
57
     * @param \stdClass $std
58
     */
59
    public function __construct(\stdClass $std)
60
    {
61
        parent::__construct(self::REG);
62
        $this->std = $this->standarize($std);
63
        $this->postValidation();
64
    }
65
66
    public function postValidation()
67
    {
68
        $somatorio = $this->values->rec_bru_ncum_trib_mi;
69
        $somatorio += $this->values->rec_bru_ncum_nt_mi;
70
        $somatorio += $this->values->rec_bru_ncum_exp;
71
        $somatorio += $this->values->rec_bru_cum;
72
73
        if ($this->values->rec_bru_total != $somatorio) {
74
            throw new \InvalidArgumentException("[" . self::REG . "] " .
75
                " A soma dos valores dos campos 02, 03, 04 e " .
76
                "05 deve ser igual ao valor informado no campo REC_BRU_TOTAL.");
77
        }
78
    }
79
}
80