Test Failed
Push — master ( 0fe426...8c51ed )
by Roberto
05:10 queued 11s
created

TraitS3000::toNodeS100()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 8.6545
c 0
b 0
f 0
cc 3
nc 4
nop 0

How to fix   Long Method   

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 TraitS3000
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
        $infoExclusao = $this->dom->createElement("infoExclusao");
37
        $this->dom->addChild(
38
            $infoExclusao,
39
            "tpEvento",
40
            $this->std->infoexclusao->tpevento,
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...
41
            true
42
        );
43
        $this->dom->addChild(
44
            $infoExclusao,
45
            "nrRecEvt",
46
            $this->std->infoexclusao->nrrecevt,
47
            true
48
        );
49
        if (!empty($this->std->idetrabalhador)) {
50
            $ideTrabalhador = $this->dom->createElement("ideTrabalhador");
51
            $this->dom->addChild(
52
                $ideTrabalhador,
53
                "cpfTrab",
54
                $this->std->idetrabalhador->cpftrab,
55
                true
56
            );
57
            $this->dom->addChild(
58
                $ideTrabalhador,
59
                "nisTrab",
60
                !empty($this->std->idetrabalhador->nistrab) ? $this->std->idetrabalhador->nistrab : null,
61
                false
62
            );
63
            $infoExclusao->appendChild($ideTrabalhador);
64
        }
65
        if (!empty($this->std->idefolhapagto)) {
66
            $ideFolhaPagto = $this->dom->createElement("ideFolhaPagto");
67
            $this->dom->addChild(
68
                $ideFolhaPagto,
69
                "indApuracao",
70
                $this->std->idefolhapagto->indapuracao,
71
                true
72
            );
73
            $this->dom->addChild(
74
                $ideFolhaPagto,
75
                "perApur",
76
                $this->std->idefolhapagto->perapur,
77
                true
78
            );
79
            $infoExclusao->appendChild($ideFolhaPagto);
80
        }
81
        $this->node->appendChild($infoExclusao);
82
        $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...
83
        //$this->xml = $this->dom->saveXML($this->eSocial);
84
        $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...
85
    }
86
    
87
    /**
88
     * builder for version S.1.0.0
89
     */
90
    protected function toNodeS100()
91
    {
92
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
93
        //o idEvento pode variar de evento para evento
94
        //então cada factory individualmente terá de construir o seu
95
        $ideEvento = $this->dom->createElement("ideEvento");
96
        $this->dom->addChild(
97
            $ideEvento,
98
            "tpAmb",
99
            $this->tpAmb,
100
            true
101
        );
102
        $this->dom->addChild(
103
            $ideEvento,
104
            "procEmi",
105
            $this->procEmi,
106
            true
107
        );
108
        $this->dom->addChild(
109
            $ideEvento,
110
            "verProc",
111
            $this->verProc,
112
            true
113
        );
114
        $this->node->insertBefore($ideEvento, $ideEmpregador);
115
116
        $infoExclusao = $this->dom->createElement("infoExclusao");
117
        $this->dom->addChild(
118
            $infoExclusao,
119
            "tpEvento",
120
            $this->std->infoexclusao->tpevento,
121
            true
122
        );
123
        $this->dom->addChild(
124
            $infoExclusao,
125
            "nrRecEvt",
126
            $this->std->infoexclusao->nrrecevt,
127
            true
128
        );
129
        if (!empty($this->std->idetrabalhador)) {
130
            $ideTrabalhador = $this->dom->createElement("ideTrabalhador");
131
            $this->dom->addChild(
132
                $ideTrabalhador,
133
                "cpfTrab",
134
                $this->std->idetrabalhador->cpftrab,
135
                true
136
            );
137
            $infoExclusao->appendChild($ideTrabalhador);
138
        }
139
        if (!empty($this->std->idefolhapagto)) {
140
            $ideFolhaPagto = $this->dom->createElement("ideFolhaPagto");
141
            $this->dom->addChild(
142
                $ideFolhaPagto,
143
                "indApuracao",
144
                $this->std->idefolhapagto->indapuracao,
145
                true
146
            );
147
            $this->dom->addChild(
148
                $ideFolhaPagto,
149
                "perApur",
150
                $this->std->idefolhapagto->perapur,
151
                true
152
            );
153
            $infoExclusao->appendChild($ideFolhaPagto);
154
        }
155
        $this->node->appendChild($infoExclusao);
156
        $this->eSocial->appendChild($this->node);
157
        //$this->xml = $this->dom->saveXML($this->eSocial);
158
        $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...
159
    }
160
}
161