Z1300   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 84
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 12
loc 84
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A postValidation() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
class Z1300 extends Element implements ElementInterface
10
{
11
    const REG = '1300';
12
    const LEVEL = 2;
13
    const PARENT = '1001';
14
15
    protected $parameters = [
16
        'IND_NAT_RET' => [
17
            'type' => 'numeric',
18
            'regex' => '^(1|2|3|4|5|9|1|2|3|4|5|9|1|2|3|4|5|9)$',
19
            'required' => false,
20
            'info' => 'Indicador de Natureza da Retenção na Fonte',
21
            'format' => ''
22
        ],
23
        'PR_REC_RET' => [
24
            'type' => 'numeric',
25
            'regex' => '^(\d{0,6})$',
26
            'required' => false,
27
            'info' => 'Período do Recebimento e da Retenção (MM/AAAA) ',
28
            'format' => ''
29
        ],
30
        'VL_RET_APU' => [
31
            'type' => 'numeric',
32
            'regex' => '^\d+(\.\d*)?|\.\d+$',
33
            'required' => false,
34
            'info' => 'Valor Total da Retenção ',
35
            'format' => '15v2'
36
        ],
37
        'VL_RET_DED' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => false,
41
            'info' => 'Valor da Retenção deduzida da Contribuição devida no período da escrituração e em ' .
42
                'períodos anteriores. ',
43
            'format' => '15v2'
44
        ],
45
        'VL_RET_PER' => [
46
            'type' => 'numeric',
47
            'regex' => '^\d+(\.\d*)?|\.\d+$',
48
            'required' => false,
49
            'info' => 'Valor da Retenção utilizada mediante Pedido de Restituição. ',
50
            'format' => '15v2'
51
        ],
52
        'VL_RET_DCOMP' => [
53
            'type' => 'numeric',
54
            'regex' => '^\d+(\.\d*)?|\.\d+$',
55
            'required' => false,
56
            'info' => 'Valor da Retenção utilizada mediante Declaração de Compensação. ',
57
            'format' => '15v2'
58
        ],
59
        'SLD_RET' => [
60
            'type' => 'numeric',
61
            'regex' => '^\d+(\.\d*)?|\.\d+$',
62
            'required' => false,
63
            'info' => 'Saldo de Retenção a utilizar em períodos de apuração futuros (04 – 05 - 06 - 07). ',
64
            'format' => '15v2'
65
        ],
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 View Code Duplication
    public function postValidation()
0 ignored issues
show
Duplication introduced by
This method 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...
81
    {
82
        $calculo = $this->values->vl_ret_apu-
83
            $this->values->vl_ret_ded-
84
            $this->values->vl_ret_per-
85
            $this->values->vl_ret_dcomp;
86
        if (number_format($this->values->sld_ret, 2)!==number_format($calculo, 2)) {
87
            throw new \InvalidArgumentException("[" . self::REG . "] " .
88
                "O valor do campo SLD_RET deverá ser igual a 
89
                VL_RET_APU - VL_RET_DED - VL_RET_PER - VL_RET_DCOMP. ");
90
        }
91
    }
92
}
93