Completed
Pull Request — master (#274)
by
unknown
10:53
created

C495::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 0
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
class C495 extends Element implements ElementInterface
10
{
11
    const REG = 'C495';
12
    const LEVEL = 2;
13
    const PARENT = 'C400';
14
15
    protected $parameters = [
16
        'ALIQ_ICMS' => [
17
            'type' => 'numeric',
18
            'regex' => '^\d+(\.\d*)?|\.\d+$',
19
            'required' => false,
20
            'info' => 'Alíquota do ICMS',
21
            'format' => '6v2'
22
        ],
23
        'COD_ITEM' => [
24
            'type' => 'string',
25
            'regex' => '^.{1,60}$',
26
            'required' => true,
27
            'info' => 'Código do item (campo 02 do Registro 0200)',
28
            'format' => ''
29
        ],
30
        'QTD' => [
31
            'type' => 'numeric',
32
            'regex' => '^\d+(\.\d*)?|\.\d+$',
33
            'required' => true,
34
            'info' => 'Quantidade acumulada do item',
35
            'format' => '15v3'
36
        ],
37
        'QTD_CANC' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => false,
41
            'info' => 'Quantidade cancelada acumulada, no caso de cancelamento parcial de item',
42
            'format' => '15v3'
43
        ],
44
        'UNID' => [
45
            'type' => 'string',
46
            'regex' => '^.{1,6}$',
47
            'required' => true,
48
            'info' => 'Unidade do item (Campo 02 do registro 0190)',
49
            'format' => ''
50
        ],
51
        'VL_ITEM' => [
52
            'type' => 'numeric',
53
            'regex' => '^\d+(\.\d*)?|\.\d+$',
54
            'required' => true,
55
            'info' => 'Valor acumulado do item',
56
            'format' => '15v2'
57
        ],
58
        'VL_DESC' => [
59
            'type' => 'numeric',
60
            'regex' => '^\d+(\.\d*)?|\.\d+$',
61
            'required' => false,
62
            'info' => 'Valor acumulado dos descontos',
63
            'format' => '15v2'
64
        ],
65
        'VL_CANC' => [
66
            'type' => 'numeric',
67
            'regex' => '^\d+(\.\d*)?|\.\d+$',
68
            'required' => false,
69
            'info' => 'Valor acumulado dos cancelamentos',
70
            'format' => '15v2'
71
        ],
72
        'VL_ACMO' => [
73
            'type' => 'numeric',
74
            'regex' => '^\d+(\.\d*)?|\.\d+$',
75
            'required' => false,
76
            'info' => 'Valor acumulado dos acréscimos',
77
            'format' => '15v2'
78
        ],
79
        'VL_BC_ICMS' => [
80
            'type' => 'numeric',
81
            'regex' => '^\d+(\.\d*)?|\.\d+$',
82
            'required' => false,
83
            'info' => 'Valor acumulado da base de cálculo do ICMS',
84
            'format' => '15v2'
85
        ],
86
        'VL_ICMS' => [
87
            'type' => 'numeric',
88
            'regex' => '^\d+(\.\d*)?|\.\d+$',
89
            'required' => false,
90
            'info' => 'Valor acumulado do ICMS',
91
            'format' => '15v2'
92
        ],
93
        'VL_ISEN' => [
94
            'type' => 'numeric',
95
            'regex' => '^\d+(\.\d*)?|\.\d+$',
96
            'required' => false,
97
            'info' => 'Valor das saídas isentas do ICMS',
98
            'format' => '15v2'
99
        ],
100
        'VL_NT' => [
101
            'type' => 'numeric',
102
            'regex' => '^\d+(\.\d*)?|\.\d+$',
103
            'required' => false,
104
            'info' => 'Valor das saídas sob não-incidência ou não- tributadas pelo ICMS',
105
            'format' => '15v2'
106
        ],
107
        'VL_ICMS_ST' => [
108
            'type' => 'numeric',
109
            'regex' => '^\d+(\.\d*)?|\.\d+$',
110
            'required' => false,
111
            'info' => 'Valor das saídas de mercadorias adquiridas com substituição tributária do ICMS',
112
            'format' => '15v2'
113
        ],
114
    ];
115
116
    /**
117
     * Constructor
118
     * @param \stdClass $std
119
     */
120
    public function __construct(\stdClass $std)
121
    {
122
        parent::__construct(self::REG);
123
        $this->std = $this->standarize($std);
124
    }
125
126
127
    /**
128
     * Transforma o valor com virgula em float para poder fazer os calculos de verificacao
129
     * @param $vlr
130
     * @return mixed
131
     */
132
    private function strToFloat($vlr)
133
    {
134
        return (float)str_replace(',', '.', $this->std->$vlr);
135
    }
136
137
138
    public function postValidation()
139
    {
140 View Code Duplication
        if ($this->strToFloat('qtd') <= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
141
            throw new \InvalidArgumentException("[" . self::REG . "] " .
142
                " O do campo QTD deve ser maior do que 0");
143
        }
144 View Code Duplication
        if ($this->strToFloat('vl_item') <= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
145
            throw new \InvalidArgumentException("[" . self::REG . "] " .
146
                " O do campo VL_ITEM deve ser maior do que 0");
147
        }
148
    }
149
}
150