Test Failed
Push — master ( 78dd3e...0fe426 )
by Roberto
04:43 queued 02:21
created

TraitS1070   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 342
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 26
lcom 1
cbo 0
dl 0
loc 342
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C toNode250() 0 166 13
C toNodeS100() 0 166 13
1
<?php
2
3
namespace NFePHP\eSocial\Factories\Traits;
4
5
trait TraitS1070
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
        $info = $this->dom->createElement("infoProcesso");
38
39
        //tag comum a todos os modos
40
        $ide = $this->dom->createElement("ideProcesso");
41
        $this->dom->addChild(
42
            $ide,
43
            "tpProc",
44
            $this->std->tpproc,
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...
45
            true
46
        );
47
        $this->dom->addChild(
48
            $ide,
49
            "nrProc",
50
            $this->std->nrproc,
51
            true
52
        );
53
        $this->dom->addChild(
54
            $ide,
55
            "iniValid",
56
            $this->std->inivalid,
57
            true
58
        );
59
        $this->dom->addChild(
60
            $ide,
61
            "fimValid",
62
            ! empty($this->std->fimvalid) ? $this->std->fimvalid : null,
63
            false
64
        );
65
        //seleção do modo
66
        if ($this->std->modo == 'INC') {
67
            $node = $this->dom->createElement("inclusao");
68
        } elseif ($this->std->modo == 'ALT') {
69
            $node = $this->dom->createElement("alteracao");
70
        } else {
71
            $node = $this->dom->createElement("exclusao");
72
        }
73
        $node->appendChild($ide);
74
75
        if ($this->std->modo != 'EXC') {
76
            $dados = $this->dom->createElement("dadosProc");
77
            $this->dom->addChild(
78
                $dados,
79
                "indAutoria",
80
                ! empty($this->std->dadosproc->indautoria)
81
                    ? $this->std->dadosproc->indautoria
82
                    : null,
83
                false
84
            );
85
            $this->dom->addChild(
86
                $dados,
87
                "indMatProc",
88
                $this->std->dadosproc->indmatproc,
89
                true
90
            );
91
            $this->dom->addChild(
92
                $dados,
93
                "observacao",
94
                !empty($this->std->dadosproc->observacao) ? $this->std->dadosproc->observacao : null,
95
                false
96
            );
97
            if (! empty($this->std->dadosproc->dadosprocjud)) {
98
                $dadosProcJud = $this->dom->createElement("dadosProcJud");
99
                $this->dom->addChild(
100
                    $dadosProcJud,
101
                    "ufVara",
102
                    $this->std->dadosproc->dadosprocjud->ufvara,
103
                    true
104
                );
105
                $this->dom->addChild(
106
                    $dadosProcJud,
107
                    "codMunic",
108
                    $this->std->dadosproc->dadosprocjud->codmunic,
109
                    true
110
                );
111
                $this->dom->addChild(
112
                    $dadosProcJud,
113
                    "idVara",
114
                    $this->std->dadosproc->dadosprocjud->idvara,
115
                    true
116
                );
117
                $dados->appendChild($dadosProcJud);
118
            }
119
            if (! empty($this->std->dadosproc->infosusp)) {
120
                foreach ($this->std->dadosproc->infosusp as $susp) {
121
                    $infoSusp = $this->dom->createElement("infoSusp");
122
                    $this->dom->addChild(
123
                        $infoSusp,
124
                        "codSusp",
125
                        $susp->codsusp,
126
                        true
127
                    );
128
                    $this->dom->addChild(
129
                        $infoSusp,
130
                        "indSusp",
131
                        $susp->indsusp,
132
                        true
133
                    );
134
                    $this->dom->addChild(
135
                        $infoSusp,
136
                        "dtDecisao",
137
                        $susp->dtdecisao,
138
                        true
139
                    );
140
                    $this->dom->addChild(
141
                        $infoSusp,
142
                        "indDeposito",
143
                        $susp->inddeposito,
144
                        true
145
                    );
146
                    $dados->appendChild($infoSusp);
147
                }
148
            }
149
            $node->appendChild($dados);
150
        }
151
        if (! empty($this->std->novavalidade) && $this->std->modo == 'ALT') {
152
            $newVal       = $this->std->novavalidade;
153
            $novaValidade = $this->dom->createElement("novaValidade");
154
            $this->dom->addChild(
155
                $ideRubrica,
0 ignored issues
show
Bug introduced by
The variable $ideRubrica does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
156
                "iniValid",
157
                $newVal->inivalid,
158
                true
159
            );
160
            $this->dom->addChild(
161
                $ideRubrica,
162
                "fimValid",
163
                ! empty($newVal->fimvalid) ? $newVal->fimvalid : null,
164
                false
165
            );
166
            $node->appendChild($novaValidade);
167
        }
168
169
        $info->appendChild($node);
170
        //finalização do xml
171
        $this->node->appendChild($info);
172
        $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...
173
        //$this->xml = $this->dom->saveXML($this->eSocial);
174
        $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...
175
    }
176
    
177
    /**
178
     * builder for version S.1.0.0
179
     */
180
    protected function toNodeS100()
181
    {
182
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
183
        //o idEvento pode variar de evento para evento
184
        //então cada factory individualmente terá de construir o seu
185
        $ideEvento = $this->dom->createElement("ideEvento");
186
        $this->dom->addChild(
187
            $ideEvento,
188
            "tpAmb",
189
            $this->tpAmb,
190
            true
191
        );
192
        $this->dom->addChild(
193
            $ideEvento,
194
            "procEmi",
195
            $this->procEmi,
196
            true
197
        );
198
        $this->dom->addChild(
199
            $ideEvento,
200
            "verProc",
201
            $this->verProc,
202
            true
203
        );
204
        $this->node->insertBefore($ideEvento, $ideEmpregador);
205
206
        //tag deste evento em particular
207
        $info = $this->dom->createElement("infoProcesso");
208
209
        //tag comum a todos os modos
210
        $ide = $this->dom->createElement("ideProcesso");
211
        $this->dom->addChild(
212
            $ide,
213
            "tpProc",
214
            $this->std->tpproc,
215
            true
216
        );
217
        $this->dom->addChild(
218
            $ide,
219
            "nrProc",
220
            $this->std->nrproc,
221
            true
222
        );
223
        $this->dom->addChild(
224
            $ide,
225
            "iniValid",
226
            $this->std->inivalid,
227
            true
228
        );
229
        $this->dom->addChild(
230
            $ide,
231
            "fimValid",
232
            ! empty($this->std->fimvalid) ? $this->std->fimvalid : null,
233
            false
234
        );
235
        //seleção do modo
236
        if ($this->std->modo == 'INC') {
237
            $node = $this->dom->createElement("inclusao");
238
        } elseif ($this->std->modo == 'ALT') {
239
            $node = $this->dom->createElement("alteracao");
240
        } else {
241
            $node = $this->dom->createElement("exclusao");
242
        }
243
        $node->appendChild($ide);
244
245
        if ($this->std->modo != 'EXC') {
246
            $dados = $this->dom->createElement("dadosProc");
247
            $this->dom->addChild(
248
                $dados,
249
                "indAutoria",
250
                !empty($this->std->dadosproc->indautoria)
251
                    ? $this->std->dadosproc->indautoria
252
                    : null,
253
                false
254
            );
255
            $this->dom->addChild(
256
                $dados,
257
                "indMatProc",
258
                $this->std->dadosproc->indmatproc,
259
                true
260
            );
261
            $this->dom->addChild(
262
                $dados,
263
                "observacao",
264
                !empty($this->std->dadosproc->observacao) ? $this->std->dadosproc->observacao : null,
265
                false
266
            );
267
            if (! empty($this->std->dadosproc->dadosprocjud)) {
268
                $dadosProcJud = $this->dom->createElement("dadosProcJud");
269
                $this->dom->addChild(
270
                    $dadosProcJud,
271
                    "ufVara",
272
                    $this->std->dadosproc->dadosprocjud->ufvara,
273
                    true
274
                );
275
                $this->dom->addChild(
276
                    $dadosProcJud,
277
                    "codMunic",
278
                    $this->std->dadosproc->dadosprocjud->codmunic,
279
                    true
280
                );
281
                $this->dom->addChild(
282
                    $dadosProcJud,
283
                    "idVara",
284
                    $this->std->dadosproc->dadosprocjud->idvara,
285
                    true
286
                );
287
                $dados->appendChild($dadosProcJud);
288
            }
289
            if (! empty($this->std->dadosproc->infosusp)) {
290
                foreach ($this->std->dadosproc->infosusp as $susp) {
291
                    $infoSusp = $this->dom->createElement("infoSusp");
292
                    $this->dom->addChild(
293
                        $infoSusp,
294
                        "codSusp",
295
                        $susp->codsusp,
296
                        true
297
                    );
298
                    $this->dom->addChild(
299
                        $infoSusp,
300
                        "indSusp",
301
                        $susp->indsusp,
302
                        true
303
                    );
304
                    $this->dom->addChild(
305
                        $infoSusp,
306
                        "dtDecisao",
307
                        $susp->dtdecisao,
308
                        true
309
                    );
310
                    $this->dom->addChild(
311
                        $infoSusp,
312
                        "indDeposito",
313
                        $susp->inddeposito,
314
                        true
315
                    );
316
                    $dados->appendChild($infoSusp);
317
                }
318
            }
319
            $node->appendChild($dados);
320
        }
321
        if (! empty($this->std->novavalidade) && $this->std->modo == 'ALT') {
322
            $newVal       = $this->std->novavalidade;
323
            $novaValidade = $this->dom->createElement("novaValidade");
324
            $this->dom->addChild(
325
                $ideRubrica,
0 ignored issues
show
Bug introduced by
The variable $ideRubrica does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
326
                "iniValid",
327
                $newVal->inivalid,
328
                true
329
            );
330
            $this->dom->addChild(
331
                $ideRubrica,
332
                "fimValid",
333
                ! empty($newVal->fimvalid) ? $newVal->fimvalid : null,
334
                false
335
            );
336
            $node->appendChild($novaValidade);
337
        }
338
339
        $info->appendChild($node);
340
        //finalização do xml
341
        $this->node->appendChild($info);
342
        $this->eSocial->appendChild($this->node);
343
        //$this->xml = $this->dom->saveXML($this->eSocial);
344
        $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...
345
    }
346
}
347