Passed
Push — master ( 69529f...d0bdbe )
by Roberto
02:28
created

EvtFechaEvPer::toNode()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 117
Code Lines 92

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 117
ccs 0
cts 111
cp 0
rs 8.1463
c 0
b 0
f 0
cc 5
eloc 92
nc 2
nop 0
crap 30

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\EFDReinf\Factories;
4
5
/**
6
 * Class EFD-Reinf EvtFechaEvPer Event R-2099 constructor
7
 *
8
 * @category  API
9
 * @package   NFePHP\EFDReinf
10
 * @copyright NFePHP Copyright (c) 2017
11
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
12
 * @license   https://opensource.org/licenses/MIT MIT
13
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
14
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
15
 * @link      http://github.com/nfephp-org/sped-efdreinf for the canonical source repository
16
 */
17
18
use NFePHP\EFDReinf\Common\Factory;
19
use NFePHP\EFDReinf\Common\FactoryInterface;
20
use NFePHP\EFDReinf\Common\FactoryId;
21
use NFePHP\Common\Certificate;
22
use stdClass;
23
24
class EvtFechaEvPer extends Factory implements FactoryInterface
25
{
26
    /**
27
     * Constructor
28
     * @param string $config
29
     * @param stdClass $std
30
     * @param Certificate $certificate
31
     * @param string $data
32
     */
33
    public function __construct(
34
        $config,
35
        stdClass $std,
36
        Certificate $certificate = null,
37
        $data = ''
38
    ) {
39
        $params = new \stdClass();
40
        $params->evtName = 'evtFechamento';
41
        $params->evtTag = 'evtFechaEvPer';
42
        $params->evtAlias = 'R-2099';
43
        parent::__construct($config, $std, $params, $certificate, $data);
44
    }
45
    
46
    /**
47
     * Node constructor
48
     */
49
    protected function toNode()
50
    {
51
        $ideContri = $this->node->getElementsByTagName('ideContri')->item(0);
52
        //o idEvento pode variar de evento para evento
53
        //então cada factory individualmente terá de construir o seu
54
        $ideEvento = $this->dom->createElement("ideEvento");
55
        $this->dom->addChild(
56
            $ideEvento,
57
            "perApur",
58
            $this->std->perapur,
59
            true
60
        );
61
        $this->dom->addChild(
62
            $ideEvento,
63
            "tpAmb",
64
            $this->tpAmb,
65
            true
66
        );
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "procEmi",
70
            $this->procEmi,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "verProc",
76
            $this->verProc,
77
            true
78
        );
79
        $this->node->insertBefore($ideEvento, $ideContri);
80
        
81
        if (!empty($this->std->iderespinf)) {
82
            $ide = $this->std->iderespinf;
83
            $ideRespInf = $this->dom->createElement("ideRespInf");
84
            $this->dom->addChild(
85
                $ideRespInf,
86
                "nmResp",
87
                $ide->nmresp,
88
                true
89
            );
90
            $this->dom->addChild(
91
                $ideRespInf,
92
                "cpfResp",
93
                $ide->cpfresp,
94
                true
95
            );
96
            $this->dom->addChild(
97
                $ideRespInf,
98
                "telefone",
99
                !empty($ide->telefone) ? $ide->telefone : null,
100
                false
101
            );
102
            $this->dom->addChild(
103
                $ideRespInf,
104
                "email",
105
                !empty($ide->email) ? $ide->email : null,
106
                false
107
            );
108
            $this->node->appendChild($ideRespInf);
109
        }
110
        
111
        
112
        $infoFech = $this->dom->createElement("infoFech");
113
        $this->dom->addChild(
114
            $infoFech,
115
            "evtServTm",
116
            $this->std->evtservtm,
117
            true
118
        );
119
        $this->dom->addChild(
120
            $infoFech,
121
            "evtServPr",
122
            $this->std->evtservpr,
123
            true
124
        );
125
        $this->dom->addChild(
126
            $infoFech,
127
            "evtAssDespRec",
128
            $this->std->evtassdesprec,
129
            true
130
        );
131
        $this->dom->addChild(
132
            $infoFech,
133
            "evtAssDespRep",
134
            $this->std->evtassdesprep,
135
            true
136
        );
137
        $this->dom->addChild(
138
            $infoFech,
139
            "evtComProd",
140
            $this->std->evtcomprod,
141
            true
142
        );
143
        $this->dom->addChild(
144
            $infoFech,
145
            "evtCPRB",
146
            $this->std->evtcprb,
147
            true
148
        );
149
        $this->dom->addChild(
150
            $infoFech,
151
            "evtPgtos",
152
            $this->std->evtpgtos,
153
            true
154
        );
155
        $this->dom->addChild(
156
            $infoFech,
157
            "compSemMovto",
158
            !empty($this->std->compsemmovto) ? $this->std->compsemmovto : null,
159
            false
160
        );
161
        $this->node->appendChild($infoFech);
162
        $this->reinf->appendChild($this->node);
163
        //$this->xml = $this->dom->saveXML($this->reinf);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
164
        $this->sign($this->evtTag);
165
    }
166
}
167