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

C425::__construct()   A

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 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 C425 extends Element implements ElementInterface
10
{
11
    const REG = 'C425';
12
    const LEVEL = 5;
13
    const PARENT = 'C420';
14
15
    protected $parameters = [
16
        'COD_ITEM' => [
17
            'type' => 'string',
18
            'regex' => '^.{1,60}$',
19
            'required' => true,
20
            'info' => 'Código do item (campo 02 do Registro 0200)',
21
            'format' => ''
22
        ],
23
        'QTD' => [
24
            'type' => 'numeric',
25
            'regex' => '^\d+(\.\d*)?|\.\d+$',
26
            'required' => true,
27
            'info' => 'Quantidade acumulada do item',
28
            'format' => '15v3'
29
        ],
30
        'UNID' => [
31
            'type' => 'string',
32
            'regex' => '^.{1,6}$',
33
            'required' => true,
34
            'info' => 'Unidade do item (Campo 02 do registro 0190)',
35
            'format' => ''
36
        ],
37
        'VL_ITEM' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => true,
41
            'info' => 'Valor acumulado do item',
42
            'format' => '15v2'
43
        ],
44
        'VL_PIS' => [
45
            'type' => 'numeric',
46
            'regex' => '^\d+(\.\d*)?|\.\d+$',
47
            'required' => false,
48
            'info' => 'Valor do PIS',
49
            'format' => '15v2'
50
        ],
51
        'VL_COFINS' => [
52
            'type' => 'numeric',
53
            'regex' => '^\d+(\.\d*)?|\.\d+$',
54
            'required' => false,
55
            'info' => 'Valor da COFINS',
56
            'format' => '15v2'
57
        ],
58
    ];
59
60
    /**
61
     * Constructor
62
     * @param \stdClass $std
63
     */
64
    public function __construct(\stdClass $std)
65
    {
66
        parent::__construct(self::REG);
67
        $this->std = $this->standarize($std);
68
        $this->postValidation();
69
    }
70
71
    /**
72
     * Transforma o valor com virgula em float para poder fazer os calculos de verificacao
73
     * @param $vlr
74
     * @return mixed
75
     */
76
    private function strToFloat($vlr)
77
    {
78
        return (float)str_replace(',', '.', $this->std->$vlr);
79
    }
80
81
82
    public function postValidation()
83
    {
84
        $vlItem = $this->strToFloat('vl_item');
85
        if ($vlItem <= 0) {
86
            throw new \InvalidArgumentException("[" . self::REG . "] " .
87
                " O Valor acumulado do item (VL_ITEM) deve ser maior que 0");
88
        }
89
    }
90
}
91