Z1700::__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 Z1700 extends Element implements ElementInterface
10
{
11
    const REG = '1700';
12
    const LEVEL = 2;
13
    const PARENT = '1001';
14
15
    protected $parameters = [
16
        'IND_NAT_RET' => [
17
            'type' => 'numeric',
18
            'regex' => '^(01|02|03|04|05|09)$',
19
            'required' => false,
20
            'info' => 'Indicador de Natureza da Retenção na Fonte até 2013 ' .
21
                ' 01 - Retenção por Órgãos, Autarquias e Fundações Federais 02 - Retenção por ' .
22
                'outras Entidades da Administração Pública Federal 03 - Retenção por Pessoas ' .
23
                'Jurídicas de Direito Privado 04 - Recolhimento por Sociedade Cooperativa 05 - Retenção ' .
24
                'por Fabricante de Máquinas e Veículos 99 - Outras Retenções ',
25
            'format' => ''
26
        ],
27
        'PR_REC_RET' => [
28
            'type' => 'numeric',
29
            'regex' => '^(\d{6})$',
30
            'required' => false,
31
            'info' => 'Período do Recebimento e da Retenção (MM/AAAA) ',
32
            'format' => ''
33
        ],
34
        'VL_RET_APU' => [
35
            'type' => 'numeric',
36
            'regex' => '^\d+(\.\d*)?|\.\d+$',
37
            'required' => false,
38
            'info' => 'Valor Total da Retenção ',
39
            'format' => '15v2'
40
        ],
41
        'VL_RET_DED' => [
42
            'type' => 'numeric',
43
            'regex' => '^\d+(\.\d*)?|\.\d+$',
44
            'required' => false,
45
            'info' => 'Valor da Retenção deduzida da Contribuição devida no período da escrituração e em ' .
46
                'períodos anteriores. ',
47
            'format' => '15v2'
48
        ],
49
        'VL_RET_PER' => [
50
            'type' => 'numeric',
51
            'regex' => '^\d+(\.\d*)?|\.\d+$',
52
            'required' => false,
53
            'info' => 'Valor da Retenção utilizada mediante Pedido de Restituição. ',
54
            'format' => '15v2'
55
        ],
56
        'VL_RET_DCOMP' => [
57
            'type' => 'numeric',
58
            'regex' => '^\d+(\.\d*)?|\.\d+$',
59
            'required' => false,
60
            'info' => 'Valor da Retenção utilizada mediante Declaração de Compensação. ',
61
            'format' => '15v2'
62
        ],
63
        'SLD_RET' => [
64
            'type' => 'numeric',
65
            'regex' => '^\d+(\.\d*)?|\.\d+$',
66
            'required' => false,
67
            'info' => 'Saldo de Retenção a utilizar em períodos de apuração futuros (04 - 05 - 06 - 07). ',
68
            'format' => '15v2'
69
        ],
70
71
    ];
72
73
    /**
74
     * Constructor
75
     * @param \stdClass $std
76
     */
77
    public function __construct(\stdClass $std)
78
    {
79
        parent::__construct(self::REG);
80
        $this->std = $this->standarize($std);
81
        $this->postValidation();
82
    }
83
84 View Code Duplication
    public function postValidation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
85
    {
86
        $calculo = $this->values->vl_ret_apu-
87
            $this->values->vl_ret_ded-
88
            $this->values->vl_ret_per-
89
            $this->values->vl_ret_dcomp;
90
        if (number_format($this->values->sld_ret, 2)!==number_format($calculo, 2)) {
91
            throw new \InvalidArgumentException("[" . self::REG . "] " .
92
                "O valor do campo SLD_RET deverá ser igual a 
93
                VL_RET_APU - VL_RET_DED - VL_RET_PER - VL_RET_DCOMP. ");
94
        }
95
    }
96
}
97