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

EvtCS::toNode()   D

Complexity

Conditions 35
Paths 24

Size

Total Lines 586
Code Lines 471

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1260

Importance

Changes 0
Metric Value
dl 0
loc 586
ccs 0
cts 578
cp 0
rs 4.297
c 0
b 0
f 0
cc 35
eloc 471
nc 24
nop 0
crap 1260

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 EvtCS Event S-5011 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 EvtCS extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
    /**
31
     * @var string
32
     */
33
    protected $evtName = 'evtCS';
34
    /**
35
     * @var string
36
     */
37
    protected $evtAlias = 'S-5011';
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
            "indApuracao",
70
            $this->std->indapuracao,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "perApur",
76
            $this->std->perapur,
77
            true
78
        );
79
        $this->node->insertBefore($ideEvento, $ideEmpregador);
80
        
81
        $infoCS = $this->dom->createElement("infoCS");
82
        $this->dom->addChild(
83
            $infoCS,
84
            "nrRecArqBase",
85
            !empty($this->std->nrrecarqbase) ? $this->std->nrrecarqbase : null,
86
            false
87
        );
88
        $this->dom->addChild(
89
            $infoCS,
90
            "indExistInfo",
91
            $this->std->indexistinfo,
92
            true
93
        );
94
95
        if (!empty($this->std->infocpseg)) {
96
            $ips = $this->std->infocpseg;
97
            $infoCPSeg = $this->dom->createElement("infoCPSeg");
98
            $this->dom->addChild(
99
                $infoCPSeg,
100
                "vrDescCP",
101
                $ips->vrdesccp,
102
                true
103
            );
104
            $this->dom->addChild(
105
                $infoCPSeg,
106
                "vrCpSeg",
107
                $ips->vrcpseg,
108
                true
109
            );
110
            $infoCS->appendChild($infoCPSeg);
111
        }
112
        $ict = $this->std->infocontrib;
113
        $infoContrib = $this->dom->createElement("infoContrib");
114
        $this->dom->addChild(
115
            $infoContrib,
116
            "classTrib",
117
            $ict->classtrib,
118
            true
119
        );
120
        if (!empty($ict->infopj)) {
121
            $ipj = $ict->infopj;
122
            $infoPJ = $this->dom->createElement("infoPJ");
123
            $this->dom->addChild(
124
                $infoPJ,
125
                "indCoop",
126
                !empty($ipj->indcoop) ? $ipj->indcoop : null,
127
                false
128
            );
129
            $this->dom->addChild(
130
                $infoPJ,
131
                "indConstr",
132
                $ipj->indconstr,
133
                true
134
            );
135
            $this->dom->addChild(
136
                $infoPJ,
137
                "indSubstPatr",
138
                !empty($ipj->indsubstpatr) ? $ipj->indsubstpatr : null,
139
                false
140
            );
141
            $this->dom->addChild(
142
                $infoPJ,
143
                "percRedContrib",
144
                !empty($ipj->percredcontrib) ? $ipj->percredcontrib : null,
145
                false
146
            );
147
            if (!empty($ipj->infoatconc)) {
148
                $at = $ipj->infoatconc;
149
                $infoAtConc = $this->dom->createElement("infoAtConc");
150
                $this->dom->addChild(
151
                    $infoAtConc,
152
                    "fatorMes",
153
                    $at->fatormes,
154
                    true
155
                );
156
                $this->dom->addChild(
157
                    $infoAtConc,
158
                    "fator13",
159
                    $at->fator13,
160
                    true
161
                );
162
163
                $infoPJ->appendChild($infoAtConc);
164
            }
165
            $infoContrib->appendChild($infoPJ);
166
        }
167
        $infoCS->appendChild($infoContrib);
168
        
169
        if (!empty($this->std->ideestab)) {
170
            foreach ($this->std->ideestab as $is) {
171
                $ideEstab = $this->dom->createElement("ideEstab");
172
                $this->dom->addChild(
173
                    $ideEstab,
174
                    "tpInsc",
175
                    $is->tpinsc,
176
                    true
177
                );
178
                $this->dom->addChild(
179
                    $ideEstab,
180
                    "nrInsc",
181
                    $is->nrinsc,
182
                    true
183
                );
184
                if (!empty($is->infoestab)) {
185
                    $infoEstab = $this->dom->createElement("infoEstab");
186
                    $this->dom->addChild(
187
                        $infoEstab,
188
                        "cnaePrep",
189
                        $is->infoestab->cnaeprep,
190
                        true
191
                    );
192
                    $this->dom->addChild(
193
                        $infoEstab,
194
                        "aliqRat",
195
                        $is->infoestab->aliqrat,
196
                        true
197
                    );
198
                    $this->dom->addChild(
199
                        $infoEstab,
200
                        "fap",
201
                        $is->infoestab->fap,
202
                        true
203
                    );
204
                    $this->dom->addChild(
205
                        $infoEstab,
206
                        "aliqRatAjust",
207
                        $is->infoestab->aliqratajust,
208
                        true
209
                    );
210
                    if (!empty($is->infoestab->infocomplobra)) {
211
                        $infoComplObra = $this->dom->createElement("infoComplObra");
212
                        $this->dom->addChild(
213
                            $infoComplObra,
214
                            "indSubstPatrObra",
215
                            $is->infoestab->infocomplobra->indsubstpatrobra,
216
                            true
217
                        );
218
                        $infoEstab->appendChild($infoComplObra);
219
                    }
220
                    $ideEstab->appendChild($infoEstab);
221
                }
222
                if (!empty($is->idelotacao)) {
223
                    foreach ($is->idelotacao as $id) {
224
                        $ideLotacao = $this->dom->createElement("ideLotacao");
225
                        $this->dom->addChild(
226
                            $ideLotacao,
227
                            "codLotacao",
228
                            $id->codlotacao,
229
                            true
230
                        );
231
                        $this->dom->addChild(
232
                            $ideLotacao,
233
                            "fpas",
234
                            $id->fpas,
235
                            true
236
                        );
237
                        $this->dom->addChild(
238
                            $ideLotacao,
239
                            "codTercs",
240
                            $id->codtercs,
241
                            true
242
                        );
243
                        $this->dom->addChild(
244
                            $ideLotacao,
245
                            "codTercsSusp",
246
                            !empty($id->codtercssusp) ? $id->codtercssusp : null,
247
                            false
248
                        );
249
                        if (!empty($id->infotercsusp)) {
250
                            foreach ($id->infotercsusp as $tsus) {
251
                                $infoTercSusp = $this->dom->createElement("infoTercSusp");
252
                                $this->dom->addChild(
253
                                    $infoTercSusp,
254
                                    "codTerc",
255
                                    $tsus->codterc,
256
                                    true
257
                                );
258
                                $ideLotacao->appendChild($infoTercSusp);
259
                            }
260
                        }
261
                        if (!empty($id->infoemprparcial)) {
262
                            $infoEmprParcial = $this->dom->createElement("infoEmprParcial");
263
                            $this->dom->addChild(
264
                                $infoEmprParcial,
265
                                "tpInscContrat",
266
                                $id->infoemprparcial->tpinsccontrat,
267
                                true
268
                            );
269
                            $this->dom->addChild(
270
                                $infoEmprParcial,
271
                                "nrInscContrat",
272
                                $id->infoemprparcial->nrinsccontrat,
273
                                true
274
                            );
275
                            $this->dom->addChild(
276
                                $infoEmprParcial,
277
                                "tpInscProp",
278
                                $id->infoemprparcial->tpinscprop,
279
                                true
280
                            );
281
                            $this->dom->addChild(
282
                                $infoEmprParcial,
283
                                "nrInscProp",
284
                                $id->infoemprparcial->nrinscprop,
285
                                true
286
                            );
287
                            $ideLotacao->appendChild($infoEmprParcial);
288
                        }
289
                        if (!empty($id->dadosopport)) {
290
                            $dadosOpPort = $this->dom->createElement("dadosOpPort");
291
                            $this->dom->addChild(
292
                                $dadosOpPort,
293
                                "cnpjOpPortuario",
294
                                $id->dadosopport->cnpjopportuario,
295
                                true
296
                            );
297
                            $this->dom->addChild(
298
                                $dadosOpPort,
299
                                "aliqRat",
300
                                $id->dadosopport->aliqrat,
301
                                true
302
                            );
303
                            $this->dom->addChild(
304
                                $dadosOpPort,
305
                                "fap",
306
                                $id->dadosopport->fap,
307
                                true
308
                            );
309
                            $this->dom->addChild(
310
                                $dadosOpPort,
311
                                "aliqRatAjust",
312
                                $id->dadosopport->aliqratajust,
313
                                true
314
                            );
315
                            $ideLotacao->appendChild($dadosOpPort);
316
                        }
317
                        if (!empty($id->basesremun)) {
318
                            foreach ($id->basesremun as $br) {
319
                                $basesRemun = $this->dom->createElement("basesRemun");
320
                                $this->dom->addChild(
321
                                    $basesRemun,
322
                                    "indIncid",
323
                                    $br->indincid,
324
                                    true
325
                                );
326
                                $this->dom->addChild(
327
                                    $basesRemun,
328
                                    "codCateg",
329
                                    $br->codcateg,
330
                                    true
331
                                );
332
                                $basesCp = $this->dom->createElement("basesCp");
333
                                $this->dom->addChild(
334
                                    $basesCp,
335
                                    "vrBcCp00",
336
                                    $br->basescp->vrbccp00,
337
                                    true
338
                                );
339
                                $this->dom->addChild(
340
                                    $basesCp,
341
                                    "vrBcCp15",
342
                                    $br->basescp->vrbccp15,
343
                                    true
344
                                );
345
                                $this->dom->addChild(
346
                                    $basesCp,
347
                                    "vrBcCp20",
348
                                    $br->basescp->vrbccp20,
349
                                    true
350
                                );
351
                                $this->dom->addChild(
352
                                    $basesCp,
353
                                    "vrBcCp25",
354
                                    $br->basescp->vrbccp25,
355
                                    true
356
                                );
357
                                $this->dom->addChild(
358
                                    $basesCp,
359
                                    "vrSuspBcCp00",
360
                                    $br->basescp->vrsuspbccp00,
361
                                    true
362
                                );
363
                                $this->dom->addChild(
364
                                    $basesCp,
365
                                    "vrSuspBcCp15",
366
                                    $br->basescp->vrsuspbccp15,
367
                                    true
368
                                );
369
                                $this->dom->addChild(
370
                                    $basesCp,
371
                                    "vrSuspBcCp20",
372
                                    $br->basescp->vrsuspbccp20,
373
                                    true
374
                                );
375
                                $this->dom->addChild(
376
                                    $basesCp,
377
                                    "vrSuspBcCp25",
378
                                    $br->basescp->vrsuspbccp25,
379
                                    true
380
                                );
381
                                $this->dom->addChild(
382
                                    $basesCp,
383
                                    "vrDescSest",
384
                                    $br->basescp->vrdescsest,
385
                                    true
386
                                );
387
                                $this->dom->addChild(
388
                                    $basesCp,
389
                                    "vrCalcSest",
390
                                    $br->basescp->vrcalcsest,
391
                                    true
392
                                );
393
                                $this->dom->addChild(
394
                                    $basesCp,
395
                                    "vrDescSenat",
396
                                    $br->basescp->vrdescsenat,
397
                                    true
398
                                );
399
                                $this->dom->addChild(
400
                                    $basesCp,
401
                                    "vrCalcSenat",
402
                                    $br->basescp->vrcalcsenat,
403
                                    true
404
                                );
405
                                $this->dom->addChild(
406
                                    $basesCp,
407
                                    "vrSalFam",
408
                                    $br->basescp->vrsalfam,
409
                                    true
410
                                );
411
                                $this->dom->addChild(
412
                                    $basesCp,
413
                                    "vrSalMat",
414
                                    $br->basescp->vrsalmat,
415
                                    true
416
                                );
417
                                $basesRemun->appendChild($basesCp);
418
                                $ideLotacao->appendChild($basesRemun);
419
                            }
420
                        }
421
                        
422
                        if (!empty($id->basesavnport)) {
423
                            $basesAvNPort = $this->dom->createElement("basesAvNPort");
424
                            $this->dom->addChild(
425
                                $basesAvNPort,
426
                                "vrBcCp00",
427
                                $id->basesavnport->vrbccp00,
428
                                true
429
                            );
430
                            $this->dom->addChild(
431
                                $basesAvNPort,
432
                                "vrBcCp15",
433
                                $id->basesavnport->vrbccp15,
434
                                true
435
                            );
436
                            $this->dom->addChild(
437
                                $basesAvNPort,
438
                                "vrBcCp20",
439
                                $id->basesavnport->vrbccp20,
440
                                true
441
                            );
442
                            $this->dom->addChild(
443
                                $basesAvNPort,
444
                                "vrBcCp25",
445
                                $id->basesavnport->vrbccp25,
446
                                true
447
                            );
448
                            $this->dom->addChild(
449
                                $basesAvNPort,
450
                                "vrBcCp13",
451
                                $id->basesavnport->vrbccp13,
452
                                true
453
                            );
454
                            $this->dom->addChild(
455
                                $basesAvNPort,
456
                                "vrBcFgts",
457
                                $id->basesavnport->vrbcfgts,
458
                                true
459
                            );
460
                            $this->dom->addChild(
461
                                $basesAvNPort,
462
                                "vrDescCP",
463
                                $id->basesavnport->vrdesccp,
464
                                true
465
                            );
466
                            $ideLotacao->appendChild($basesAvNPort);
467
                        }
468
                        
469
                        if (!empty($id->infosubstpatropport)) {
470
                            foreach ($id->infosubstpatropport as $ipp) {
471
                                $infoSubstPatrOpPort = $this->dom->createElement("infoSubstPatrOpPort");
472
                                $this->dom->addChild(
473
                                    $infoSubstPatrOpPort,
474
                                    "cnpjOpPortuario",
475
                                    $ipp->cnpjopportuario,
476
                                    true
477
                                );
478
                                $ideLotacao->appendChild($infoSubstPatrOpPort);
479
                            }
480
                        }
481
                        $ideEstab->appendChild($ideLotacao);
482
                    }
483
                }
484
                
485
                if (!empty($is->basesaquis)) {
486
                    foreach ($is->basesaquis as $bq) {
487
                        $basesAquis = $this->dom->createElement("basesAquis");
488
                        $this->dom->addChild(
489
                            $basesAquis,
490
                            "indAquis",
491
                            $bq->indaquis,
492
                            true
493
                        );
494
                        $this->dom->addChild(
495
                            $basesAquis,
496
                            "vlrAquis",
497
                            $bq->vlraquis,
498
                            true
499
                        );
500
                        $this->dom->addChild(
501
                            $basesAquis,
502
                            "vrCPDescPR",
503
                            $bq->vrcpdescpr,
504
                            true
505
                        );
506
                        $this->dom->addChild(
507
                            $basesAquis,
508
                            "vrCPNRet",
509
                            $bq->vrcpnret,
510
                            true
511
                        );
512
                        $this->dom->addChild(
513
                            $basesAquis,
514
                            "vrRatNRet",
515
                            $bq->vrratnret,
516
                            true
517
                        );
518
                        $this->dom->addChild(
519
                            $basesAquis,
520
                            "vrSenarNRet",
521
                            $bq->vrsenarnret,
522
                            true
523
                        );
524
                        $this->dom->addChild(
525
                            $basesAquis,
526
                            "vrCPCalcPR",
527
                            $bq->vrcpcalcpr,
528
                            true
529
                        );
530
                        $this->dom->addChild(
531
                            $basesAquis,
532
                            "vrRatDescPR",
533
                            $bq->vrratdescpr,
534
                            true
535
                        );
536
                        $this->dom->addChild(
537
                            $basesAquis,
538
                            "vrRatCalcPR",
539
                            $bq->vrratcalcpr,
540
                            true
541
                        );
542
                        $this->dom->addChild(
543
                            $basesAquis,
544
                            "vrSenarDesc",
545
                            $bq->vrsenardesc,
546
                            true
547
                        );
548
                        $this->dom->addChild(
549
                            $basesAquis,
550
                            "vrSenarCalc",
551
                            $bq->vrsenarcalc,
552
                            true
553
                        );
554
                        $ideEstab->appendChild($basesAquis);
555
                    }
556
                }
557
                if (!empty($is->basescomerc)) {
558
                    foreach ($is->basescomerc as $bc) {
559
                        $basesComerc = $this->dom->createElement("basesComerc");
560
                        $this->dom->addChild(
561
                            $basesComerc,
562
                            "indComerc",
563
                            $bc->indcomerc,
564
                            true
565
                        );
566
                        $this->dom->addChild(
567
                            $basesComerc,
568
                            "vrBcComPR",
569
                            $bc->vrbccompr,
570
                            true
571
                        );
572
                        $this->dom->addChild(
573
                            $basesComerc,
574
                            "vrCPSusp",
575
                            !empty($bc->vrcpsusp) ? $bc->vrcpsusp : null,
576
                            false
577
                        );
578
                        $this->dom->addChild(
579
                            $basesComerc,
580
                            "vrRatSusp",
581
                            !empty($bc->vrratsusp) ? $bc->vrratsusp : null,
582
                            false
583
                        );
584
                        $this->dom->addChild(
585
                            $basesComerc,
586
                            "vrSenarSusp",
587
                            !empty($bc->vrsenarsusp) ? $bc->vrsenarsusp : null,
588
                            false
589
                        );
590
                        $ideEstab->appendChild($basesComerc);
591
                    }
592
                }
593
                if (!empty($is->infocrestab)) {
594
                    foreach ($is->infocrestab as $cre) {
595
                        $infoCREstab = $this->dom->createElement("infoCREstab");
596
                        $this->dom->addChild(
597
                            $infoCREstab,
598
                            "tpCR",
599
                            $cre->tpcr,
600
                            true
601
                        );
602
                        $this->dom->addChild(
603
                            $infoCREstab,
604
                            "vrCR",
605
                            $cre->vrcr,
606
                            true
607
                        );
608
                        $this->dom->addChild(
609
                            $infoCREstab,
610
                            "vrSuspCR",
611
                            $cre->vrsuspcr,
612
                            true
613
                        );
614
                        $ideEstab->appendChild($infoCREstab);
615
                    }
616
                }
617
                $infoCS->appendChild($ideEstab);
618
            }
619
        }
620
        if (!empty($this->std->infocrcontrib)) {
621
            foreach ($this->std->infocrcontrib as $ic) {
622
                $infoCRContrib = $this->dom->createElement("infoCRContrib");
623
                $this->dom->addChild(
624
                    $infoCRContrib,
625
                    "tpCR",
626
                    $ic->tpcr,
627
                    true
628
                );
629
                $this->dom->addChild(
630
                    $infoCRContrib,
631
                    "vrCR",
632
                    $ic->vrcr,
633
                    true
634
                );
635
                $this->dom->addChild(
636
                    $infoCRContrib,
637
                    "vrCRSusp",
638
                    $ic->vrcrsusp,
639
                    true
640
                );
641
                $infoCS->appendChild($infoCRContrib);
642
            }
643
        }
644
        $this->node->appendChild($infoCS);
645
        $this->eSocial->appendChild($this->node);
646
        //$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...
647
        $this->sign();
648
    }
649
}
650