Completed
Push — master ( 74d6ff...309b24 )
by Roberto
43:07 queued 28:08
created

C490::strToFloat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
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 View Code Duplication
class C490 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 = 'C490';
12
    const LEVEL = 4;
13
    const PARENT = 'C400';
14
15
    protected $parameters = [
16
        'CST_ICMS' => [
17
            'type' => 'numeric',
18
            'regex' => '^(\d{3})$',
19
            'required' => true,
20
            'info' => 'Código da Situação Tributária,',
21
            'format' => ''
22
        ],
23
        'CFOP' => [
24
            'type' => 'numeric',
25
            'regex' => '^(\d{4})$',
26
            'required' => true,
27
            'info' => 'Código Fiscal de Operação e Prestação',
28
            'format' => ''
29
        ],
30
        'ALIQ_ICMS' => [
31
            'type' => 'numeric',
32
            'regex' => '^\d+(\.\d*)?|\.\d+$',
33
            'required' => false,
34
            'info' => 'Alíquota do ICMS',
35
            'format' => '6v2'
36
        ],
37
        'VL_OPR' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => true,
41
            'info' => 'Valor da operação correspondente à combinação de CST_ICMS, CFOP, e alíquota do ICMS, 
42
            incluídas as despesas acessórias e acréscimos',
43
            'format' => '15v2'
44
        ],
45
        'VL_BC_ICMS' => [
46
            'type' => 'numeric',
47
            'regex' => '^\d+(\.\d*)?|\.\d+$',
48
            'required' => true,
49
            'info' => 'Valor acumulado da base de cálculo do ICMS, referente à combinação 
50
            de CST_ICMS, CFOP, e alíquota do ICMS.',
51
            'format' => '15v2'
52
        ],
53
        'VL_ICMS' => [
54
            'type' => 'numeric',
55
            'regex' => '^\d+(\.\d*)?|\.\d+$',
56
            'required' => true,
57
            'info' => 'Valor acumulado do ICMS, referente à combinação de CST_ICMS, CFOP e alíquota do ICMS.',
58
            'format' => '15v2'
59
        ],
60
        'COD_OBS' => [
61
            'type' => 'string',
62
            'regex' => '^.{0,6}$',
63
            'required' => false,
64
            'info' => 'Código da observação do lançamento fiscal (campo 02 do Registro 0460)',
65
            'format' => ''
66
        ],
67
    ];
68
69
    /**
70
     * Constructor
71
     * @param \stdClass $std
72
     */
73
    public function __construct(\stdClass $std)
74
    {
75
        parent::__construct(self::REG);
76
        $this->std = $this->standarize($std);
77
        $this->postValidation();
78
    }
79
80
    public function postValidation()
81
    {
82
        //pega o fim da string do CST_ICMS e faz a verificacao
83
        $cstIcmsLast = (int) substr($this->std->cst_icms, -2);
84
        if (in_array($cstIcmsLast, [30, 40, 41, 50, 60])) {
85
            if ($this->values->vl_bc_icms != 0) {
86
                throw new \InvalidArgumentException("[" . self::REG . "] " .
87
                    " O do campo VL_BC_ICMS deve ser Igual 0");
88
            }
89
            if ($this->values->aliq_icms != 0) {
90
                throw new \InvalidArgumentException("[" . self::REG . "] " .
91
                    " O do campo VL_ICMS deve ser Igual 0");
92
            }
93
            if ($this->values->vl_icms != 0) {
94
                throw new \InvalidArgumentException("[" . self::REG . "] " .
95
                    " O do campo ALIQ_ICMS deve ser Igual 0");
96
            }
97
        } elseif (!in_array($cstIcmsLast, [51, 90])) {
98
            if ($this->values->vl_bc_icms <= 0) {
99
                throw new \InvalidArgumentException("[" . self::REG . "] " .
100
                    " O do campo VL_BC_ICMS deve ser maior do que 0");
101
            }
102
            if ($this->values->aliq_icms <= 0) {
103
                throw new \InvalidArgumentException("[" . self::REG . "] " .
104
                    " O do campo ALIQ_ICMS deve ser maior do que 0");
105
            }
106
            if ($this->values->vl_icms <= 0) {
107
                throw new \InvalidArgumentException("[" . self::REG . "] " .
108
                    " O do campo VL_ICMS deve ser maior do que 0");
109
            }
110
        }
111
    }
112
}
113