B035::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 6
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\ICMSIPI;
4
5
use NFePHP\EFD\Common\Element;
6
use NFePHP\EFD\Common\ElementInterface;
7
use \stdClass;
8
9 View Code Duplication
class B035 extends Element implements ElementInterface
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    const REG = 'B035';
12
    const LEVEL = 3;
13
    const PARENT = 'B030';
14
15
    protected $parameters = [
16
        'VL_CONT_P' => [
17
            'type'     => 'numeric',
18
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
19
            'required' => true,
20
            'info'     => 'Parcela correspondente ao "V alor Contábil" referente à combinação '
21
            .'da alíquota e item da lista',
22
            'format'   => '15v2'
23
        ],
24
        'VL_BC_ISS_P' => [
25
            'type'     => 'numeric',
26
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
27
            'required' => true,
28
            'info'     => 'Parcela correspondente ao "Valor da base de cálculo do ISS" referente '
29
            .'à combinação da alíquota e item da lista',
30
            'format'   => '15v2'
31
        ],
32
        'ALIQ_ISS' => [
33
            'type'     => 'integer',
34
            'regex'    => '^[0-5]{1}$',
35
            'required' => true,
36
            'info'     => 'Alíquota do ISS',
37
            'format'   => ''
38
        ],
39
        'VL_ISS_P' => [
40
            'type'     => 'numeric',
41
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
42
            'required' => true,
43
            'info'     => 'Parcela correspondente ao "Valor do ISS" referente à combinação da '
44
            .'alíquota e item da lista',
45
            'format'   => '15v2'
46
        ],
47
        'VL_ISNT_ISS_P' => [
48
            'type'     => 'numeric',
49
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
50
            'required' => true,
51
            'info'     => 'Parcela correspondente ao "Valor das operações isentas ou não-tributadas '
52
            .'pelo ISS" referente à combinação da alíquota e item da lista',
53
            'format'   => '15v2'
54
        ],
55
        'COD_SERV' => [
56
            'type'     => 'string',
57
            'regex'    => '^.{4}$',
58
            'required' => true,
59
            'info'     => 'Item da lista de serviços, conforme Tabela 4.6.3.',
60
            'format'   => ''
61
        ]
62
    ];
63
64
    /**
65
     * Constructor
66
     * @param \stdClass $std
67
     */
68
    public function __construct(\stdClass $std)
69
    {
70
        parent::__construct(self::REG);
71
        $this->std = $this->standarize($std);
72
        $this->postValidation();
73
    }
74
75
    public function postValidation()
76
    {
77
        /*
78
         * Campo 05 (VL_ISS_P) Validação: O valor deve ser igual ao produto
79
         * da base de cálculo “VL_BC_ISS_P” pela alíquota “ALIQ_ISS”.
80
         */
81
        $vl_iss_p = ($this->values->vl_bc_iss_p/100) * $this->std->aliq_iss;
82
        $vl_iss_p = (float) number_format((float) $vl_iss_p, 2, '.', '');
83
        
84
        if ($this->values->vl_iss_p != $vl_iss_p) {
85
            throw new \InvalidArgumentException("[" . self::REG . "] O valor informado no campo “VL_ISS_P” "
86
            ."deve ser igual ao produto da base de cálculo “VL_BC_ISS_P” pela alíquota “ALIQ_ISS”.");
87
        }
88
    }
89
}
90