Passed
Push — master ( 96841a...1f231a )
by Roberto
02:57
created

EvtRemun   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 616
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 53
lcom 1
cbo 1
dl 0
loc 616
ccs 0
cts 561
cp 0
rs 6.944
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
F toNode() 0 575 52

How to fix   Complexity   

Complex Class

Complex classes like EvtRemun often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EvtRemun, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtRemun Event S-1200 constructor
7
 * READ for 2.4.2 layout
8
 * Read for 2.5.0 layout
9
 *
10
 * @category  library
11
 * @package   NFePHP\eSocial
12
 * @copyright NFePHP Copyright (c) 2017
13
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
14
 * @license   https://opensource.org/licenses/MIT MIT
15
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
16
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
17
 * @link      http://github.com/nfephp-org/sped-esocial for the canonical source repository
18
 */
19
20
use NFePHP\Common\Certificate;
21
use NFePHP\eSocial\Common\Factory;
22
use NFePHP\eSocial\Common\FactoryId;
23
use NFePHP\eSocial\Common\FactoryInterface;
24
use stdClass;
25
26
class EvtRemun extends Factory implements FactoryInterface
27
{
28
    /**
29
     * @var int
30
     */
31
    public $sequencial;
32
    /**
33
     * @var string
34
     */
35
    protected $evtName = 'evtRemun';
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1200';
40
    /**
41
     * Parameters patterns
42
     *
43
     * @var array
44
     */
45
    protected $parameters = [];
46
47
    /**
48
     * Constructor
49
     *
50
     * @param string $config
51
     * @param stdClass $std
52
     * @param Certificate $certificate
53
     */
54
    public function __construct(
55
        $config,
56
        stdClass $std,
57
        Certificate $certificate = null,
58
        $date = ''
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
            
139
            if (!empty($this->std->infomv->remunoutrempr)) {
140
                foreach ($this->std->infomv->remunoutrempr as $remo) {
141
                    $remunOutrEmpr = $this->dom->createElement("remunOutrEmpr");
142
                    $this->dom->addChild(
143
                        $remunOutrEmpr,
144
                        "tpInsc",
145
                        $remo->tpinsc,
146
                        true
147
                    );
148
                    $this->dom->addChild(
149
                        $remunOutrEmpr,
150
                        "nrInsc",
151
                        $remo->nrinsc,
152
                        true
153
                    );
154
                    $this->dom->addChild(
155
                        $remunOutrEmpr,
156
                        "codCateg",
157
                        $remo->codcateg,
158
                        true
159
                    );
160
                    $this->dom->addChild(
161
                        $remunOutrEmpr,
162
                        "vlrRemunOE",
163
                        $remo->vlrremunoe,
164
                        true
165
                    );
166
                    $info->appendChild($remunOutrEmpr);
167
                }
168
                $ide->appendChild($info);
169
            }
170
        }
171
        
172
        
173
        if (!empty($this->std->infocomplem)) {
174
            $ic = $this->std->infocomplem;
175
            $infoComplem = $this->dom->createElement("infoComplem");
176
            $this->dom->addChild(
177
                $infoComplem,
178
                "nmTrab",
179
                $ic->nmtrab,
180
                true
181
            );
182
            $this->dom->addChild(
183
                $infoComplem,
184
                "dtNascto",
185
                $ic->dtnascto,
186
                true
187
            );
188
            if (!empty($ic->sucessaovinc)) {
189
                $sucessaoVinc = $this->dom->createElement("sucessaoVinc");
190
                $this->dom->addChild(
191
                    $sucessaoVinc,
192
                    "tpInscAnt",
193
                    $ic->sucessaovinc->tpinscant,
194
                    true
195
                );
196
                $this->dom->addChild(
197
                    $sucessaoVinc,
198
                    "cnpjEmpregAnt",
199
                    $ic->sucessaovinc->cnpjempregant,
200
                    true
201
                );
202
                $this->dom->addChild(
203
                    $sucessaoVinc,
204
                    "matricAnt",
205
                    !empty($ic->sucessaovinc->matricant) ? $ic->sucessaovinc->matricant : null,
206
                    false
207
                );
208
                $this->dom->addChild(
209
                    $sucessaoVinc,
210
                    "dtAdm",
211
                    $ic->sucessaovinc->dtadm,
212
                    true
213
                );
214
                $this->dom->addChild(
215
                    $sucessaoVinc,
216
                    "observacao",
217
                    !empty($ic->observacao) ? $ic->observacao : null,
218
                    false
219
                );
220
                $infoComplem->appendChild($sucessaoVinc);
221
            }
222
            $ide->appendChild($infoComplem);
223
        }
224
        
225
        if (!empty($this->std->procjudtrab)) {
226
            foreach ($this->std->procjudtrab as $proc) {
227
                $procJudTrab = $this->dom->createElement("procJudTrab");
228
                $this->dom->addChild(
229
                    $procJudTrab,
230
                    "tpTrib",
231
                    $proc->tptrib,
232
                    true
233
                );
234
                $this->dom->addChild(
235
                    $procJudTrab,
236
                    "nrProcJud",
237
                    $proc->nrprocjud,
238
                    true
239
                );
240
                $this->dom->addChild(
241
                    $procJudTrab,
242
                    "codSusp",
243
                    $proc->codsusp,
244
                    true
245
                );
246
                $ide->appendChild($procJudTrab);
247
            }
248
        }
249
        
250
        if (!empty($this->std->infointerm)) {
251
            $infoInterm = $this->dom->createElement("infoInterm");
252
            $this->dom->addChild(
253
                $infoInterm,
254
                "qtdDiasInterm",
255
                $this->std->infointerm->qtddiasinterm,
256
                true
257
            );
258
            $ide->appendChild($infoInterm);
259
        }
260
        
261
        $this->node->appendChild($ide);
262
        
263
        foreach ($this->std->dmdev as $dm) {
264
            $dmDev = $this->dom->createElement("dmDev");
265
            $this->dom->addChild(
266
                $dmDev,
267
                "ideDmDev",
268
                $dm->idedmdev,
269
                true
270
            );
271
            $this->dom->addChild(
272
                $dmDev,
273
                "codCateg",
274
                $dm->codcateg,
275
                true
276
            );
277
            if (!empty($dm->ideestablot)) {
278
                $infoPerApur = $this->dom->createElement("infoPerApur");
279
                foreach ($dm->ideestablot as $idsl) {
280
                    $ideEstabLot = $this->dom->createElement("ideEstabLot");
281
                    $this->dom->addChild(
282
                        $ideEstabLot,
283
                        "tpInsc",
284
                        $idsl->tpinsc,
285
                        true
286
                    );
287
                    $this->dom->addChild(
288
                        $ideEstabLot,
289
                        "nrInsc",
290
                        $idsl->nrinsc,
291
                        true
292
                    );
293
                    $this->dom->addChild(
294
                        $ideEstabLot,
295
                        "codLotacao",
296
                        $idsl->codlotacao,
297
                        true
298
                    );
299
                    $this->dom->addChild(
300
                        $ideEstabLot,
301
                        "qtdDiasAv",
302
                        !empty($idsl->qtddiasav) ? $idsl->qtddiasav : null,
303
                        false
304
                    );
305
                    foreach ($idsl->remunperapur as $rpa) {
306
                        $remunPerApur = $this->dom->createElement("remunPerApur");
307
                        $this->dom->addChild(
308
                            $remunPerApur,
309
                            "matricula",
310
                            !empty($rpa->matricula) ? $rpa->matricula : null,
311
                            false
312
                        );
313
                        $this->dom->addChild(
314
                            $remunPerApur,
315
                            "indSimples",
316
                            !empty($rpa->indsimples) ? $rpa->indsimples : null,
317
                            false
318
                        );
319
                        foreach ($rpa->itensremun as $itemr) {
320
                            $itensRemun = $this->dom->createElement("itensRemun");
321
                            $this->dom->addChild(
322
                                $itensRemun,
323
                                "codRubr",
324
                                $itemr->codrubr,
325
                                true
326
                            );
327
                            $this->dom->addChild(
328
                                $itensRemun,
329
                                "ideTabRubr",
330
                                $itemr->idetabrubr,
331
                                true
332
                            );
333
                            $this->dom->addChild(
334
                                $itensRemun,
335
                                "qtdRubr",
336
                                !empty($itemr->qtdrubr) ? $itemr->qtdrubr : null,
337
                                false
338
                            );
339
                            $this->dom->addChild(
340
                                $itensRemun,
341
                                "fatorRubr",
342
                                !empty($itemr->fatorrubr) ? $itemr->fatorrubr : null,
343
                                false
344
                            );
345
                            $this->dom->addChild(
346
                                $itensRemun,
347
                                "vrUnit",
348
                                !empty($itemr->vrunit) ? $itemr->vrunit : null,
349
                                false
350
                            );
351
                            $this->dom->addChild(
352
                                $itensRemun,
353
                                "vrRubr",
354
                                $itemr->vrrubr,
355
                                true
356
                            );
357
                            $remunPerApur->appendChild($itensRemun);
358
                        }
359
                        
360
                        if (!empty($rpa->detoper)) {
361
                            $infoSaudeColet = $this->dom->createElement("infoSaudeColet");
362
                            foreach ($rpa->detoper as $dop) {
363
                                $detOper = $this->dom->createElement("detOper");
364
                                $this->dom->addChild(
365
                                    $detOper,
366
                                    "cnpjOper",
367
                                    $dop->cnpjoper,
368
                                    true
369
                                );
370
                                $this->dom->addChild(
371
                                    $detOper,
372
                                    "regANS",
373
                                    $dop->regans,
374
                                    true
375
                                );
376
                                $this->dom->addChild(
377
                                    $detOper,
378
                                    "vrPgTit",
379
                                    $dop->vrpgtit,
380
                                    true
381
                                );
382
                                if (!empty($dop->detplano)) {
383
                                    foreach ($dop->detplano as $pl) {
384
                                        $detPlano = $this->dom->createElement("detPlano");
385
                                        $this->dom->addChild(
386
                                            $detPlano,
387
                                            "tpDep",
388
                                            $pl->tpdep,
389
                                            true
390
                                        );
391
                                        $this->dom->addChild(
392
                                            $detPlano,
393
                                            "cpfDep",
394
                                            !empty($pl->cpfdep) ? $pl->cpfdep : null,
395
                                            false
396
                                        );
397
                                        $this->dom->addChild(
398
                                            $detPlano,
399
                                            "nmDep",
400
                                            $pl->nmdep,
401
                                            true
402
                                        );
403
                                        $this->dom->addChild(
404
                                            $detPlano,
405
                                            "dtNascto",
406
                                            $pl->dtnascto,
407
                                            true
408
                                        );
409
                                        $this->dom->addChild(
410
                                            $detPlano,
411
                                            "vlrPgDep",
412
                                            $pl->vlrpgdep,
413
                                            true
414
                                        );
415
                                        $detOper->appendChild($detPlano);
416
                                    }
417
                                }
418
                                $infoSaudeColet->appendChild($detOper);
419
                            }
420
                            $remunPerApur->appendChild($infoSaudeColet);
421
                        }
422
                        if (!empty($rpa->infoagnocivo)) {
423
                            $infoAgNocivo = $this->dom->createElement("infoAgNocivo");
424
                            $this->dom->addChild(
425
                                $infoAgNocivo,
426
                                "grauExp",
427
                                $rpa->infoagnocivo->grauexp,
428
                                true
429
                            );
430
                            $remunPerApur->appendChild($infoAgNocivo);
431
                        }
432
                        
433
                        if (!empty($rpa->infotrabinterm)) {
434
                            foreach ($rpa->infotrabinterm as $iti) {
435
                                $infoTrabInterm = $this->dom->createElement("infoTrabInterm");
436
                                $this->dom->addChild(
437
                                    $infoTrabInterm,
438
                                    "codConv",
439
                                    $iti->codconv,
440
                                    true
441
                                );
442
                                $remunPerApur->appendChild($infoTrabInterm);
443
                            }
444
                        }
445
                        
446
                        $ideEstabLot->appendChild($remunPerApur);
447
                    }
448
                    $infoPerApur->appendChild($ideEstabLot);
449
                }
450
                $dmDev->appendChild($infoPerApur);
451
                if (!empty($dm->ideadc)) {
452
                    $infoPerAnt = $this->dom->createElement("infoPerAnt");
453
                    foreach ($dm->ideadc as $adc) {
454
                        $ideADC = $this->dom->createElement("ideADC");
455
                        $this->dom->addChild(
456
                            $ideADC,
457
                            "dtAcConv",
458
                            !empty($adc->dtacconv) ? $adc->dtacconv : null,
459
                            false
460
                        );
461
                        $this->dom->addChild(
462
                            $ideADC,
463
                            "tpAcConv",
464
                            $adc->tpacconv,
465
                            true
466
                        );
467
                        $this->dom->addChild(
468
                            $ideADC,
469
                            "compAcConv",
470
                            !empty($adc->compacconv) ? $adc->compacconv : null,
471
                            false
472
                        );
473
                        $this->dom->addChild(
474
                            $ideADC,
475
                            "dtEfAcConv",
476
                            !empty($adc->dtefacconv) ? $adc->dtefacconv : null,
477
                            false
478
                        );
479
                        $this->dom->addChild(
480
                            $ideADC,
481
                            "dsc",
482
                            $adc->dsc,
483
                            true
484
                        );
485
                        $this->dom->addChild(
486
                            $ideADC,
487
                            "remunSuc",
488
                            $adc->remunsuc,
489
                            true
490
                        );
491
                        foreach ($adc->ideperiodo as $idp) {
492
                            $idePeriodo = $this->dom->createElement("idePeriodo");
493
                            $this->dom->addChild(
494
                                $idePeriodo,
495
                                "perRef",
496
                                $idp->perref,
497
                                true
498
                            );
499
                            foreach ($idp->ideestablot as $idl) {
500
                                $ideEstabLot = $this->dom->createElement("ideEstabLot");
501
                                $this->dom->addChild(
502
                                    $ideEstabLot,
503
                                    "tpInsc",
504
                                    $idl->tpinsc,
505
                                    true
506
                                );
507
                                $this->dom->addChild(
508
                                    $ideEstabLot,
509
                                    "nrInsc",
510
                                    $idl->nrinsc,
511
                                    true
512
                                );
513
                                $this->dom->addChild(
514
                                    $ideEstabLot,
515
                                    "codLotacao",
516
                                    $idl->codlotacao,
517
                                    true
518
                                );
519
                                foreach ($idl->remunperant as $rpr) {
520
                                    $remunPerAnt = $this->dom->createElement("remunPerAnt");
521
                                    $this->dom->addChild(
522
                                        $remunPerAnt,
523
                                        "matricula",
524
                                        !empty($rpr->matricula) ? $rpr->matricula : null,
525
                                        false
526
                                    );
527
                                    $this->dom->addChild(
528
                                        $remunPerAnt,
529
                                        "indSimples",
530
                                        !empty($rpr->indsimples) ? $rpr->indsimples : null,
531
                                        false
532
                                    );
533
                                    foreach ($rpr->itensremun as $irem) {
534
                                        $itensRemun = $this->dom->createElement("itensRemun");
535
                                        $this->dom->addChild(
536
                                            $itensRemun,
537
                                            "codRubr",
538
                                            $irem->codrubr,
539
                                            true
540
                                        );
541
                                        $this->dom->addChild(
542
                                            $itensRemun,
543
                                            "ideTabRubr",
544
                                            $irem->idetabrubr,
545
                                            true
546
                                        );
547
                                        $this->dom->addChild(
548
                                            $itensRemun,
549
                                            "qtdRubr",
550
                                            !empty($irem->qtdrubr) ? $irem->qtdrubr : null,
551
                                            false
552
                                        );
553
                                        $this->dom->addChild(
554
                                            $itensRemun,
555
                                            "fatorRubr",
556
                                            !empty($irem->fatorrubr) ? $irem->fatorrubr : null,
557
                                            false
558
                                        );
559
                                        $this->dom->addChild(
560
                                            $itensRemun,
561
                                            "vrUnit",
562
                                            !empty($irem->vrunit) ? $irem->vrunit : null,
563
                                            false
564
                                        );
565
                                        $this->dom->addChild(
566
                                            $itensRemun,
567
                                            "vrRubr",
568
                                            $irem->vrrubr,
569
                                            true
570
                                        );
571
                                        $remunPerAnt->appendChild($itensRemun);
572
                                    }
573
                                    if (!empty($rpr->infoagnocivo)) {
574
                                        $infoAgNocivo = $this->dom->createElement("infoAgNocivo");
575
                                        $this->dom->addChild(
576
                                            $infoAgNocivo,
577
                                            "grauExp",
578
                                            $rpr->infoagnocivo->grauexp,
579
                                            true
580
                                        );
581
                                        $remunPerAnt->appendChild($infoAgNocivo);
582
                                    }
583
                                    
584
                                    if (!empty($rpr->infotrabinterm)) {
585
                                        foreach ($rpr->infotrabinterm as $iti) {
586
                                            $infoTrabInterm = $this->dom->createElement("infoTrabInterm");
587
                                            $this->dom->addChild(
588
                                                $infoTrabInterm,
589
                                                "codConv",
590
                                                $iti->codconv,
591
                                                true
592
                                            );
593
                                            $remunPerAnt->appendChild($infoTrabInterm);
594
                                        }
595
                                    }
596
                                    
597
                                    $ideEstabLot->appendChild($remunPerAnt);
598
                                }
599
                                $idePeriodo->appendChild($ideEstabLot);
600
                            }
601
                            $ideADC->appendChild($idePeriodo);
602
                        }
603
                        
604
                        $infoPerAnt->appendChild($ideADC);
605
                    }
606
                    $dmDev->appendChild($infoPerAnt);
607
                }
608
                
609
                if (!empty($dm->infocomplcont)) {
610
                    $infoComplCont = $this->dom->createElement("infoComplCont");
611
                    $this->dom->addChild(
612
                        $infoComplCont,
613
                        "codCBO",
614
                        $dm->infocomplcont->codcbo,
615
                        true
616
                    );
617
                    $this->dom->addChild(
618
                        $infoComplCont,
619
                        "natAtividade",
620
                        !empty($dm->infocomplcont->natatividade) ? $dm->infocomplcont->natatividade : null,
621
                        false
622
                    );
623
                    $this->dom->addChild(
624
                        $infoComplCont,
625
                        "qtdDiasTrab",
626
                        !empty($dm->infocomplcont->qtddiastrab) ? $dm->infocomplcont->qtddiastrab : null,
627
                        false
628
                    );
629
                    $dmDev->appendChild($infoComplCont);
630
                }
631
            }
632
            
633
            
634
            
635
            $this->node->appendChild($dmDev);
636
        }
637
        $this->eSocial->appendChild($this->node);
638
        //$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...
639
        $this->sign();
640
    }
641
}
642