Passed
Push — master ( f30f26...aba7a3 )
by Roberto
13:07
created

EvtTSVTermino::toNode()   D

Complexity

Conditions 23
Paths 10

Size

Total Lines 306
Code Lines 247

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 552

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 306
ccs 0
cts 303
cp 0
rs 4.6303
c 1
b 0
f 0
cc 23
eloc 247
nc 10
nop 0
crap 552

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\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtTSVTermino Event S-2399 constructor
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHPSocial
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-esocial for the canonical source repository
16
 */
17
18
use NFePHP\Common\Certificate;
19
use NFePHP\eSocial\Common\Factory;
20
use NFePHP\eSocial\Common\FactoryId;
21
use NFePHP\eSocial\Common\FactoryInterface;
22
use stdClass;
23
24
class EvtTSVTermino extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
    /**
31
     * @var string
32
     */
33
    protected $evtName = 'evtTSVTermino';
34
    /**
35
     * @var string
36
     */
37
    protected $evtAlias = 'S-2399';
38
    /**
39
     * Parameters patterns
40
     *
41
     * @var array
42
     */
43
    protected $parameters = [];
44
45
    /**
46
     * Constructor
47
     *
48
     * @param string $config
49
     * @param stdClass $std
50
     * @param Certificate $certificate
51
     */
52
    public function __construct(
53
        $config,
54
        stdClass $std,
55
        Certificate $certificate
56
    ) {
57
        parent::__construct($config, $std, $certificate);
58
    }
59
60
    /**
61
     * Node constructor
62
     */
63
    protected function toNode()
64
    {
65
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
66
        $ideEvento = $this->dom->createElement("ideEvento");
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "indRetif",
70
            $this->std->indretif,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "nrRecibo",
76
            ! empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
77
            false
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "tpAmb",
82
            $this->tpAmb,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "procEmi",
88
            $this->procEmi,
89
            true
90
        );
91
        $this->dom->addChild(
92
            $ideEvento,
93
            "verProc",
94
            $this->verProc,
95
            true
96
        );
97
        $this->node->insertBefore($ideEvento, $ideEmpregador);
98
        
99
        $ideTrabSemVinculo = $this->dom->createElement("ideTrabSemVinculo");
100
        $this->dom->addChild(
101
            $ideTrabSemVinculo,
102
            "cpfTrab",
103
            $this->std->cpftrab,
104
            true
105
        );
106
        $this->dom->addChild(
107
            $ideTrabSemVinculo,
108
            "nisTrab",
109
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
110
            false
111
        );
112
        $this->dom->addChild(
113
            $ideTrabSemVinculo,
114
            "codCateg",
115
            $this->std->codcateg,
116
            true
117
        );
118
        $this->node->appendChild($ideTrabSemVinculo);
119
        $infoTSVTermino = $this->dom->createElement("infoTSVTermino");
120
        $this->dom->addChild(
121
            $infoTSVTermino,
122
            "dtTerm",
123
            $this->std->dtterm,
124
            true
125
        );
126
        $this->dom->addChild(
127
            $infoTSVTermino,
128
            "mtvDesligTSV",
129
            !empty($this->std->mtvdesligtsv) ? $this->std->mtvdesligtsv : null,
130
            false
131
        );
132
        if (!empty($this->std->verbasresc)) {
133
            $vr = $this->std->verbasresc;
134
            $verbasResc = $this->dom->createElement("verbasResc");
135
            foreach ($vr->dmdev as $dv) {
136
                $dmDev = $this->dom->createElement("dmDev");
137
                $this->dom->addChild(
138
                    $dmDev,
139
                    "ideDmDev",
140
                    $dv->idedmdev,
141
                    true
142
                );
143
                foreach ($dv->ideestablot as $el) {
144
                    $ideEstabLot = $this->dom->createElement("ideEstabLot");
145
                    $this->dom->addChild(
146
                        $ideEstabLot,
147
                        "tpInsc",
148
                        $el->tpinsc,
149
                        true
150
                    );
151
                    $this->dom->addChild(
152
                        $ideEstabLot,
153
                        "nrInsc",
154
                        $el->nrinsc,
155
                        true
156
                    );
157
                    $this->dom->addChild(
158
                        $ideEstabLot,
159
                        "codLotacao",
160
                        $el->codlotacao,
161
                        true
162
                    );
163
                    foreach ($el->detverbas as $dever) {
164
                        $detVerbas = $this->dom->createElement("detVerbas");
165
                        $this->dom->addChild(
166
                            $detVerbas,
167
                            "codRubr",
168
                            $dever->codrubr,
169
                            true
170
                        );
171
                        $this->dom->addChild(
172
                            $detVerbas,
173
                            "ideTabRubr",
174
                            $dever->idetabrubr,
175
                            true
176
                        );
177
                        $this->dom->addChild(
178
                            $detVerbas,
179
                            "qtdRubr",
180
                            !empty($dever->qtdrubr) ? $dever->qtdrubr : null,
181
                            false
182
                        );
183
                        $this->dom->addChild(
184
                            $detVerbas,
185
                            "fatorRubr",
186
                            !empty($dever->fatorrubr) ? $dever->fatorrubr : null,
187
                            false
188
                        );
189
                        $this->dom->addChild(
190
                            $detVerbas,
191
                            "vrUnit",
192
                            !empty($dever->vrunit) ? $dever->vrunit : null,
193
                            false
194
                        );
195
                        $this->dom->addChild(
196
                            $detVerbas,
197
                            "vrRubr",
198
                            $dever->vrrubr,
199
                            true
200
                        );
201
                        $ideEstabLot->appendChild($detVerbas);
202
                    }
203
                    if (!empty($el->infosaudecolet)) {
204
                        $infoSaudeColet = $this->dom->createElement("infoSaudeColet");
205
                        foreach ($el->infosaudecolet->detoper as $dop) {
206
                            $detOper = $this->dom->createElement("detOper");
207
                            $this->dom->addChild(
208
                                $detOper,
209
                                "cnpjOper",
210
                                $dop->cnpjoper,
211
                                true
212
                            );
213
                            $this->dom->addChild(
214
                                $detOper,
215
                                "regANS",
216
                                $dop->regans,
217
                                true
218
                            );
219
                            $this->dom->addChild(
220
                                $detOper,
221
                                "vrPgTit",
222
                                $dop->vrpgtit,
223
                                true
224
                            );
225
                            if (!empty($dop->detplano)) {
226
                                foreach ($dop->detplano as $dpl) {
227
                                    $detPlano = $this->dom->createElement("detPlano");
228
                                    $this->dom->addChild(
229
                                        $detPlano,
230
                                        "tpDep",
231
                                        $dpl->tpdep,
232
                                        true
233
                                    );
234
                                    $this->dom->addChild(
235
                                        $detPlano,
236
                                        "cpfDep",
237
                                        !empty($dpl->cpfdep) ? $dpl->cpfdep : null,
238
                                        false
239
                                    );
240
                                    $this->dom->addChild(
241
                                        $detPlano,
242
                                        "nmDep",
243
                                        $dpl->nmdep,
244
                                        true
245
                                    );
246
                                    $this->dom->addChild(
247
                                        $detPlano,
248
                                        "dtNascto",
249
                                        $dpl->dtnascto,
250
                                        true
251
                                    );
252
                                    $this->dom->addChild(
253
                                        $detPlano,
254
                                        "vlrPgDep",
255
                                        $dpl->vlrpgdep,
256
                                        true
257
                                    );
258
                                    $detOper->appendChild($detPlano);
259
                                }
260
                            }
261
                            $infoSaudeColet->appendChild($detOper);
262
                        }
263
                        $ideEstabLot->appendChild($infoSaudeColet);
264
                    }
265
                    if (!empty($el->infoagnocivo)) {
266
                        $infoAgNocivo = $this->dom->createElement("infoAgNocivo");
267
                        $this->dom->addChild(
268
                            $infoAgNocivo,
269
                            "grauExp",
270
                            $el->infoagnocivo->grauexp,
271
                            true
272
                        );
273
                        $ideEstabLot->appendChild($infoAgNocivo);
274
                    }
275
                    if (!empty($el->infosimples)) {
276
                        $infoSimples = $this->dom->createElement("infoSimples");
277
                        $this->dom->addChild(
278
                            $infoSimples,
279
                            "indSimples",
280
                            $el->infosimples->indsimples,
281
                            true
282
                        );
283
                        $ideEstabLot->appendChild($infoSimples);
284
                    }
285
                    $dmDev->appendChild($ideEstabLot);
286
                }
287
                $verbasResc->appendChild($dmDev);
288
            }
289
            
290
            if (!empty($this->std->verbasresc->procjudtrab)) {
291
                foreach ($this->std->verbasresc->procjudtrab as $pj) {
292
                    $procJudTrab = $this->dom->createElement("procJudTrab");
293
                    $this->dom->addChild(
294
                        $procJudTrab,
295
                        "tpTrib",
296
                        $pj->tptrib,
297
                        true
298
                    );
299
                    $this->dom->addChild(
300
                        $procJudTrab,
301
                        "nrProcJud",
302
                        $pj->nrprocjud,
303
                        true
304
                    );
305
                    $this->dom->addChild(
306
                        $procJudTrab,
307
                        "codSusp",
308
                        $pj->codsusp,
309
                        true
310
                    );
311
                    $verbasResc->appendChild($procJudTrab);
312
                }
313
            }
314
            if (!empty($this->std->verbasresc->infomv)) {
315
                $infoMV = $this->dom->createElement("infoMV");
316
                $this->dom->addChild(
317
                    $infoMV,
318
                    "indMV",
319
                    $this->std->verbasresc->infomv->indmv,
320
                    true
321
                );
322
                foreach ($this->std->verbasresc->infomv->remunoutrempr as $rm) {
323
                    $remunOutrEmpr = $this->dom->createElement("remunOutrEmpr");
324
                    $this->dom->addChild(
325
                        $remunOutrEmpr,
326
                        "tpInsc",
327
                        $rm->tpinsc,
328
                        true
329
                    );
330
                    $this->dom->addChild(
331
                        $remunOutrEmpr,
332
                        "nrInsc",
333
                        $rm->nrinsc,
334
                        true
335
                    );
336
                    $this->dom->addChild(
337
                        $remunOutrEmpr,
338
                        "codCateg",
339
                        $rm->codcateg,
340
                        true
341
                    );
342
                    $this->dom->addChild(
343
                        $remunOutrEmpr,
344
                        "vlrRemunOE",
345
                        $rm->vlrremunoe,
346
                        true
347
                    );
348
                    $infoMV->appendChild($remunOutrEmpr);
349
                }
350
                $verbasResc->appendChild($infoMV);
351
            }
352
            $infoTSVTermino->appendChild($verbasResc);
353
        }
354
        if (!empty($this->std->quarentena)) {
355
            $quarentena = $this->dom->createElement("quarentena");
356
            $this->dom->addChild(
357
                $quarentena,
358
                "dtFimQuar",
359
                $this->std->quarentena->dtfimquar,
360
                true
361
            );
362
            $infoTSVTermino->appendChild($quarentena);
363
        }
364
        $this->node->appendChild($infoTSVTermino);
365
        $this->eSocial->appendChild($this->node);
366
        //$this->xml = $this->dom->saveXML($this->eSocial);
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...
367
        $this->sign();
368
    }
369
}
370