C601::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 0
cts 6
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\Contribuicoes;
4
5
use NFePHP\EFD\Common\Element;
6
use NFePHP\EFD\Common\ElementInterface;
7
use \stdClass;
8
9 View Code Duplication
class C601 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 = 'C601';
12
    const LEVEL = 4;
13
    const PARENT = 'C600';
14
15
    protected $parameters = [
16
        'CST_PIS' => [
17
            'type' => 'numeric',
18
            'regex' => '^((0[1-9])|49|99)$',
19
            'required' => false,
20
            'info' => 'Código da Situação Tributária referente ao PIS/PASEP',
21
            'format' => ''
22
        ],
23
        'VL_ITEM' => [
24
            'type' => 'numeric',
25
            'regex' => '^\d+(\.\d*)?|\.\d+$',
26
            'required' => false,
27
            'info' => 'Valor total dos itens',
28
            'format' => '15v2'
29
        ],
30
        'VL_BC_PIS' => [
31
            'type' => 'numeric',
32
            'regex' => '^\d+(\.\d*)?|\.\d+$',
33
            'required' => false,
34
            'info' => 'Valor da base de cálculo do PIS/PASEP',
35
            'format' => '15v2'
36
        ],
37
        'ALIQ_PIS' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => false,
41
            'info' => 'Alíquota do PIS/PASEP (em percentual)',
42
            'format' => '8v4'
43
        ],
44
        'VL_PIS' => [
45
            'type' => 'numeric',
46
            'regex' => '^\d+(\.\d*)?|\.\d+$',
47
            'required' => false,
48
            'info' => 'Valor do PIS/PASEP',
49
            'format' => '15v2'
50
        ],
51
        'COD_CTA' => [
52
            'type' => 'string',
53
            'regex' => '^.{0,255}$',
54
            'required' => false,
55
            'info' => 'Código da conta analítica contábil debitada/creditada',
56
            'format' => ''
57
        ],
58
59
    ];
60
61
    /**
62
     * Constructor
63
     * @param \stdClass $std
64
     */
65
    public function __construct(\stdClass $std)
66
    {
67
        parent::__construct(self::REG);
68
        $this->std = $this->standarize($std);
69
        $this->postValidation();
70
    }
71
72
    public function postValidation()
73
    {
74
        $multiplicacao = $this->values->vl_bc_pis * $this->values->aliq_pis;
75
        if (number_format($this->values->vl_pis, 2) != number_format($multiplicacao/100, 2)) {
76
            throw new \InvalidArgumentException("[" . self::REG . "] " .
77
                "O campo VL_PIS deve de ser o calculo da multiplicacao " .
78
                "da base de calculo do PIS com a aliquota do PIS, o resultado dividido por 100");
79
        }
80
    }
81
}
82