Completed
Push — master ( 2973a2...01fa63 )
by Roberto
04:58 queued 02:26
created

TraitS2399::toNode250()   F

Complexity

Conditions 27
Paths 10

Size

Total Lines 324

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 324
rs 3.3333
c 0
b 0
f 0
cc 27
nc 10
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 TraitS2399
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
        $ideTrabSemVinculo = $this->dom->createElement("ideTrabSemVinculo");
47
        $this->dom->addChild(
48
            $ideTrabSemVinculo,
49
            "cpfTrab",
50
            $this->std->cpftrab,
51
            true
52
        );
53
        $this->dom->addChild(
54
            $ideTrabSemVinculo,
55
            "nisTrab",
56
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
57
            false
58
        );
59
        $this->dom->addChild(
60
            $ideTrabSemVinculo,
61
            "codCateg",
62
            $this->std->codcateg,
63
            true
64
        );
65
        $this->node->appendChild($ideTrabSemVinculo);
66
        $infoTSVTermino = $this->dom->createElement("infoTSVTermino");
67
        $this->dom->addChild(
68
            $infoTSVTermino,
69
            "dtTerm",
70
            $this->std->dtterm,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $infoTSVTermino,
75
            "mtvDesligTSV",
76
            !empty($this->std->mtvdesligtsv) ? $this->std->mtvdesligtsv : null,
77
            false
78
        );
79
        $this->dom->addChild(
80
            $infoTSVTermino,
81
            "pensAlim",
82
            !empty($this->std->pensalim) ? $this->std->pensalim : null,
83
            false
84
        );
85
        $this->dom->addChild(
86
            $infoTSVTermino,
87
            "percAliment",
88
            !empty($this->std->percaliment) ? $this->std->percaliment : null,
89
            false
90
        );
91
        $this->dom->addChild(
92
            $infoTSVTermino,
93
            "vrAlim",
94
            !empty($this->std->vralim) ? $this->std->vralim : null,
95
            false
96
        );
97
        if (!empty($this->std->verbasresc)) {
98
            $vr = $this->std->verbasresc;
99
            $verbasResc = $this->dom->createElement("verbasResc");
100
            foreach ($vr->dmdev as $dv) {
101
                $dmDev = $this->dom->createElement("dmDev");
102
                $this->dom->addChild(
103
                    $dmDev,
104
                    "ideDmDev",
105
                    $dv->idedmdev,
106
                    true
107
                );
108
                foreach ($dv->ideestablot as $el) {
109
                    $ideEstabLot = $this->dom->createElement("ideEstabLot");
110
                    $this->dom->addChild(
111
                        $ideEstabLot,
112
                        "tpInsc",
113
                        $el->tpinsc,
114
                        true
115
                    );
116
                    $this->dom->addChild(
117
                        $ideEstabLot,
118
                        "nrInsc",
119
                        $el->nrinsc,
120
                        true
121
                    );
122
                    $this->dom->addChild(
123
                        $ideEstabLot,
124
                        "codLotacao",
125
                        $el->codlotacao,
126
                        true
127
                    );
128
                    foreach ($el->detverbas as $dever) {
129
                        $detVerbas = $this->dom->createElement("detVerbas");
130
                        $this->dom->addChild(
131
                            $detVerbas,
132
                            "codRubr",
133
                            $dever->codrubr,
134
                            true
135
                        );
136
                        $this->dom->addChild(
137
                            $detVerbas,
138
                            "ideTabRubr",
139
                            $dever->idetabrubr,
140
                            true
141
                        );
142
                        $this->dom->addChild(
143
                            $detVerbas,
144
                            "qtdRubr",
145
                            !empty($dever->qtdrubr) ? $dever->qtdrubr : null,
146
                            false
147
                        );
148
                        $this->dom->addChild(
149
                            $detVerbas,
150
                            "fatorRubr",
151
                            !empty($dever->fatorrubr) ? $dever->fatorrubr : null,
152
                            false
153
                        );
154
                        $this->dom->addChild(
155
                            $detVerbas,
156
                            "vrUnit",
157
                            !empty($dever->vrunit) ? $dever->vrunit : null,
158
                            false
159
                        );
160
                        $this->dom->addChild(
161
                            $detVerbas,
162
                            "vrRubr",
163
                            $dever->vrrubr,
164
                            true
165
                        );
166
                        $ideEstabLot->appendChild($detVerbas);
167
                    }
168
                    if (!empty($el->infosaudecolet)) {
169
                        $infoSaudeColet = $this->dom->createElement("infoSaudeColet");
170
                        foreach ($el->infosaudecolet->detoper as $dop) {
171
                            $detOper = $this->dom->createElement("detOper");
172
                            $this->dom->addChild(
173
                                $detOper,
174
                                "cnpjOper",
175
                                $dop->cnpjoper,
176
                                true
177
                            );
178
                            $this->dom->addChild(
179
                                $detOper,
180
                                "regANS",
181
                                $dop->regans,
182
                                true
183
                            );
184
                            $this->dom->addChild(
185
                                $detOper,
186
                                "vrPgTit",
187
                                $dop->vrpgtit,
188
                                true
189
                            );
190
                            if (!empty($dop->detplano)) {
191
                                foreach ($dop->detplano as $dpl) {
192
                                    $detPlano = $this->dom->createElement("detPlano");
193
                                    $this->dom->addChild(
194
                                        $detPlano,
195
                                        "tpDep",
196
                                        $dpl->tpdep,
197
                                        true
198
                                    );
199
                                    $this->dom->addChild(
200
                                        $detPlano,
201
                                        "cpfDep",
202
                                        !empty($dpl->cpfdep) ? $dpl->cpfdep : null,
203
                                        false
204
                                    );
205
                                    $this->dom->addChild(
206
                                        $detPlano,
207
                                        "nmDep",
208
                                        $dpl->nmdep,
209
                                        true
210
                                    );
211
                                    $this->dom->addChild(
212
                                        $detPlano,
213
                                        "dtNascto",
214
                                        $dpl->dtnascto,
215
                                        true
216
                                    );
217
                                    $this->dom->addChild(
218
                                        $detPlano,
219
                                        "vlrPgDep",
220
                                        $dpl->vlrpgdep,
221
                                        true
222
                                    );
223
                                    $detOper->appendChild($detPlano);
224
                                }
225
                            }
226
                            $infoSaudeColet->appendChild($detOper);
227
                        }
228
                        $ideEstabLot->appendChild($infoSaudeColet);
229
                    }
230
                    if (!empty($el->infoagnocivo)) {
231
                        $infoAgNocivo = $this->dom->createElement("infoAgNocivo");
232
                        $this->dom->addChild(
233
                            $infoAgNocivo,
234
                            "grauExp",
235
                            $el->infoagnocivo->grauexp,
236
                            true
237
                        );
238
                        $ideEstabLot->appendChild($infoAgNocivo);
239
                    }
240
                    if (!empty($el->infosimples)) {
241
                        $infoSimples = $this->dom->createElement("infoSimples");
242
                        $this->dom->addChild(
243
                            $infoSimples,
244
                            "indSimples",
245
                            $el->infosimples->indsimples,
246
                            true
247
                        );
248
                        $ideEstabLot->appendChild($infoSimples);
249
                    }
250
                    $dmDev->appendChild($ideEstabLot);
251
                }
252
                $verbasResc->appendChild($dmDev);
253
            }
254
255
            if (!empty($this->std->verbasresc->procjudtrab)) {
256
                foreach ($this->std->verbasresc->procjudtrab as $pj) {
257
                    $procJudTrab = $this->dom->createElement("procJudTrab");
258
                    $this->dom->addChild(
259
                        $procJudTrab,
260
                        "tpTrib",
261
                        $pj->tptrib,
262
                        true
263
                    );
264
                    $this->dom->addChild(
265
                        $procJudTrab,
266
                        "nrProcJud",
267
                        $pj->nrprocjud,
268
                        true
269
                    );
270
                    $this->dom->addChild(
271
                        $procJudTrab,
272
                        "codSusp",
273
                        !empty($pj->codsusp) ? $pj->codsusp : null,
274
                        false
275
                    );
276
                    $verbasResc->appendChild($procJudTrab);
277
                }
278
            }
279
            if (!empty($this->std->verbasresc->infomv)) {
280
                $infoMV = $this->dom->createElement("infoMV");
281
                $this->dom->addChild(
282
                    $infoMV,
283
                    "indMV",
284
                    $this->std->verbasresc->infomv->indmv,
285
                    true
286
                );
287
                foreach ($this->std->verbasresc->infomv->remunoutrempr as $rm) {
288
                    $remunOutrEmpr = $this->dom->createElement("remunOutrEmpr");
289
                    $this->dom->addChild(
290
                        $remunOutrEmpr,
291
                        "tpInsc",
292
                        $rm->tpinsc,
293
                        true
294
                    );
295
                    $this->dom->addChild(
296
                        $remunOutrEmpr,
297
                        "nrInsc",
298
                        $rm->nrinsc,
299
                        true
300
                    );
301
                    $this->dom->addChild(
302
                        $remunOutrEmpr,
303
                        "codCateg",
304
                        $rm->codcateg,
305
                        true
306
                    );
307
                    $this->dom->addChild(
308
                        $remunOutrEmpr,
309
                        "vlrRemunOE",
310
                        $rm->vlrremunoe,
311
                        true
312
                    );
313
                    $infoMV->appendChild($remunOutrEmpr);
314
                }
315
                $verbasResc->appendChild($infoMV);
316
            }
317
            $infoTSVTermino->appendChild($verbasResc);
318
        }
319
        if (!empty($this->std->quarentena)) {
320
            $quarentena = $this->dom->createElement("quarentena");
321
            $this->dom->addChild(
322
                $quarentena,
323
                "dtFimQuar",
324
                $this->std->quarentena->dtfimquar,
325
                true
326
            );
327
            $infoTSVTermino->appendChild($quarentena);
328
        }
329
        $this->node->appendChild($infoTSVTermino);
330
        $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...
331
        //$this->xml = $this->dom->saveXML($this->eSocial);
332
        $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...
333
    }
334
    
335
    /**
336
     * builder for version S.1.0.0
337
     */
338
    protected function toNodeS100()
339
    {
340
        throw new \Exception("TODO !!");
341
    }
342
}
343