Test Failed
Push — master ( 63d89e...78dd3e )
by Roberto
03:02 queued 13s
created

TraitS1010::toNode250()   F

Complexity

Conditions 18
Paths 102

Size

Total Lines 217

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 217
rs 3.88
c 0
b 0
f 0
cc 18
nc 102
nop 0

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\Traits;
4
5
trait TraitS1010
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
        //o idEvento pode variar de evento para evento
14
        //então cada factory individualmente terá de construir o seu
15
        $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...
16
        $this->dom->addChild(
17
            $ideEvento,
18
            "tpAmb",
19
            $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...
20
            true
21
        );
22
        $this->dom->addChild(
23
            $ideEvento,
24
            "procEmi",
25
            $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...
26
            true
27
        );
28
        $this->dom->addChild(
29
            $ideEvento,
30
            "verProc",
31
            $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...
32
            true
33
        );
34
        $this->node->insertBefore($ideEvento, $ideEmpregador);
35
36
        //tag deste evento em particular
37
        $infoRubrica = $this->dom->createElement("infoRubrica");
38
        //tag comum a todos os modos
39
        $ideRubrica = $this->dom->createElement("ideRubrica");
40
        $this->dom->addChild(
41
            $ideRubrica,
42
            "codRubr",
43
            $this->std->codrubr,
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...
44
            true
45
        );
46
        $this->dom->addChild(
47
            $ideRubrica,
48
            "ideTabRubr",
49
            $this->std->idetabrubr,
50
            true
51
        );
52
        $this->dom->addChild(
53
            $ideRubrica,
54
            "iniValid",
55
            $this->std->inivalid,
56
            true
57
        );
58
        $this->dom->addChild(
59
            $ideRubrica,
60
            "fimValid",
61
            ! empty($this->std->fimvalid) ? $this->std->fimvalid : null,
62
            false
63
        );
64
        //seleção do modo
65
        if ($this->std->modo == 'INC') {
66
            $node = $this->dom->createElement("inclusao");
67
        } elseif ($this->std->modo == 'ALT') {
68
            $node = $this->dom->createElement("alteracao");
69
        } else {
70
            $node = $this->dom->createElement("exclusao");
71
        }
72
        $node->appendChild($ideRubrica);
73
74
        if (!empty($this->std->dadosrubrica) && $this->std->modo != 'EXC') {
75
            $dadosRubrica = $this->dom->createElement("dadosRubrica");
76
            $this->dom->addChild(
77
                $dadosRubrica,
78
                "dscRubr",
79
                $this->std->dadosrubrica->dscrubr,
80
                true
81
            );
82
            $this->dom->addChild(
83
                $dadosRubrica,
84
                "natRubr",
85
                $this->std->dadosrubrica->natrubr,
86
                true
87
            );
88
            $this->dom->addChild(
89
                $dadosRubrica,
90
                "tpRubr",
91
                $this->std->dadosrubrica->tprubr,
92
                true
93
            );
94
            $this->dom->addChild(
95
                $dadosRubrica,
96
                "codIncCP",
97
                $this->std->dadosrubrica->codinccp,
98
                true
99
            );
100
            $this->dom->addChild(
101
                $dadosRubrica,
102
                "codIncIRRF",
103
                $this->std->dadosrubrica->codincirrf,
104
                true
105
            );
106
            $this->dom->addChild(
107
                $dadosRubrica,
108
                "codIncFGTS",
109
                $this->std->dadosrubrica->codincfgts,
110
                true
111
            );
112
            $this->dom->addChild(
113
                $dadosRubrica,
114
                "codIncSIND",
115
                $this->std->dadosrubrica->codincsind,
116
                true
117
            );
118
            $this->dom->addChild(
119
                $dadosRubrica,
120
                "observacao",
121
                ! empty($this->std->dadosrubrica->observacao)
122
                    ? $this->std->dadosrubrica->observacao
123
                    : null,
124
                false
125
            );
126
127
            if (! empty($this->std->dadosrubrica->ideprocessocp)) {
128
                foreach ($this->std->dadosrubrica->ideprocessocp as $cp) {
129
                    $ideProcessoCP = $this->dom->createElement("ideProcessoCP");
130
                    $this->dom->addChild(
131
                        $ideProcessoCP,
132
                        "tpProc",
133
                        $cp->tpproc,
134
                        true
135
                    );
136
                    $this->dom->addChild(
137
                        $ideProcessoCP,
138
                        "nrProc",
139
                        $cp->nrproc,
140
                        true
141
                    );
142
                    $this->dom->addChild(
143
                        $ideProcessoCP,
144
                        "extDecisao",
145
                        $cp->extdecisao,
146
                        true
147
                    );
148
                    $this->dom->addChild(
149
                        $ideProcessoCP,
150
                        "codSusp",
151
                        $cp->codsusp,
152
                        true
153
                    );
154
                    $dadosRubrica->appendChild($ideProcessoCP);
155
                }
156
            }
157
158
            if (! empty($this->std->dadosrubrica->ideprocessoirrf)) {
159
                foreach ($this->std->dadosrubrica->ideprocessoirrf as $irrf) {
160
                    $ideProcessoIRRF = $this->dom->createElement("ideProcessoIRRF");
161
                    $this->dom->addChild(
162
                        $ideProcessoIRRF,
163
                        "nrProc",
164
                        $irrf->nrproc,
165
                        true
166
                    );
167
                    $this->dom->addChild(
168
                        $ideProcessoIRRF,
169
                        "codSusp",
170
                        $irrf->codsusp,
171
                        true
172
                    );
173
                    $dadosRubrica->appendChild($ideProcessoIRRF);
174
                }
175
            }
176
            if (! empty($this->std->dadosrubrica->ideprocessofgts)) {
177
                foreach ($this->std->dadosrubrica->ideprocessofgts as $fgts) {
178
                    $ideProcessoFGTS = $this->dom->createElement("ideProcessoFGTS");
179
                    $this->dom->addChild(
180
                        $ideProcessoFGTS,
181
                        "nrProc",
182
                        $fgts->nrproc,
183
                        true
184
                    );
185
                    $dadosRubrica->appendChild($ideProcessoFGTS);
186
                }
187
            }
188
            if (! empty($this->std->dadosrubrica->ideprocessosind)) {
189
                foreach ($this->std->dadosrubrica->ideprocessosind as $sind) {
190
                    $ideProcessoSIND = $this->dom->createElement("ideProcessoSIND");
191
                    $this->dom->addChild(
192
                        $ideProcessoSIND,
193
                        "nrProc",
194
                        $sind->nrproc,
195
                        true
196
                    );
197
                    $dadosRubrica->appendChild($ideProcessoSIND);
198
                }
199
            }
200
            $node->appendChild($dadosRubrica);
201
        }
202
        if (! empty($this->std->novavalidade) && $this->std->modo == 'ALT') {
203
            $newVal = $this->std->novavalidade;
204
            $novaValidade = $this->dom->createElement("novaValidade");
205
            $this->dom->addChild(
206
                $novaValidade,
207
                "iniValid",
208
                $newVal->inivalid,
209
                true
210
            );
211
            $this->dom->addChild(
212
                $novaValidade,
213
                "fimValid",
214
                ! empty($newVal->fimvalid) ? $newVal->fimvalid : null,
215
                false
216
            );
217
            $node->appendChild($novaValidade);
218
        }
219
220
        //finalização do xml
221
        $infoRubrica->appendChild($node);
222
        $this->node->appendChild($infoRubrica);
223
        $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...
224
        //$this->xml = $this->dom->saveXML($this->eSocial);
225
        $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...
226
    }
227
    
228
    /**
229
     * builder for version S.1.0.0
230
     */
231
    protected function toNodeS100()
232
    {
233
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
234
        //o idEvento pode variar de evento para evento
235
        //então cada factory individualmente terá de construir o seu
236
        $ideEvento = $this->dom->createElement("ideEvento");
237
        $this->dom->addChild(
238
            $ideEvento,
239
            "tpAmb",
240
            $this->tpAmb,
241
            true
242
        );
243
        $this->dom->addChild(
244
            $ideEvento,
245
            "procEmi",
246
            $this->procEmi,
247
            true
248
        );
249
        $this->dom->addChild(
250
            $ideEvento,
251
            "verProc",
252
            $this->verProc,
253
            true
254
        );
255
        $this->node->insertBefore($ideEvento, $ideEmpregador);
256
257
        //tag deste evento em particular
258
        $infoRubrica = $this->dom->createElement("infoRubrica");
259
        //tag comum a todos os modos
260
        $ideRubrica = $this->dom->createElement("ideRubrica");
261
        $this->dom->addChild(
262
            $ideRubrica,
263
            "codRubr",
264
            $this->std->codrubr,
265
            true
266
        );
267
        $this->dom->addChild(
268
            $ideRubrica,
269
            "ideTabRubr",
270
            $this->std->idetabrubr,
271
            true
272
        );
273
        $this->dom->addChild(
274
            $ideRubrica,
275
            "iniValid",
276
            $this->std->inivalid,
277
            true
278
        );
279
        $this->dom->addChild(
280
            $ideRubrica,
281
            "fimValid",
282
            ! empty($this->std->fimvalid) ? $this->std->fimvalid : null,
283
            false
284
        );
285
        //seleção do modo
286
        if ($this->std->modo == 'INC') {
287
            $node = $this->dom->createElement("inclusao");
288
        } elseif ($this->std->modo == 'ALT') {
289
            $node = $this->dom->createElement("alteracao");
290
        } else {
291
            $node = $this->dom->createElement("exclusao");
292
        }
293
        $node->appendChild($ideRubrica);
294
295
        if (!empty($this->std->dadosrubrica) && $this->std->modo != 'EXC') {
296
            $dadosRubrica = $this->dom->createElement("dadosRubrica");
297
            $this->dom->addChild(
298
                $dadosRubrica,
299
                "dscRubr",
300
                $this->std->dadosrubrica->dscrubr,
301
                true
302
            );
303
            $this->dom->addChild(
304
                $dadosRubrica,
305
                "natRubr",
306
                $this->std->dadosrubrica->natrubr,
307
                true
308
            );
309
            $this->dom->addChild(
310
                $dadosRubrica,
311
                "tpRubr",
312
                $this->std->dadosrubrica->tprubr,
313
                true
314
            );
315
            $this->dom->addChild(
316
                $dadosRubrica,
317
                "codIncCP",
318
                $this->std->dadosrubrica->codinccp,
319
                true
320
            );
321
            $this->dom->addChild(
322
                $dadosRubrica,
323
                "codIncIRRF",
324
                $this->std->dadosrubrica->codincirrf,
325
                true
326
            );
327
            $this->dom->addChild(
328
                $dadosRubrica,
329
                "codIncFGTS",
330
                $this->std->dadosrubrica->codincfgts,
331
                true
332
            );
333
            $this->dom->addChild(
334
                $dadosRubrica,
335
                "observacao",
336
                ! empty($this->std->dadosrubrica->observacao)
337
                    ? $this->std->dadosrubrica->observacao
338
                    : null,
339
                false
340
            );
341
342
            if (! empty($this->std->dadosrubrica->ideprocessocp)) {
343
                foreach ($this->std->dadosrubrica->ideprocessocp as $cp) {
344
                    $ideProcessoCP = $this->dom->createElement("ideProcessoCP");
345
                    $this->dom->addChild(
346
                        $ideProcessoCP,
347
                        "tpProc",
348
                        $cp->tpproc,
349
                        true
350
                    );
351
                    $this->dom->addChild(
352
                        $ideProcessoCP,
353
                        "nrProc",
354
                        $cp->nrproc,
355
                        true
356
                    );
357
                    $this->dom->addChild(
358
                        $ideProcessoCP,
359
                        "extDecisao",
360
                        $cp->extdecisao,
361
                        true
362
                    );
363
                    $this->dom->addChild(
364
                        $ideProcessoCP,
365
                        "codSusp",
366
                        $cp->codsusp,
367
                        true
368
                    );
369
                    $dadosRubrica->appendChild($ideProcessoCP);
370
                }
371
            }
372
373
            if (! empty($this->std->dadosrubrica->ideprocessoirrf)) {
374
                foreach ($this->std->dadosrubrica->ideprocessoirrf as $irrf) {
375
                    $ideProcessoIRRF = $this->dom->createElement("ideProcessoIRRF");
376
                    $this->dom->addChild(
377
                        $ideProcessoIRRF,
378
                        "nrProc",
379
                        $irrf->nrproc,
380
                        true
381
                    );
382
                    $this->dom->addChild(
383
                        $ideProcessoIRRF,
384
                        "codSusp",
385
                        $irrf->codsusp,
386
                        true
387
                    );
388
                    $dadosRubrica->appendChild($ideProcessoIRRF);
389
                }
390
            }
391
            if (! empty($this->std->dadosrubrica->ideprocessofgts)) {
392
                foreach ($this->std->dadosrubrica->ideprocessofgts as $fgts) {
393
                    $ideProcessoFGTS = $this->dom->createElement("ideProcessoFGTS");
394
                    $this->dom->addChild(
395
                        $ideProcessoFGTS,
396
                        "nrProc",
397
                        $fgts->nrproc,
398
                        true
399
                    );
400
                    $dadosRubrica->appendChild($ideProcessoFGTS);
401
                }
402
            }
403
            if (! empty($this->std->dadosrubrica->ideprocessosind)) {
404
                foreach ($this->std->dadosrubrica->ideprocessosind as $sind) {
405
                    $ideProcessoSIND = $this->dom->createElement("ideProcessoSIND");
406
                    $this->dom->addChild(
407
                        $ideProcessoSIND,
408
                        "nrProc",
409
                        $sind->nrproc,
410
                        true
411
                    );
412
                    $dadosRubrica->appendChild($ideProcessoSIND);
413
                }
414
            }
415
            $node->appendChild($dadosRubrica);
416
        }
417
        if (! empty($this->std->novavalidade) && $this->std->modo == 'ALT') {
418
            $newVal = $this->std->novavalidade;
419
            $novaValidade = $this->dom->createElement("novaValidade");
420
            $this->dom->addChild(
421
                $novaValidade,
422
                "iniValid",
423
                $newVal->inivalid,
424
                true
425
            );
426
            $this->dom->addChild(
427
                $novaValidade,
428
                "fimValid",
429
                ! empty($newVal->fimvalid) ? $newVal->fimvalid : null,
430
                false
431
            );
432
            $node->appendChild($novaValidade);
433
        }
434
435
        //finalização do xml
436
        $infoRubrica->appendChild($node);
437
        $this->node->appendChild($infoRubrica);
438
        $this->eSocial->appendChild($this->node);
439
        //$this->xml = $this->dom->saveXML($this->eSocial);
440
        $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...
441
    }
442
}
443