Test Failed
Push — master ( 88ea0f...5ac8de )
by Roberto
03:16 queued 14s
created

TraitS2210   B

Complexity

Total Complexity 49

Size/Duplication

Total Lines 489
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 49
lcom 1
cbo 0
dl 0
loc 489
rs 8.48
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
F toNode250() 0 212 18
A tagRegistrador() 0 23 3
A tagTrabalhador() 0 17 2
A tagVinculo() 0 29 4
B tagCAT() 0 80 6
C tagLocalAcidente() 0 91 14
A tagIdeLocalAcid() 0 17 1
A toNodeS100() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like TraitS2210 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 TraitS2210, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace NFePHP\eSocial\Factories\Traits;
4
5
trait TraitS2210
6
{
7
    /**
8
     * builder for version 2.5.0
9
     */
10
    protected function toNode250()
11
    {
12
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
0 ignored issues
show
Bug introduced by
The property node does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
        $ideEvento = $this->dom->createElement("ideEvento");
0 ignored issues
show
Bug introduced by
The property dom does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
        $this->dom->addChild(
15
            $ideEvento,
16
            "indRetif",
17
            $this->std->indretif,
0 ignored issues
show
Bug introduced by
The property std does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
            true
19
        );
20
        $this->dom->addChild(
21
            $ideEvento,
22
            "nrRecibo",
23
            ! empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
24
            false
25
        );
26
        $this->dom->addChild(
27
            $ideEvento,
28
            "tpAmb",
29
            $this->tpAmb,
0 ignored issues
show
Bug introduced by
The property tpAmb does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
            true
31
        );
32
        $this->dom->addChild(
33
            $ideEvento,
34
            "procEmi",
35
            $this->procEmi,
0 ignored issues
show
Bug introduced by
The property procEmi does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
            true
37
        );
38
        $this->dom->addChild(
39
            $ideEvento,
40
            "verProc",
41
            $this->verProc,
0 ignored issues
show
Bug introduced by
The property verProc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
            true
43
        );
44
        $this->node->insertBefore($ideEvento, $ideEmpregador);
45
46
        $this->tagVinculo();
47
48
        $cat = $this->tagCAT();
49
50
        $localAcidente = $this->tagLocalAcidente($cat);
51
52
        if (!empty($this->std->idelocalacid)) {
53
            $this->tagIdeLocalAcid($localAcidente);
54
        }
55
56
57
58
        foreach ($this->std->parteatingida as $pa) {
59
            $parteAtingida = $this->dom->createElement("parteAtingida");
60
            $this->dom->addChild(
61
                $parteAtingida,
62
                "codParteAting",
63
                $pa->codparteating,
64
                true
65
            );
66
            $this->dom->addChild(
67
                $parteAtingida,
68
                "lateralidade",
69
                $pa->lateralidade,
70
                true
71
            );
72
            $cat->appendChild($parteAtingida);
73
        }
74
75
        foreach ($this->std->agentecausador as $pa) {
76
            $agenteCausador = $this->dom->createElement("agenteCausador");
77
            $this->dom->addChild(
78
                $agenteCausador,
79
                "codAgntCausador",
80
                $pa->codagntcausador,
81
                true
82
            );
83
            $cat->appendChild($agenteCausador);
84
        }
85
        if (!empty($this->std->atestado)) {
86
            $pa = $this->std->atestado;
87
            $atestado = $this->dom->createElement("atestado");
88
            $this->dom->addChild(
89
                $atestado,
90
                "codCNES",
91
                !empty($pa->codcnes) ? $pa->codcnes : null,
92
                false
93
            );
94
            $this->dom->addChild(
95
                $atestado,
96
                "dtAtendimento",
97
                $pa->dtatendimento,
98
                true
99
            );
100
            $this->dom->addChild(
101
                $atestado,
102
                "hrAtendimento",
103
                $pa->hratendimento,
104
                true
105
            );
106
            $this->dom->addChild(
107
                $atestado,
108
                "indInternacao",
109
                $pa->indinternacao,
110
                true
111
            );
112
            $this->dom->addChild(
113
                $atestado,
114
                "durTrat",
115
                $pa->durtrat,
116
                true
117
            );
118
            $this->dom->addChild(
119
                $atestado,
120
                "indAfast",
121
                $pa->indafast,
122
                true
123
            );
124
            $this->dom->addChild(
125
                $atestado,
126
                "dscLesao",
127
                !empty($pa->dsclesao) ? $pa->dsclesao : null,
128
                false
129
            );
130
            $this->dom->addChild(
131
                $atestado,
132
                "dscCompLesao",
133
                !empty($pa->dsccomplesao) ? $pa->dsccomplesao : null,
134
                false
135
            );
136
            $this->dom->addChild(
137
                $atestado,
138
                "diagProvavel",
139
                !empty($pa->diagprovavel) ? $pa->diagprovavel : null,
140
                false
141
            );
142
            $this->dom->addChild(
143
                $atestado,
144
                "codCID",
145
                $pa->codcid,
146
                true
147
            );
148
            $this->dom->addChild(
149
                $atestado,
150
                "observacao",
151
                !empty($pa->observacao) ? $pa->observacao : null,
152
                false
153
            );
154
            $emitente = $this->dom->createElement("emitente");
155
            $this->dom->addChild(
156
                $emitente,
157
                "nmEmit",
158
                $pa->nmemit,
159
                true
160
            );
161
            $this->dom->addChild(
162
                $emitente,
163
                "ideOC",
164
                $pa->ideoc,
165
                true
166
            );
167
            if ($this->layoutStr == 'v02_05_00') {
0 ignored issues
show
Bug introduced by
The property layoutStr does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
168
                $this->dom->addChild(
169
                    $emitente,
170
                    "nrOC",
171
                    $pa->nroc,
172
                    true
173
                );
174
            } else {
175
                $this->dom->addChild(
176
                    $emitente,
177
                    "nrOc",
178
                    $pa->nroc,
179
                    true
180
                );
181
            }
182
            $this->dom->addChild(
183
                $emitente,
184
                "ufOC",
185
                !empty($pa->ufoc) ? $pa->ufoc : null,
186
                true
187
            );
188
            $atestado->appendChild($emitente);
189
            $cat->appendChild($atestado);
190
        }
191
        if (!empty($this->std->catorigem)) {
192
            $pa = $this->std->catorigem;
193
            $catOrigem = $this->dom->createElement("catOrigem");
194
            $this->dom->addChild(
195
                $catOrigem,
196
                "dtCatOrig",
197
                !empty($pa->dtcatorig) ? $pa->dtcatorig : null,
198
                false
199
            );
200
            if ($this->layoutStr != 'v02_05_00') {
201
                $this->dom->addChild(
202
                    $catOrigem,
203
                    "nrCatOrig",
204
                    !empty($pa->nrcatorig) ? $pa->nrcatorig : null,
205
                    false
206
                );
207
            } else {
208
                $this->dom->addChild(
209
                    $catOrigem,
210
                    "nrRecCatOrig",
211
                    !empty($pa->nrreccatorig) ? $pa->nrreccatorig : null,
212
                    false
213
                );
214
            }
215
            $cat->appendChild($catOrigem);
216
        }
217
        $this->node->appendChild($cat);
218
        $this->eSocial->appendChild($this->node);
0 ignored issues
show
Bug introduced by
The property eSocial does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
219
        //$this->xml = $this->dom->saveXML($this->eSocial);
220
        $this->sign();
0 ignored issues
show
Bug introduced by
It seems like sign() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
221
    }
222
223
    protected function tagRegistrador(\DOMElement $ideEmpregador)
224
    {
225
        $ideRegistrador = $this->dom->createElement("ideRegistrador");
226
        $this->dom->addChild(
227
            $ideRegistrador,
228
            "tpRegistrador",
229
            $this->std->tpregistrador,
230
            true
231
        );
232
        $this->dom->addChild(
233
            $ideRegistrador,
234
            "tpInsc",
235
            !empty($this->std->tpinsc) ? $this->std->tpinsc : null,
236
            false
237
        );
238
        $this->dom->addChild(
239
            $ideRegistrador,
240
            "nrInsc",
241
            !empty($this->std->nrinsc) ? $this->std->nrinsc : null,
242
            false
243
        );
244
        $this->node->insertBefore($ideRegistrador, $ideEmpregador);
245
    }
246
247
    protected function tagTrabalhador()
248
    {
249
        $ideTrabalhador = $this->dom->createElement("ideTrabalhador");
250
        $this->dom->addChild(
251
            $ideTrabalhador,
252
            "cpfTrab",
253
            $this->std->cpftrab,
254
            true
255
        );
256
        $this->dom->addChild(
257
            $ideTrabalhador,
258
            "nisTrab",
259
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
260
            false
261
        );
262
        $this->node->appendChild($ideTrabalhador);
263
    }
264
265
    protected function tagVinculo()
266
    {
267
        $ideVinculo = $this->dom->createElement("ideVinculo");
268
        $this->dom->addChild(
269
            $ideVinculo,
270
            "cpfTrab",
271
            $this->std->cpftrab,
272
            true
273
        );
274
        $this->dom->addChild(
275
            $ideVinculo,
276
            "nisTrab",
277
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
278
            false
279
        );
280
        $this->dom->addChild(
281
            $ideVinculo,
282
            "matricula",
283
            !empty($this->std->matricula) ? $this->std->matricula : null,
284
            false
285
        );
286
        $this->dom->addChild(
287
            $ideVinculo,
288
            "codCateg",
289
            !empty($this->std->codcateg) ? $this->std->codcateg : null,
290
            false
291
        );
292
        $this->node->appendChild($ideVinculo);
293
    }
294
295
    protected function tagCAT()
296
    {
297
        $cat = $this->dom->createElement("cat");
298
        $this->dom->addChild(
299
            $cat,
300
            "dtAcid",
301
            $this->std->dtacid,
302
            true
303
        );
304
        $this->dom->addChild(
305
            $cat,
306
            "tpAcid",
307
            $this->std->tpacid,
308
            true
309
        );
310
        $this->dom->addChild(
311
            $cat,
312
            "hrAcid",
313
            $this->std->hracid,
314
            true
315
        );
316
        $this->dom->addChild(
317
            $cat,
318
            "hrsTrabAntesAcid",
319
            $this->std->hrstrabantesacid,
320
            true
321
        );
322
        $this->dom->addChild(
323
            $cat,
324
            "tpCat",
325
            $this->std->tpcat,
326
            true
327
        );
328
        $this->dom->addChild(
329
            $cat,
330
            "indCatObito",
331
            $this->std->indcatobito,
332
            true
333
        );
334
        $this->dom->addChild(
335
            $cat,
336
            "dtObito",
337
            !empty($this->std->dtobito) ? $this->std->dtobito : null,
338
            false
339
        );
340
        $this->dom->addChild(
341
            $cat,
342
            "indComunPolicia",
343
            $this->std->indcomunpolicia,
344
            true
345
        );
346
        $this->dom->addChild(
347
            $cat,
348
            "codSitGeradora",
349
            !empty($this->std->codsitgeradora) ? $this->std->codsitgeradora : null,
350
            false
351
        );
352
        $this->dom->addChild(
353
            $cat,
354
            "iniciatCAT",
355
            $this->std->iniciatcat,
356
            true
357
        );
358
        if ($this->layoutStr !== 'v02_04_02') {
359
            $this->dom->addChild(
360
                $cat,
361
                "obsCAT",
362
                !empty($this->std->obscat) ? $this->std->obscat : null,
363
                false
364
            );
365
        } else {
366
            $this->dom->addChild(
367
                $cat,
368
                "observacao",
369
                !empty($this->std->observacao) ? $this->std->observacao : null,
370
                false
371
            );
372
        }
373
        return $cat;
374
    }
375
376
    protected function tagLocalAcidente(\DOMElement &$cat)
377
    {
378
        $localAcidente = $this->dom->createElement("localAcidente");
379
        $this->dom->addChild(
380
            $localAcidente,
381
            "tpLocal",
382
            $this->std->tplocal,
383
            true
384
        );
385
        $this->dom->addChild(
386
            $localAcidente,
387
            "dscLocal",
388
            !empty($this->std->dsclocal) ? $this->std->dsclocal : null,
389
            false
390
        );
391
        $this->dom->addChild(
392
            $localAcidente,
393
            "codAmb",
394
            !empty($this->std->codamb) ? $this->std->codamb : null,
395
            false
396
        );
397
        $this->dom->addChild(
398
            $localAcidente,
399
            "tpLograd",
400
            !empty($this->std->tplograd) ? $this->std->tplograd : null,
401
            false
402
        );
403
        $this->dom->addChild(
404
            $localAcidente,
405
            "dscLograd",
406
            !empty($this->std->dsclograd) ? $this->std->dsclograd : null,
407
            false
408
        );
409
        $this->dom->addChild(
410
            $localAcidente,
411
            "nrLograd",
412
            !empty($this->std->nrlograd) ? $this->std->nrlograd : null,
413
            false
414
        );
415
        $this->dom->addChild(
416
            $localAcidente,
417
            "complemento",
418
            !empty($this->std->complemento) ? $this->std->complemento : null,
419
            false
420
        );
421
        $this->dom->addChild(
422
            $localAcidente,
423
            "bairro",
424
            !empty($this->std->bairro) ? $this->std->bairro : null,
425
            false
426
        );
427
        $this->dom->addChild(
428
            $localAcidente,
429
            "cep",
430
            !empty($this->std->cep) ? $this->std->cep : null,
431
            false
432
        );
433
        $this->dom->addChild(
434
            $localAcidente,
435
            "codMunic",
436
            !empty($this->std->codmunic) ? $this->std->codmunic : null,
437
            false
438
        );
439
        $this->dom->addChild(
440
            $localAcidente,
441
            "uf",
442
            !empty($this->std->uf) ? $this->std->uf : null,
443
            false
444
        );
445
        $this->dom->addChild(
446
            $localAcidente,
447
            "cnpjLocalAcid",
448
            !empty($this->std->cnpjlocalacid) ? $this->std->cnpjlocalacid : null,
449
            false
450
        );
451
        $this->dom->addChild(
452
            $localAcidente,
453
            "pais",
454
            !empty($this->std->pais) ? $this->std->pais : null,
455
            false
456
        );
457
        $this->dom->addChild(
458
            $localAcidente,
459
            "codPostal",
460
            !empty($this->std->codpostal) ? $this->std->codpostal : null,
461
            false
462
        );
463
        $cat->appendChild($localAcidente);
464
465
        return $localAcidente;
466
    }
467
468
    protected function tagIdeLocalAcid(\DOMElement &$cat)
469
    {
470
        $ideLocalAcid = $this->dom->createElement("ideLocalAcid");
471
        $this->dom->addChild(
472
            $ideLocalAcid,
473
            "tpInsc",
474
            $this->std->idelocalacid->tpinsc,
475
            true
476
        );
477
        $this->dom->addChild(
478
            $ideLocalAcid,
479
            "nrInsc",
480
            $this->std->idelocalacid->nrinsc,
481
            true
482
        );
483
        $cat->appendChild($ideLocalAcid);
484
    }
485
    
486
    /**
487
     * builder for version S.1.0.0
488
     */
489
    protected function toNodeS100()
490
    {
491
        throw new \Exception("TODO !!");
492
    }
493
}
494