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

TraitS2230::toNode250()   F

Complexity

Conditions 18
Paths 36

Size

Total Lines 214

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 214
rs 3.8933
c 0
b 0
f 0
cc 18
nc 36
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 TraitS2230
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
            "nrRecibo",
25
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
26
            false
27
        );
28
        $this->dom->addChild(
29
            $ideEvento,
30
            "tpAmb",
31
            $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...
32
            true
33
        );
34
        $this->dom->addChild(
35
            $ideEvento,
36
            "procEmi",
37
            $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...
38
            true
39
        );
40
        $this->dom->addChild(
41
            $ideEvento,
42
            "verProc",
43
            $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...
44
            true
45
        );
46
        $this->node->insertBefore($ideEvento, $ideEmpregador);
47
        $ideVinculo = $this->dom->createElement("ideVinculo");
48
        $this->dom->addChild(
49
            $ideVinculo,
50
            "cpfTrab",
51
            $this->std->idevinculo->cpftrab,
52
            true
53
        );
54
        $this->dom->addChild(
55
            $ideVinculo,
56
            "nisTrab",
57
            $this->std->idevinculo->nistrab,
58
            true
59
        );
60
        $this->dom->addChild(
61
            $ideVinculo,
62
            "matricula",
63
            !empty($this->std->idevinculo->matricula) ? $this->std->idevinculo->matricula : null,
64
            false
65
        );
66
        $this->dom->addChild(
67
            $ideVinculo,
68
            "codCateg",
69
            !empty($this->std->idevinculo->codcateg) ? $this->std->idevinculo->codcateg : null,
70
            false
71
        );
72
        $this->node->appendChild($ideVinculo);
73
        $infoAfastamento = $this->dom->createElement("infoAfastamento");
74
        if (! empty($this->std->iniafastamento)) {
75
            $iniAfastamento = $this->dom->createElement("iniAfastamento");
76
            $this->dom->addChild(
77
                $iniAfastamento,
78
                "dtIniAfast",
79
                $this->std->iniafastamento->dtiniafast,
80
                true
81
            );
82
            $this->dom->addChild(
83
                $iniAfastamento,
84
                "codMotAfast",
85
                $this->std->iniafastamento->codmotafast,
86
                true
87
            );
88
            $this->dom->addChild(
89
                $iniAfastamento,
90
                "infoMesmoMtv",
91
                ! empty($this->std->iniafastamento->infomesmomtv) ? $this->std->iniafastamento->infomesmomtv : null,
92
                false
93
            );
94
            $this->dom->addChild(
95
                $iniAfastamento,
96
                "tpAcidTransito",
97
                ! empty($this->std->iniafastamento->tpacidtransito) ? $this->std->iniafastamento->tpacidtransito : null,
98
                false
99
            );
100
            $this->dom->addChild(
101
                $iniAfastamento,
102
                "observacao",
103
                ! empty($this->std->iniafastamento->observacao) ? $this->std->iniafastamento->observacao : null,
104
                false
105
            );
106
            if (isset($this->std->iniafastamento->infoatestado)) {
107
                foreach ($this->std->iniafastamento->infoatestado as $info) {
108
                    $infoAtestado = $this->dom->createElement("infoAtestado");
109
                    $this->dom->addChild(
110
                        $infoAtestado,
111
                        "codCID",
112
                        ! empty($info->codcid) ? $info->codcid : null,
113
                        false
114
                    );
115
                    $this->dom->addChild(
116
                        $infoAtestado,
117
                        "qtdDiasAfast",
118
                        $info->qtddiasafast,
119
                        true
120
                    );
121
                    if (isset($info->emitente)) {
122
                        $emitente = $this->dom->createElement("emitente");
123
124
                        $this->dom->addChild(
125
                            $emitente,
126
                            "nmEmit",
127
                            $info->emitente->nmemit,
128
                            true
129
                        );
130
                        $this->dom->addChild(
131
                            $emitente,
132
                            "ideOC",
133
                            $info->emitente->ideoc,
134
                            true
135
                        );
136
                        $this->dom->addChild(
137
                            $emitente,
138
                            "nrOc",
139
                            $info->emitente->nroc,
140
                            true
141
                        );
142
                        $this->dom->addChild(
143
                            $emitente,
144
                            "ufOC",
145
                            ! empty($info->emitente->ufoc) ? $info->emitente->ufoc : null,
146
                            false
147
                        );
148
                        $infoAtestado->appendChild($emitente);
149
                    }
150
                    $iniAfastamento->appendChild($infoAtestado);
151
                }
152
            }
153
            if (! empty($this->std->infocessao)) {
154
                $infoCessao = $this->dom->createElement("infoCessao");
155
                $this->dom->addChild(
156
                    $infoCessao,
157
                    "cnpjCess",
158
                    $this->std->infocessao->cnpjcess,
159
                    true
160
                );
161
                $this->dom->addChild(
162
                    $infoCessao,
163
                    "infOnus",
164
                    $this->std->infocessao->infonus,
165
                    true
166
                );
167
                $iniAfastamento->appendChild($infoCessao);
168
            }
169
            if (! empty($this->std->infomandsind)) {
170
                $infoMandSind = $this->dom->createElement("infoMandSind");
171
                $this->dom->addChild(
172
                    $infoMandSind,
173
                    "cnpjSind",
174
                    $this->std->infomandsind->cnpjsind,
175
                    true
176
                );
177
                $this->dom->addChild(
178
                    $infoMandSind,
179
                    "infOnusRemun",
180
                    $this->std->infomandsind->infonusremun,
181
                    true
182
                );
183
                $iniAfastamento->appendChild($infoMandSind);
184
            }
185
            $infoAfastamento->appendChild($iniAfastamento);
186
        }
187
        if (! empty($this->std->inforetif)) {
188
            $infoRetif = $this->dom->createElement("infoRetif");
189
            $this->dom->addChild(
190
                $infoRetif,
191
                "origRetif",
192
                $this->std->inforetif->origretif,
193
                true
194
            );
195
            $this->dom->addChild(
196
                $infoRetif,
197
                "tpProc",
198
                $this->std->inforetif->tpproc,
199
                true
200
            );
201
            $this->dom->addChild(
202
                $infoRetif,
203
                "nrProc",
204
                ! empty($this->std->inforetif->nrproc) ? $this->std->inforetif->nrproc : null,
205
                false
206
            );
207
            $infoAfastamento->appendChild($infoRetif);
208
        }
209
        if (! empty($this->std->fimafastamento)) {
210
            $fimAfastamento = $this->dom->createElement("fimAfastamento");
211
            $this->dom->addChild(
212
                $fimAfastamento,
213
                "dtTermAfast",
214
                $this->std->fimafastamento->dttermafast,
215
                true
216
            );
217
            $infoAfastamento->appendChild($fimAfastamento);
218
        }
219
        $this->node->appendChild($infoAfastamento);
220
        $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...
221
        //$this->xml = $this->dom->saveXML($this->eSocial);
222
        $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...
223
    }
224
    
225
    /**
226
     * builder for version S.1.0.0
227
     */
228
    protected function toNodeS100()
229
    {
230
        throw new \Exception("TODO !!");
231
    }
232
}
233