Passed
Push — master ( 82987a...8bd657 )
by Roberto
02:36
created

EvtRemun::toNode()   D

Complexity

Conditions 45
Paths 48

Size

Total Lines 518
Code Lines 414

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2070

Importance

Changes 0
Metric Value
dl 0
loc 518
ccs 0
cts 507
cp 0
rs 4.1818
c 0
b 0
f 0
cc 45
eloc 414
nc 48
nop 0
crap 2070

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 EvtRemun Event S-1200 constructor
7
 *
8
 * @category  API
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 EvtRemun extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtRemun';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1200';
40
41
    /**
42
     * Parameters patterns
43
     *
44
     * @var array
45
     */
46
    protected $parameters = [];
47
48
    /**
49
     * Constructor
50
     *
51
     * @param string $config
52
     * @param stdClass $std
53
     * @param Certificate $certificate
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate
59
    ) {
60
        parent::__construct($config, $std, $certificate);
61
    }
62
63
    /**
64
     * Node constructor
65
     */
66
    protected function toNode()
67
    {
68
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
69
        //o idEvento pode variar de evento para evento
70
        //então cada factory individualmente terá de construir o seu
71
        $ideEvento = $this->dom->createElement("ideEvento");
72
        $this->dom->addChild(
73
            $ideEvento,
74
            "indRetif",
75
            $this->std->indretif,
76
            true
77
        );
78
        $this->dom->addChild(
79
            $ideEvento,
80
            "nrRecibo",
81
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
82
            false
83
        );
84
        $this->dom->addChild(
85
            $ideEvento,
86
            "indApuracao",
87
            $this->std->indapuracao,
88
            true
89
        );
90
        $this->dom->addChild(
91
            $ideEvento,
92
            "perApur",
93
            $this->std->perapur,
94
            true
95
        );
96
        $this->dom->addChild(
97
            $ideEvento,
98
            "tpAmb",
99
            $this->tpAmb,
100
            true
101
        );
102
        $this->dom->addChild(
103
            $ideEvento,
104
            "procEmi",
105
            $this->procEmi,
106
            true
107
        );
108
        $this->dom->addChild(
109
            $ideEvento,
110
            "verProc",
111
            $this->verProc,
112
            true
113
        );
114
        $this->node->insertBefore($ideEvento, $ideEmpregador);
115
        
116
        $ide = $this->dom->createElement("ideTrabalhador");
117
        $this->dom->addChild(
118
            $ide,
119
            "cpfTrab",
120
            $this->std->cpftrab,
121
            true
122
        );
123
        $this->dom->addChild(
124
            $ide,
125
            "nisTrab",
126
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
127
            false
128
        );
129
        
130
        if (!empty($this->std->infomv)) {
131
            $info = $this->dom->createElement("infoMV");
132
            $this->dom->addChild(
133
                $info,
134
                "indMV",
135
                $this->std->infomv->indmv,
136
                true
137
            );
138
            foreach ($this->std->infomv->remunoutrempr as $remo) {
139
                $remunOutrEmpr = $this->dom->createElement("remunOutrEmpr");
140
                $this->dom->addChild(
141
                    $remunOutrEmpr,
142
                    "tpInsc",
143
                    $remo->tpinsc,
144
                    true
145
                );
146
                $this->dom->addChild(
147
                    $remunOutrEmpr,
148
                    "nrInsc",
149
                    $remo->nrinsc,
150
                    true
151
                );
152
                $this->dom->addChild(
153
                    $remunOutrEmpr,
154
                    "codCateg",
155
                    $remo->codcateg,
156
                    true
157
                );
158
                $this->dom->addChild(
159
                    $remunOutrEmpr,
160
                    "vlrRemunOE",
161
                    $remo->vlrremunoe,
162
                    true
163
                );
164
                $info->appendChild($remunOutrEmpr);
165
            }
166
            $ide->appendChild($info);
167
        }
168
        
169
        if (!empty($this->std->infocomplem)) {
170
            $ic = $this->std->infocomplem;
171
            $infoComplem = $this->dom->createElement("infoComplem");
172
            $this->dom->addChild(
173
                $infoComplem,
174
                "nmTrab",
175
                $ic->nmtrab,
176
                true
177
            );
178
            $this->dom->addChild(
179
                $infoComplem,
180
                "dtNascto",
181
                $ic->dtnascto,
182
                true
183
            );
184
            $this->dom->addChild(
185
                $infoComplem,
186
                "codCBO",
187
                $ic->codcbo,
188
                true
189
            );
190
            $this->dom->addChild(
191
                $infoComplem,
192
                "natAtividade",
193
                !empty($ic->natatividade) ? $ic->natatividade : null,
194
                false
195
            );
196
            $this->dom->addChild(
197
                $infoComplem,
198
                "qtdDiasTrab",
199
                !empty($ic->qtddiastrab) ? $ic->qtddiastrab : null,
200
                false
201
            );
202
            if (!empty($ic->sucessaovinc)) {
203
                $sucessaoVinc = $this->dom->createElement("sucessaoVinc");
204
                $this->dom->addChild(
205
                    $sucessaoVinc,
206
                    "cnpjEmpregAnt",
207
                    $ic->sucessaovinc->cnpjempregant,
208
                    true
209
                );
210
                $this->dom->addChild(
211
                    $sucessaoVinc,
212
                    "matricAnt",
213
                    !empty($ic->sucessaovinc->matricant) ? $ic->sucessaovinc->matricant : null,
214
                    false
215
                );
216
                $this->dom->addChild(
217
                    $sucessaoVinc,
218
                    "dtIniVinculo",
219
                    $ic->sucessaovinc->dtinivinculo,
220
                    true
221
                );
222
                $this->dom->addChild(
223
                    $sucessaoVinc,
224
                    "observacao",
225
                    !empty($ic->observacao) ? $ic->observacao : null,
226
                    false
227
                );
228
                $infoComplem->appendChild($sucessaoVinc);
229
            }
230
            $ide->appendChild($infoComplem);
231
        }
232
        
233
        if (!empty($this->std->procjudtrab)) {
234
            foreach ($this->std->procjudtrab as $proc) {
235
                $procJudTrab = $this->dom->createElement("procJudTrab");
236
                $this->dom->addChild(
237
                    $procJudTrab,
238
                    "tpTrib",
239
                    $proc->tptrib,
240
                    true
241
                );
242
                $this->dom->addChild(
243
                    $procJudTrab,
244
                    "nrProcJud",
245
                    $proc->nrprocjud,
246
                    true
247
                );
248
                $this->dom->addChild(
249
                    $procJudTrab,
250
                    "codSusp",
251
                    $proc->codsusp,
252
                    true
253
                );
254
                $ide->appendChild($procJudTrab);
255
            }
256
        }
257
        
258
        $this->node->appendChild($ide);
259
        
260
        foreach ($this->std->dmdev as $dm) {
261
            $dmDev = $this->dom->createElement("dmDev");
262
            $this->dom->addChild(
263
                $dmDev,
264
                "ideDmDev",
265
                $dm->idedmdev,
266
                true
267
            );
268
            $this->dom->addChild(
269
                $dmDev,
270
                "codCateg",
271
                $dm->codcateg,
272
                true
273
            );
274
            if (!empty($dm->ideestablot)) {
275
                $infoPerApur = $this->dom->createElement("infoPerApur");
276
                foreach ($dm->ideestablot as $idsl) {
277
                    $ideEstabLot = $this->dom->createElement("ideEstabLot");
278
                    $this->dom->addChild(
279
                        $ideEstabLot,
280
                        "tpInsc",
281
                        $idsl->tpinsc,
282
                        true
283
                    );
284
                    $this->dom->addChild(
285
                        $ideEstabLot,
286
                        "nrInsc",
287
                        $idsl->nrinsc,
288
                        true
289
                    );
290
                    $this->dom->addChild(
291
                        $ideEstabLot,
292
                        "codLotacao",
293
                        $idsl->codlotacao,
294
                        true
295
                    );
296
                    $this->dom->addChild(
297
                        $ideEstabLot,
298
                        "qtdDiasAv",
299
                        !empty($idsl->qtddiasav) ? $idsl->qtddiasav : null,
300
                        false
301
                    );
302
                    foreach ($idsl->remunperapur as $rpa) {
303
                        $remunPerApur = $this->dom->createElement("remunPerApur");
304
                        $this->dom->addChild(
305
                            $remunPerApur,
306
                            "matricula",
307
                            !empty($rpa->matricula) ? $rpa->matricula : null,
308
                            false
309
                        );
310
                        $this->dom->addChild(
311
                            $remunPerApur,
312
                            "indSimples",
313
                            !empty($rpa->indsimples) ? $rpa->indsimples : null,
314
                            false
315
                        );
316
                        foreach ($rpa->itensremun as $itemr) {
317
                            $itensRemun = $this->dom->createElement("itensRemun");
318
                            $this->dom->addChild(
319
                                $itensRemun,
320
                                "codRubr",
321
                                $itemr->codrubr,
322
                                true
323
                            );
324
                            $this->dom->addChild(
325
                                $itensRemun,
326
                                "ideTabRubr",
327
                                $itemr->idetabrubr,
328
                                true
329
                            );
330
                            $this->dom->addChild(
331
                                $itensRemun,
332
                                "qtdRubr",
333
                                !empty($itemr->qtdrubr) ? $itemr->qtdrubr : null,
334
                                false
335
                            );
336
                            $this->dom->addChild(
337
                                $itensRemun,
338
                                "fatorRubr",
339
                                !empty($itemr->fatorrubr) ? $itemr->fatorrubr : null,
340
                                false
341
                            );
342
                            $this->dom->addChild(
343
                                $itensRemun,
344
                                "vrUnit",
345
                                !empty($itemr->vrunit) ? $itemr->vrunit : null,
346
                                false
347
                            );
348
                            $this->dom->addChild(
349
                                $itensRemun,
350
                                "vrRubr",
351
                                $itemr->vrrubr,
352
                                true
353
                            );
354
                            $remunPerApur->appendChild($itensRemun);
355
                        }
356
                        
357
                        if (!empty($rpa->detoper)) {
358
                            $infoSaudeColet = $this->dom->createElement("infoSaudeColet");
359
                            foreach ($rpa->detoper as $dop) {
360
                                $detOper = $this->dom->createElement("detOper");
361
                                $this->dom->addChild(
362
                                    $detOper,
363
                                    "cnpjOper",
364
                                    $dop->cnpjoper,
365
                                    true
366
                                );
367
                                $this->dom->addChild(
368
                                    $detOper,
369
                                    "regANS",
370
                                    $dop->regans,
371
                                    true
372
                                );
373
                                $this->dom->addChild(
374
                                    $detOper,
375
                                    "vrPgTit",
376
                                    $dop->vrpgtit,
377
                                    true
378
                                );
379
                                if (!empty($dop->detplano)) {
380
                                    foreach ($dop->detplano as $pl) {
381
                                        $detPlano = $this->dom->createElement("detPlano");
382
                                        $this->dom->addChild(
383
                                            $detPlano,
384
                                            "tpDep",
385
                                            $pl->tpdep,
386
                                            true
387
                                        );
388
                                        $this->dom->addChild(
389
                                            $detPlano,
390
                                            "cpfDep",
391
                                            !empty($pl->cpfdep) ? $pl->cpfdep : null,
392
                                            false
393
                                        );
394
                                        $this->dom->addChild(
395
                                            $detPlano,
396
                                            "nmDep",
397
                                            $pl->nmdep,
398
                                            true
399
                                        );
400
                                        $this->dom->addChild(
401
                                            $detPlano,
402
                                            "dtNascto",
403
                                            $pl->dtnascto,
404
                                            true
405
                                        );
406
                                        $this->dom->addChild(
407
                                            $detPlano,
408
                                            "vlrPgDep",
409
                                            $pl->vlrpgdep,
410
                                            true
411
                                        );
412
                                        $detOper->appendChild($detPlano);
413
                                    }
414
                                }
415
                                $infoSaudeColet->appendChild($detOper);
416
                            }
417
                            $remunPerApur->appendChild($infoSaudeColet);
418
                        }
419
                        if (!empty($rpa->infoagnocivo)) {
420
                            $infoAgNocivo = $this->dom->createElement("infoAgNocivo");
421
                            $this->dom->addChild(
422
                                $infoAgNocivo,
423
                                "grauExp",
424
                                $rpa->infoagnocivo->grauexp,
425
                                true
426
                            );
427
                            $remunPerApur->appendChild($infoAgNocivo);
428
                        }
429
                        $ideEstabLot->appendChild($remunPerApur);
430
                    }
431
                    $infoPerApur->appendChild($ideEstabLot);
432
                }
433
                $dmDev->appendChild($infoPerApur);
434
                if (!empty($dm->ideadc)) {
435
                    $infoPerAnt = $this->dom->createElement("infoPerAnt");
436
                    foreach ($dm->ideadc as $adc) {
437
                        $ideADC = $this->dom->createElement("ideADC");
438
                        $this->dom->addChild(
439
                            $ideADC,
440
                            "dtAcConv",
441
                            !empty($adc->dtacconv) ? $adc->dtacconv : null,
442
                            false
443
                        );
444
                        $this->dom->addChild(
445
                            $ideADC,
446
                            "tpAcConv",
447
                            $adc->tpacconv,
448
                            true
449
                        );
450
                        $this->dom->addChild(
451
                            $ideADC,
452
                            "compAcConv",
453
                            !empty($adc->compacconv) ? $adc->compacconv : null,
454
                            false
455
                        );
456
                        $this->dom->addChild(
457
                            $ideADC,
458
                            "dtEfAcConv",
459
                            !empty($adc->dtefacconv) ? $adc->dtefacconv : null,
460
                            false
461
                        );
462
                        $this->dom->addChild(
463
                            $ideADC,
464
                            "dsc",
465
                            $adc->dsc,
466
                            true
467
                        );
468
                        $this->dom->addChild(
469
                            $ideADC,
470
                            "remunSuc",
471
                            $adc->remunsuc,
472
                            true
473
                        );
474
                        foreach ($adc->ideperiodo as $idp) {
475
                            $idePeriodo = $this->dom->createElement("idePeriodo");
476
                            $this->dom->addChild(
477
                                $idePeriodo,
478
                                "perRef",
479
                                $idp->perref,
480
                                true
481
                            );
482
                            foreach ($idp->ideestablot as $idl) {
483
                                $ideEstabLot = $this->dom->createElement("ideEstabLot");
484
                                $this->dom->addChild(
485
                                    $ideEstabLot,
486
                                    "tpInsc",
487
                                    $idl->tpinsc,
488
                                    true
489
                                );
490
                                $this->dom->addChild(
491
                                    $ideEstabLot,
492
                                    "nrInsc",
493
                                    $idl->nrinsc,
494
                                    true
495
                                );
496
                                $this->dom->addChild(
497
                                    $ideEstabLot,
498
                                    "codLotacao",
499
                                    $idl->codlotacao,
500
                                    true
501
                                );
502
                                foreach ($idl->remunperant as $rpr) {
503
                                    $remunPerAnt = $this->dom->createElement("remunPerAnt");
504
                                    $this->dom->addChild(
505
                                        $remunPerAnt,
506
                                        "matricula",
507
                                        !empty($rpr->matricula) ? $rpr->matricula : null,
508
                                        false
509
                                    );
510
                                    $this->dom->addChild(
511
                                        $remunPerAnt,
512
                                        "indSimples",
513
                                        !empty($rpr->indsimples) ? $rpr->indsimples : null,
514
                                        false
515
                                    );
516
                                    foreach ($rpr->itensremun as $irem) {
517
                                        $itensRemun = $this->dom->createElement("itensRemun");
518
                                        $this->dom->addChild(
519
                                            $itensRemun,
520
                                            "codRubr",
521
                                            $irem->codrubr,
522
                                            true
523
                                        );
524
                                        $this->dom->addChild(
525
                                            $itensRemun,
526
                                            "ideTabRubr",
527
                                            $irem->idetabrubr,
528
                                            true
529
                                        );
530
                                        $this->dom->addChild(
531
                                            $itensRemun,
532
                                            "qtdRubr",
533
                                            !empty($irem->qtdrubr) ? $irem->qtdrubr : null,
534
                                            false
535
                                        );
536
                                        $this->dom->addChild(
537
                                            $itensRemun,
538
                                            "fatorRubr",
539
                                            !empty($irem->fatorrubr) ? $irem->fatorrubr : null,
540
                                            false
541
                                        );
542
                                        $this->dom->addChild(
543
                                            $itensRemun,
544
                                            "vrUnit",
545
                                            !empty($irem->vrunit) ? $irem->vrunit : null,
546
                                            false
547
                                        );
548
                                        $this->dom->addChild(
549
                                            $itensRemun,
550
                                            "vrRubr",
551
                                            $irem->vrrubr,
552
                                            true
553
                                        );
554
                                        $remunPerAnt->appendChild($itensRemun);
555
                                    }
556
                                    if (!empty($rpr->infoagnocivo)) {
557
                                        $infoAgNocivo = $this->dom->createElement("infoAgNocivo");
558
                                        $this->dom->addChild(
559
                                            $infoAgNocivo,
560
                                            "grauExp",
561
                                            $rpr->infoagnocivo->grauexp,
562
                                            true
563
                                        );
564
                                        $remunPerAnt->appendChild($infoAgNocivo);
565
                                    }
566
                                    $ideEstabLot->appendChild($remunPerAnt);
567
                                }
568
                                $idePeriodo->appendChild($ideEstabLot);
569
                            }
570
                            $ideADC->appendChild($idePeriodo);
571
                        }
572
                        
573
                        $infoPerAnt->appendChild($ideADC);
574
                    }
575
                    $dmDev->appendChild($infoPerAnt);
576
                }
577
            }
578
            $this->node->appendChild($dmDev);
579
        }
580
        $this->eSocial->appendChild($this->node);
581
        //$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...
582
        $this->sign();
583
    }
584
}
585