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

C460::__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 C460 extends Element implements ElementInterface
10
{
11
    const REG = 'C460';
12
    const LEVEL = 4;
13
    const PARENT = 'C400';
14
15
    protected $parameters = [
16
        'COD_MOD' => [
17
            'type' => 'string',
18
            'regex' => '^(02|2D|60)$',
19
            'required' => true,
20
            'info' => 'Código do modelo do documento fiscal',
21
            'format' => ''
22
        ],
23
        'COD_SIT' => [
24
            'type' => 'numeric',
25
            'regex' => '^(00|01|02)$',
26
            'required' => true,
27
            'info' => 'Código da situação do documento fiscal',
28
            'format' => ''
29
        ],
30
        'NUM_DOC' => [
31
            'type' => 'numeric',
32
            'regex' => '^([1-9]{1})(\d{1,8})?$',
33
            'required' => true,
34
            'info' => 'Número do documento fiscal (COO)',
35
            'format' => ''
36
        ],
37
        'DT_DOC' => [
38
            'type' => 'string',
39
            'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
40
            'required' => true,
41
            'info' => 'Data da emissão do documento fiscal',
42
            'format' => ''
43
        ],
44
        'VL_DOC' => [
45
            'type' => 'numeric',
46
            'regex' => '^\d+(\.\d*)?|\.\d+$',
47
            'required' => true,
48
            'info' => 'Valor total do documento fiscal',
49
            'format' => '15v2'
50
        ],
51
        'VL_PIS' => [
52
            'type' => 'numeric',
53
            'regex' => '^\d+(\.\d*)?|\.\d+$',
54
            'required' => false,
55
            'info' => 'Valor do PIS',
56
            'format' => '15v2'
57
        ],
58
        'VL_COFINS' => [
59
            'type' => 'numeric',
60
            'regex' => '^\d+(\.\d*)?|\.\d+$',
61
            'required' => false,
62
            'info' => 'Valor da COFINS',
63
            'format' => '15v2'
64
        ],
65
        'CPF_CNPJ' => [
66
            'type' => 'string',
67
            'regex' => '^([0-9]{11}|[0-9]{14})$',
68
            'required' => false,
69
            'info' => 'CPF ou CNPJ do adquirente',
70
            'format' => ''
71
        ],
72
        'NOM_ADQ' => [
73
            'type' => 'string',
74
            'regex' => '^.{0,60}$',
75
            'required' => false,
76
            'info' => 'Nome do adquirente',
77
            'format' => ''
78
        ],
79
    ];
80
81
    /**
82
     * Constructor
83
     * @param \stdClass $std
84
     */
85
    public function __construct(\stdClass $std)
86
    {
87
        parent::__construct(self::REG);
88
        $this->std = $this->standarize($std);
89
    }
90
91
92
    /**
93
     * Transforma o valor com virgula em float para poder fazer os calculos de verificacao
94
     * @param $vlr
95
     * @return mixed
96
     */
97
    private function strToFloat($vlr)
98
    {
99
        return (float)str_replace(',', '.', $this->std->$vlr);
100
    }
101
102
103
    public function postValidation()
104
    {
105
        $vlDoc = $this->strToFloat('vl_doc');
106
        if ($vlDoc <= 0) {
107
            throw new \InvalidArgumentException("[" . self::REG . "] " .
108
                " O Valor totao do documento fiscal " .
109
                "(VL_DOC) deve ser maior que 0");
110
        }
111
    }
112
}
113