E313::postValidation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 0
cts 7
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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 E313 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 = 'E313';
12
    const LEVEL = 5;
13
    const PARENT = 'E311';
14
15
    protected $parameters = [
16
        'COD_PART' => [
17
            'type'     => 'string',
18
            'regex'    => '^\d{1,60}+$',
19
            'required' => true,
20
            'info'     => 'Código do participante (campo 02 do Registro 0150)',
21
            'format'   => ''
22
        ],
23
        'COD_MOD' => [
24
            'type'     => 'string',
25
            'regex'    => '^\d{2}$',
26
            'required' => true,
27
            'info'     => 'Código do modelo do documento fiscal, conforme a Tabela 4.1.1',
28
            'format'   => ''
29
        ],
30
        'SER' => [
31
            'type'     => 'string',
32
            'regex'    => '^\d{1,4}+$',
33
            'required' => false,
34
            'info'     => 'Série do documento fiscal',
35
            'format'   => ''
36
        ],
37
        'SUB' => [
38
            'type'     => 'integer',
39
            'regex'    => '^\d{1,3}+$',
40
            'required' => false,
41
            'info'     => 'Subsérie do documento fiscal',
42
            'format'   => ''
43
        ],
44
        'NUM_DOC' => [
45
            'type'     => 'integer',
46
            'regex'    => '^([1-9])([0-9]{1,8}|)$',
47
            'required' => true,
48
            'info'     => 'Número do documento fiscal',
49
            'format'   => ''
50
        ],
51
        'DT_DOC' => [
52
            'type'     => 'integer',
53
            'regex'    => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$',
54
            'required' => true,
55
            'info'     => 'Data da emissão do documento fiscal'                  ,
56
            'format'   => ''
57
        ],
58
        'COD_ITEM' => [
59
            'type'     => 'string',
60
            'regex'    => '^.{1,60}$',
61
            'required' => false,
62
            'info'     => 'Código do item (campo 02 do Registro 0200)',
63
            'format'   => ''
64
        ],
65
        'VL_AJ_ITEM' => [
66
            'type'     => 'numeric',
67
            'regex'    => '^\d+(\.\d*)?|\.\d+$',
68
            'required' => true,
69
            'info'     => 'Valor do ajuste para a operação/item',
70
            'format'   => '15v2'
71
        ],
72
        'CHV_DOCE' => [
73
            'type'     => 'string',
74
            'regex'    => '^\d{44}+$',
75
            'required' => false,
76
            'info'     => 'Chave do Documento Eletrônico',
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
        $this->postValidation();
90
    }
91
92
    public function postValidation()
93
    {
94
        /*
95
         * Campo 10 (VL_AJ_ITEM) Validação: o valor informado no campo deve ser maior que “0” (zero).
96
         */
97
        if ($this->values->vl_aj_item <= 0) {
98
            throw new \InvalidArgumentException("[" . self::REG . "] O valor informado no campo deve "
99
            ."ser maior que “0” (zero).");
100
        }
101
    }
102
}
103