Passed
Push — master ( b85394...28dc46 )
by Roberto
02:23
created

EvtTabProcesso::toNode()   D

Complexity

Conditions 17
Paths 54

Size

Total Lines 183
Code Lines 140

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 306

Importance

Changes 0
Metric Value
dl 0
loc 183
ccs 0
cts 170
cp 0
rs 4.8361
c 0
b 0
f 0
cc 17
eloc 140
nc 54
nop 0
crap 306

How to fix   Long Method    Complexity   

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 EvtTabProcesso Event R-1070 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 EvtTabProcesso extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $evtName = 'evtTabProcesso';
30
    /**
31
     * @var string
32
     */
33
    protected $evtTag = 'evtTabProcesso';
34
    /**
35
     * @var string
36
     */
37
    protected $evtAlias = 'R-1070';
38
39
    /**
40
     * Constructor
41
     * @param string $config
42
     * @param stdClass $std
43
     * @param Certificate $certificate
44
     * @param string date
45
     */
46
    public function __construct(
47
        $config,
48
        stdClass $std,
49
        Certificate $certificate = null,
50
        $date = ''
51
    ) {
52
        parent::__construct($config, $std, $certificate, $date);
53
    }
54
    
55
    /**
56
     * Node constructor
57
     */
58
    protected function toNode()
59
    {
60
        $ideContri = $this->node->getElementsByTagName('ideContri')->item(0);
61
        //o idEvento pode variar de evento para evento
62
        //então cada factory individualmente terá de construir o seu
63
        $ideEvento = $this->dom->createElement("ideEvento");
64
        $this->dom->addChild(
65
            $ideEvento,
66
            "tpAmb",
67
            $this->tpAmb,
68
            true
69
        );
70
        $this->dom->addChild(
71
            $ideEvento,
72
            "procEmi",
73
            $this->procEmi,
74
            true
75
        );
76
        $this->dom->addChild(
77
            $ideEvento,
78
            "verProc",
79
            $this->verProc,
80
            true
81
        );
82
        $this->node->insertBefore($ideEvento, $ideContri);
83
        //tag deste evento em particular
84
        $info = $this->dom->createElement("infoProcesso");
85
        
86
        $ideProcesso  = $this->dom->createElement("ideProcesso");
87
        $this->dom->addChild(
88
            $ideProcesso,
89
            "tpProc",
90
            $this->std->tpproc,
91
            true
92
        );
93
        $this->dom->addChild(
94
            $ideProcesso,
95
            "nrProc",
96
            $this->std->nrproc,
97
            true
98
        );
99
        
100
        if ($this->std->modo == 'INC') {
101
            //inclusao
102
            $node = $this->dom->createElement("inclusao");
103
            $this->dom->addChild(
104
                $ideProcesso,
105
                "iniValid",
106
                $this->std->inivalid,
107
                true
108
            );
109
            $this->dom->addChild(
110
                $ideProcesso,
111
                "fimValid",
112
                !empty($this->std->fimvalid) ? $this->std->fimvalid : null,
113
                false
114
            );
115
            $this->dom->addChild(
116
                $ideProcesso,
117
                "indAutoria",
118
                !empty($this->std->indautoria) ? $this->std->indautoria : null,
119
                false
120
            );
121
        } elseif ($this->std->modo == 'ALT') {
122
            //alteracao
123
            $node = $this->dom->createElement("alteracao");
124
            $this->dom->addChild(
125
                $ideProcesso,
126
                "indAutoria",
127
                !empty($this->std->indautoria) ? $this->std->indautoria : null,
128
                false
129
            );
130
            $this->dom->addChild(
131
                $ideProcesso,
132
                "iniValid",
133
                $this->std->inivalid,
134
                true
135
            );
136
            $this->dom->addChild(
137
                $ideProcesso,
138
                "fimValid",
139
                !empty($this->std->fimvalid) ? $this->std->fimvalid : null,
140
                false
141
            );
142
        } else {
143
            //exclusao
144
            $node = $this->dom->createElement("exclusao");
145
            $this->dom->addChild(
146
                $ideProcesso,
147
                "iniValid",
148
                $this->std->inivalid,
149
                true
150
            );
151
            $this->dom->addChild(
152
                $ideProcesso,
153
                "fimValid",
154
                !empty($this->std->fimvalid) ? $this->std->fimvalid : null,
155
                false
156
            );
157
        }
158
        foreach ($this->std->infosusp as $i) {
159
            $infosusp = $this->dom->createElement("infoSusp");
160
            $this->dom->addChild(
161
                $infosusp,
162
                "codSusp",
163
                !empty($i->codsusp) ? $i->codsusp : null,
164
                false
165
            );
166
            $this->dom->addChild(
167
                $infosusp,
168
                "indSusp",
169
                $i->indsusp,
170
                true
171
            );
172
            $this->dom->addChild(
173
                $infosusp,
174
                "dtDecisao",
175
                $i->dtdecisao,
176
                true
177
            );
178
            $this->dom->addChild(
179
                $infosusp,
180
                "indDeposito",
181
                $i->inddeposito,
182
                true
183
            );
184
            if ($this->std->modo !== 'EXC') {
185
                $ideProcesso->appendChild($infosusp);
186
            }
187
        }
188
        if (!empty($this->std->dadosprocjud)) {
189
            $dadosProcJud = $this->dom->createElement("dadosProcJud");
190
            $d = $this->std->dadosprocjud;
191
            $this->dom->addChild(
192
                $dadosProcJud,
193
                "ufVara",
194
                $d->ufvara,
195
                true
196
            );
197
            $this->dom->addChild(
198
                $dadosProcJud,
199
                "codMunic",
200
                !empty($d->codmunic) ? $d->codmunic : null,
201
                false
202
            );
203
            $this->dom->addChild(
204
                $dadosProcJud,
205
                "idVara",
206
                $d->idvara,
207
                true
208
            );
209
            if ($this->std->modo !== 'EXC') {
210
                $ideProcesso->appendChild($dadosProcJud);
211
            }
212
        }
213
        $node->appendChild($ideProcesso);
214
        
215
        if (!empty($this->std->novavalidade) && $this->std->modo == 'ALT') {
216
            $novaValidade = $this->dom->createElement("novaValidade");
217
            $n = $this->std->novavalidade;
218
            $this->dom->addChild(
219
                $novaValidade,
220
                "iniValid",
221
                $n->inivalid,
222
                true
223
            );
224
            $this->dom->addChild(
225
                $novaValidade,
226
                "fimValid",
227
                !empty($n->fimvalid) ? $n->fimvalid : null,
228
                false
229
            );
230
            $node->appendChild($novaValidade);
231
        }
232
        
233
        $info->appendChild($node);
234
        
235
        $this->node->appendChild($info);
236
        
237
        $this->reinf->appendChild($this->node);
238
        //$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...
239
        $this->sign();
240
    }
241
}
242