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

TraitS2220   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 332
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 0
dl 0
loc 332
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
C toNode250() 0 194 12
B v020500() 0 123 7
A toNodeS100() 0 4 1
1
<?php
2
3
namespace NFePHP\eSocial\Factories\Traits;
4
5
trait TraitS2220
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
            "indRetif",
19
            $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...
20
            true
21
        );
22
        $this->dom->addChild(
23
            $ideEvento,
24
            "tpAmb",
25
            $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...
26
            true
27
        );
28
        $this->dom->addChild(
29
            $ideEvento,
30
            "procEmi",
31
            $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...
32
            true
33
        );
34
        $this->dom->addChild(
35
            $ideEvento,
36
            "verProc",
37
            $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...
38
            true
39
        );
40
        $this->node->insertBefore($ideEvento, $ideEmpregador);
41
        $ideVinculo = $this->dom->createElement("ideVinculo");
42
        $this->dom->addChild(
43
            $ideVinculo,
44
            "cpfTrab",
45
            $this->std->idevinculo->cpftrab,
46
            true
47
        );
48
        $this->dom->addChild(
49
            $ideVinculo,
50
            "nisTrab",
51
            $this->std->idevinculo->nistrab,
52
            true
53
        );
54
        $this->dom->addChild(
55
            $ideVinculo,
56
            "matricula",
57
            !empty($this->std->idevinculo->matricula) ? $this->std->idevinculo->matricula : null,
58
            false
59
        );
60
        $this->node->appendChild($ideVinculo);
61
62
        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...
63
            $aso = $this->dom->createElement("aso");
64
            $this->dom->addChild(
65
                $aso,
66
                "dtAso",
67
                $this->std->aso->dtaso,
68
                true
69
            );
70
            $this->dom->addChild(
71
                $aso,
72
                "resAso",
73
                $this->std->aso->resaso,
74
                true
75
            );
76
            if (isset($this->std->aso->exame)) {
77
                foreach ($this->std->aso->exame as $exa) {
78
                    $exame = $this->dom->createElement("exame");
79
                    $this->dom->addChild(
80
                        $exame,
81
                        "dtExm",
82
                        $exa->dtexm,
83
                        true
84
                    );
85
                    $this->dom->addChild(
86
                        $exame,
87
                        "procRealizado",
88
                        !empty($exa->procrealizado) ? $exa->procrealizado : null,
89
                        false
90
                    );
91
                    $this->dom->addChild(
92
                        $exame,
93
                        "obsProc",
94
                        !empty($exa->obsproc) ? $exa->obsproc : null,
95
                        false
96
                    );
97
                    $this->dom->addChild(
98
                        $exame,
99
                        "interprExm",
100
                        $exa->interprexm,
101
                        true
102
                    );
103
                    $this->dom->addChild(
104
                        $exame,
105
                        "ordExame",
106
                        $exa->ordexame,
107
                        true
108
                    );
109
                    $this->dom->addChild(
110
                        $exame,
111
                        "dtIniMonit",
112
                        $exa->dtinimonit,
113
                        true
114
                    );
115
                    $this->dom->addChild(
116
                        $exame,
117
                        "dtFimMonit",
118
                        !empty($exa->dtfimmonit) ? $exa->dtfimmonit : null,
119
                        false
120
                    );
121
                    $this->dom->addChild(
122
                        $exame,
123
                        "indResult",
124
                        !empty($exa->indresult) ? $exa->indresult : null,
125
                        false
126
                    );
127
                    $respMonit = $this->dom->createElement("respMonit");
128
                    $resm = $exa->respmonit;
129
                    $this->dom->addChild(
130
                        $respMonit,
131
                        "nisResp",
132
                        $resm->nisresp,
133
                        true
134
                    );
135
                    $this->dom->addChild(
136
                        $respMonit,
137
                        "nrConsClasse",
138
                        $resm->nrconsclasse,
139
                        true
140
                    );
141
                    $this->dom->addChild(
142
                        $respMonit,
143
                        "ufConsClasse",
144
                        !empty($resm->ufconsclasse) ? $resm->ufconsclasse : null,
145
                        false
146
                    );
147
                    $exame->appendChild($respMonit);
148
                    $aso->appendChild($exame);
149
                }
150
            }
151
            $ideServSaude = $this->dom->createElement("ideServSaude");
152
            $sers = $this->std->aso->ideservsaude;
153
            $this->dom->addChild(
154
                $ideServSaude,
155
                "codCNES",
156
                !empty($sers->codcnes) ? $sers->codcnes : null,
157
                false
158
            );
159
            $this->dom->addChild(
160
                $ideServSaude,
161
                "frmCtt",
162
                $sers->frmctt,
163
                true
164
            );
165
            $this->dom->addChild(
166
                $ideServSaude,
167
                "email",
168
                !empty($sers->email) ? $sers->email : null,
169
                false
170
            );
171
            $medico = $this->dom->createElement("medico");
172
            $med = $sers->medico;
173
            $this->dom->addChild(
174
                $medico,
175
                "nmMed",
176
                $med->nmmed,
177
                true
178
            );
179
            $crm = $this->dom->createElement("crm");
180
            $this->dom->addChild(
181
                $crm,
182
                "nrCRM",
183
                $med->nrcrm,
184
                true
185
            );
186
            $this->dom->addChild(
187
                $crm,
188
                "ufCRM",
189
                $med->ufcrm,
190
                true
191
            );
192
            $medico->appendChild($crm);
193
            $ideServSaude->appendChild($medico);
194
            $aso->appendChild($ideServSaude);
195
            $this->node->appendChild($aso);
196
        } else {
197
            $this->v020500();
198
        }
199
        //finalização do xml
200
        $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...
201
        //$this->xml = $this->dom->saveXML($this->eSocial);
202
        $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...
203
    }
204
205
    protected function v020500()
206
    {
207
        $exMedOcup = $this->dom->createElement("exMedOcup");
208
        $this->dom->addChild(
209
            $exMedOcup,
210
            "tpExameOcup",
211
            $this->std->exmedocup->tpexameocup,
212
            true
213
        );
214
        $stdaso = $this->std->exmedocup->aso;
215
        $aso = $this->dom->createElement("aso");
216
        $this->dom->addChild(
217
            $aso,
218
            "dtAso",
219
            $stdaso->dtaso,
220
            true
221
        );
222
        $this->dom->addChild(
223
            $aso,
224
            "resAso",
225
            $stdaso->resaso,
226
            true
227
        );
228
229
        foreach ($this->std->exmedocup->aso->exame as $exa) {
230
            $exame = $this->dom->createElement("exame");
231
            $this->dom->addChild(
232
                $exame,
233
                "dtExm",
234
                $exa->dtexm,
235
                true
236
            );
237
            $this->dom->addChild(
238
                $exame,
239
                "procRealizado",
240
                $exa->procrealizado,
241
                true
242
            );
243
            $this->dom->addChild(
244
                $exame,
245
                "obsProc",
246
                !empty($exa->obsproc) ? $exa->obsproc : null,
247
                false
248
            );
249
            $this->dom->addChild(
250
                $exame,
251
                "ordExame",
252
                $exa->ordexame,
253
                true
254
            );
255
            $this->dom->addChild(
256
                $exame,
257
                "indResult",
258
                !empty($exa->indresult) ? $exa->indresult : null,
259
                false
260
            );
261
            $aso->appendChild($exame);
262
        }
263
264
        $stdmed = $this->std->exmedocup->aso->medico;
265
        $medico = $this->dom->createElement("medico");
266
        $this->dom->addChild(
267
            $medico,
268
            "cpfMed",
269
            !empty($stdmed->cpfmed) ? $stdmed->cpfmed : null,
270
            false
271
        );
272
        $this->dom->addChild(
273
            $medico,
274
            "nisMed",
275
            !empty($stdmed->nismed) ? $stdmed->nismed : null,
276
            false
277
        );
278
        $this->dom->addChild(
279
            $medico,
280
            "nmMed",
281
            $stdmed->nmmed,
282
            true
283
        );
284
        $this->dom->addChild(
285
            $medico,
286
            "nrCRM",
287
            $stdmed->nrcrm,
288
            true
289
        );
290
        $this->dom->addChild(
291
            $medico,
292
            "ufCRM",
293
            $stdmed->ufcrm,
294
            true
295
        );
296
        $aso->appendChild($medico);
297
        $exMedOcup->appendChild($aso);
298
299
        $stdmon = $this->std->exmedocup->respmonit;
300
        $monit = $this->dom->createElement("respMonit");
301
        $this->dom->addChild(
302
            $monit,
303
            "cpfResp",
304
            !empty($stdmon->cpfresp) ? $stdmon->cpfresp : null,
305
            false
306
        );
307
        $this->dom->addChild(
308
            $monit,
309
            "nmResp",
310
            $stdmon->nmresp,
311
            true
312
        );
313
        $this->dom->addChild(
314
            $monit,
315
            "nrCRM",
316
            $stdmon->nrcrm,
317
            true
318
        );
319
        $this->dom->addChild(
320
            $monit,
321
            "ufCRM",
322
            $stdmon->ufcrm,
323
            true
324
        );
325
        $exMedOcup->appendChild($monit);
326
        $this->node->appendChild($exMedOcup);
327
    }
328
    
329
    /**
330
     * builder for version S.1.0.0
331
     */
332
    protected function toNodeS100()
333
    {
334
        throw new \Exception("TODO !!");
335
    }
336
}
337