Passed
Push — master ( c7de96...eccb15 )
by Roberto
02:35
created

EvtCAT::toNode()   D

Complexity

Conditions 17
Paths 36

Size

Total Lines 207

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 306

Importance

Changes 0
Metric Value
dl 0
loc 207
ccs 0
cts 200
cp 0
rs 4.1733
c 0
b 0
f 0
cc 17
nc 36
nop 0
crap 306

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtCAT Event S-2210 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 EvtCAT extends Factory implements FactoryInterface
27
{
28
    /**
29
     * @var string
30
     */
31
    protected $evtName = 'evtCAT';
32
    /**
33
     * @var string
34
     */
35
    protected $evtAlias = 'S-2210';
36
    /**
37
     * Parameters patterns
38
     *
39
     * @var array
40
     */
41
    protected $parameters = [];
42
43
    /**
44
     * Constructor
45
     *
46
     * @param string $config
47
     * @param stdClass $std
48
     * @param Certificate $certificate | null
49
     * @param string $date
50
     */
51
    public function __construct(
52
        $config,
53
        stdClass $std,
54
        Certificate $certificate = null,
55
        $date = ''
56
    ) {
57
        parent::__construct($config, $std, $certificate, $date);
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
        $this->tagVinculo();
100
        
101
        $cat = $this->tagCAT();
102
        $this->tagLocalAcidente($cat);
103
        
104
        
105
        
106
        foreach ($this->std->parteatingida as $pa) {
107
            $parteAtingida = $this->dom->createElement("parteAtingida");
108
            $this->dom->addChild(
109
                $parteAtingida,
110
                "codParteAting",
111
                $pa->codparteating,
112
                true
113
            );
114
            $this->dom->addChild(
115
                $parteAtingida,
116
                "lateralidade",
117
                $pa->lateralidade,
118
                true
119
            );
120
            $cat->appendChild($parteAtingida);
121
        }
122
123
        foreach ($this->std->agentecausador as $pa) {
124
            $agenteCausador = $this->dom->createElement("agenteCausador");
125
            $this->dom->addChild(
126
                $agenteCausador,
127
                "codAgntCausador",
128
                $pa->codagntcausador,
129
                true
130
            );
131
            $cat->appendChild($agenteCausador);
132
        }
133
        if (!empty($this->std->atestado)) {
134
            $pa = $this->std->atestado;
135
            $atestado = $this->dom->createElement("atestado");
136
            $this->dom->addChild(
137
                $atestado,
138
                "codCNES",
139
                !empty($pa->codcnes) ? $pa->codcnes : null,
140
                false
141
            );
142
            $this->dom->addChild(
143
                $atestado,
144
                "dtAtendimento",
145
                $pa->dtatendimento,
146
                true
147
            );
148
            $this->dom->addChild(
149
                $atestado,
150
                "hrAtendimento",
151
                $pa->hratendimento,
152
                true
153
            );
154
            $this->dom->addChild(
155
                $atestado,
156
                "indInternacao",
157
                $pa->indinternacao,
158
                true
159
            );
160
            $this->dom->addChild(
161
                $atestado,
162
                "durTrat",
163
                $pa->durtrat,
164
                true
165
            );
166
            $this->dom->addChild(
167
                $atestado,
168
                "indAfast",
169
                $pa->indafast,
170
                true
171
            );
172
            $this->dom->addChild(
173
                $atestado,
174
                "dscLesao",
175
                !empty($pa->dsclesao) ? $pa->dsclesao : null,
176
                false
177
            );
178
            $this->dom->addChild(
179
                $atestado,
180
                "dscCompLesao",
181
                !empty($pa->dsccomplesao) ? $pa->dsccomplesao : null,
182
                false
183
            );
184
            $this->dom->addChild(
185
                $atestado,
186
                "diagProvavel",
187
                !empty($pa->diagprovavel) ? $pa->diagprovavel : null,
188
                false
189
            );
190
            $this->dom->addChild(
191
                $atestado,
192
                "codCID",
193
                $pa->codcid,
194
                true
195
            );
196
            $this->dom->addChild(
197
                $atestado,
198
                "observacao",
199
                !empty($pa->observacao) ? $pa->observacao : null,
200
                false
201
            );
202
            $emitente = $this->dom->createElement("emitente");
203
            $this->dom->addChild(
204
                $emitente,
205
                "nmEmit",
206
                $pa->nmemit,
207
                true
208
            );
209
            $this->dom->addChild(
210
                $emitente,
211
                "ideOC",
212
                $pa->ideoc,
213
                true
214
            );
215
            if ($this->layoutStr == 'v02_05_00') {
216
                $this->dom->addChild(
217
                    $emitente,
218
                    "nrOC",
219
                    $pa->nroc,
220
                    true
221
                );
222
            } else {
223
                $this->dom->addChild(
224
                    $emitente,
225
                    "nrOc",
226
                    $pa->nroc,
227
                    true
228
                );
229
            }
230
            $this->dom->addChild(
231
                $emitente,
232
                "ufOC",
233
                !empty($pa->ufoc) ? $pa->ufoc : null,
234
                true
235
            );
236
            $atestado->appendChild($emitente);
237
            $cat->appendChild($atestado);
238
        }
239
        if (!empty($this->std->catorigem)) {
240
            $pa = $this->std->catorigem;
241
            $catOrigem = $this->dom->createElement("catOrigem");
242
            $this->dom->addChild(
243
                $catOrigem,
244
                "dtCatOrig",
245
                !empty($pa->dtcatorig) ? $pa->dtcatorig : null,
246
                false
247
            );
248
            if ($this->layoutStr != 'v02_05_00') {
249
                $this->dom->addChild(
250
                    $catOrigem,
251
                    "nrCatOrig",
252
                    !empty($pa->nrcatorig) ? $pa->nrcatorig : null,
253
                    false
254
                );
255
            } else {
256
                $this->dom->addChild(
257
                    $catOrigem,
258
                    "nrRecCatOrig",
259
                    !empty($pa->nrreccatorig) ? $pa->nrreccatorig : null,
260
                    false
261
                );
262
            }
263
            $cat->appendChild($catOrigem);
264
        }
265
        $this->node->appendChild($cat);
266
        $this->eSocial->appendChild($this->node);
267
        //$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...
268
        $this->sign();
269
    }
270
    
271
    protected function tagRegistrador(\DOMElement $ideEmpregador)
272
    {
273
        $ideRegistrador = $this->dom->createElement("ideRegistrador");
274
        $this->dom->addChild(
275
            $ideRegistrador,
276
            "tpRegistrador",
277
            $this->std->tpregistrador,
278
            true
279
        );
280
        $this->dom->addChild(
281
            $ideRegistrador,
282
            "tpInsc",
283
            !empty($this->std->tpinsc) ? $this->std->tpinsc : null,
284
            false
285
        );
286
        $this->dom->addChild(
287
            $ideRegistrador,
288
            "nrInsc",
289
            !empty($this->std->nrinsc) ? $this->std->nrinsc : null,
290
            false
291
        );
292
        $this->node->insertBefore($ideRegistrador, $ideEmpregador);
293
    }
294
    
295
    protected function tagTrabalhador()
296
    {
297
        $ideTrabalhador = $this->dom->createElement("ideTrabalhador");
298
        $this->dom->addChild(
299
            $ideTrabalhador,
300
            "cpfTrab",
301
            $this->std->cpftrab,
302
            true
303
        );
304
        $this->dom->addChild(
305
            $ideTrabalhador,
306
            "nisTrab",
307
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
308
            false
309
        );
310
        $this->node->appendChild($ideTrabalhador);
311
    }
312
    
313
    protected function tagVinculo()
314
    {
315
        $ideVinculo = $this->dom->createElement("ideVinculo");
316
        $this->dom->addChild(
317
            $ideVinculo,
318
            "cpfTrab",
319
            $this->std->cpftrab,
320
            true
321
        );
322
        $this->dom->addChild(
323
            $ideVinculo,
324
            "nisTrab",
325
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
326
            false
327
        );
328
        $this->dom->addChild(
329
            $ideVinculo,
330
            "matricula",
331
            !empty($this->std->matricula) ? $this->std->matricula : null,
332
            false
333
        );
334
        $this->dom->addChild(
335
            $ideVinculo,
336
            "codCateg",
337
            !empty($this->std->codcateg) ? $this->std->codcateg : null,
338
            false
339
        );
340
        $this->node->appendChild($ideVinculo);
341
    }
342
    
343
    protected function tagCAT()
344
    {
345
        $cat = $this->dom->createElement("cat");
346
        $this->dom->addChild(
347
            $cat,
348
            "dtAcid",
349
            $this->std->dtacid,
350
            true
351
        );
352
        $this->dom->addChild(
353
            $cat,
354
            "tpAcid",
355
            $this->std->tpacid,
356
            true
357
        );
358
        $this->dom->addChild(
359
            $cat,
360
            "hrAcid",
361
            $this->std->hracid,
362
            true
363
        );
364
        $this->dom->addChild(
365
            $cat,
366
            "hrsTrabAntesAcid",
367
            $this->std->hrstrabantesacid,
368
            true
369
        );
370
        $this->dom->addChild(
371
            $cat,
372
            "tpCat",
373
            $this->std->tpcat,
374
            true
375
        );
376
        $this->dom->addChild(
377
            $cat,
378
            "indCatObito",
379
            $this->std->indcatobito,
380
            true
381
        );
382
        $this->dom->addChild(
383
            $cat,
384
            "dtObito",
385
            !empty($this->std->dtobito) ? $this->std->dtobito : null,
386
            false
387
        );
388
        $this->dom->addChild(
389
            $cat,
390
            "indComunPolicia",
391
            $this->std->indcomunpolicia,
392
            true
393
        );
394
        $this->dom->addChild(
395
            $cat,
396
            "codSitGeradora",
397
            !empty($this->std->codsitgeradora) ? $this->std->codsitgeradora : null,
398
            false
399
        );
400
        $this->dom->addChild(
401
            $cat,
402
            "iniciatCAT",
403
            $this->std->iniciatcat,
404
            true
405
        );
406
        if ($this->layoutStr !== 'v02_04_02') {
407
            $this->dom->addChild(
408
                $cat,
409
                "obsCAT",
410
                !empty($this->std->obscat) ? $this->std->obscat : null,
411
                false
412
            );
413
        } else {
414
            $this->dom->addChild(
415
                $cat,
416
                "observacao",
417
                !empty($this->std->observacao) ? $this->std->observacao : null,
418
                false
419
            );
420
        }
421
        return $cat;
422
    }
423
    
424
    protected function tagLocalAcidente(\DOMElement &$cat)
425
    {
426
        $localAcidente = $this->dom->createElement("localAcidente");
427
        $this->dom->addChild(
428
            $localAcidente,
429
            "tpLocal",
430
            $this->std->tplocal,
431
            true
432
        );
433
        $this->dom->addChild(
434
            $localAcidente,
435
            "dscLocal",
436
            !empty($this->std->dsclocal) ? $this->std->dsclocal : null,
437
            false
438
        );
439
        $this->dom->addChild(
440
            $localAcidente,
441
            "codAmb",
442
            !empty($this->std->codamb) ? $this->std->codamb : null,
443
            false
444
        );
445
        $this->dom->addChild(
446
            $localAcidente,
447
            "tpLograd",
448
            !empty($this->std->tplograd) ? $this->std->tplograd : null,
449
            false
450
        );
451
        $this->dom->addChild(
452
            $localAcidente,
453
            "dscLograd",
454
            !empty($this->std->dsclograd) ? $this->std->dsclograd : null,
455
            false
456
        );
457
        $this->dom->addChild(
458
            $localAcidente,
459
            "nrLograd",
460
            !empty($this->std->nrlograd) ? $this->std->nrlograd : null,
461
            false
462
        );
463
        $this->dom->addChild(
464
            $localAcidente,
465
            "complemento",
466
            !empty($this->std->complemento) ? $this->std->complemento : null,
467
            false
468
        );
469
        $this->dom->addChild(
470
            $localAcidente,
471
            "bairro",
472
            !empty($this->std->bairro) ? $this->std->bairro : null,
473
            false
474
        );
475
        $this->dom->addChild(
476
            $localAcidente,
477
            "cep",
478
            !empty($this->std->cep) ? $this->std->cep : null,
479
            false
480
        );
481
        $this->dom->addChild(
482
            $localAcidente,
483
            "codMunic",
484
            !empty($this->std->codmunic) ? $this->std->codmunic : null,
485
            false
486
        );
487
        $this->dom->addChild(
488
            $localAcidente,
489
            "uf",
490
            !empty($this->std->uf) ? $this->std->uf : null,
491
            false
492
        );
493
        $this->dom->addChild(
494
            $localAcidente,
495
            "cnpjLocalAcid",
496
            !empty($this->std->cnpjlocalacid) ? $this->std->cnpjlocalacid : null,
497
            false
498
        );
499
        $this->dom->addChild(
500
            $localAcidente,
501
            "pais",
502
            !empty($this->std->pais) ? $this->std->pais : null,
503
            false
504
        );
505
        $this->dom->addChild(
506
            $localAcidente,
507
            "codPostal",
508
            !empty($this->std->codpostal) ? $this->std->codpostal : null,
509
            false
510
        );
511
        $cat->appendChild($localAcidente);
512
    }
513
}
514