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

TraitS5002::toNode250()   C

Complexity

Conditions 13
Paths 18

Size

Total Lines 152

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 152
rs 5.2933
c 0
b 0
f 0
cc 13
nc 18
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 TraitS5002
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
            "nrRecArqBase",
19
            ! empty($this->std->nrrecarqbase) ? $this->std->nrrecarqbase : null,
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
            false
21
        );
22
        $this->dom->addChild(
23
            $ideEvento,
24
            "perApur",
25
            $this->std->perapur,
26
            true
27
        );
28
        $this->node->insertBefore($ideEvento, $ideEmpregador);
29
        $ideTrabalhador = $this->dom->createElement("ideTrabalhador");
30
        $this->dom->addChild(
31
            $ideTrabalhador,
32
            "cpfTrab",
33
            $this->std->cpftrab,
34
            true
35
        );
36
        $this->node->appendChild($ideTrabalhador);
37
        if (! empty($this->std->vrdeddep)) {
38
            $infoDep = $this->dom->createElement("infoDep");
39
            $this->dom->addChild(
40
                $infoDep,
41
                "vrDedDep",
42
                $this->std->vrdeddep,
43
                true
44
            );
45
            $this->node->appendChild($infoDep);
46
        }
47
        foreach ($this->std->infoirrf as $nIrrf) {
48
            $infoIrrf = $this->dom->createElement("infoIrrf");
49
            $this->dom->addChild(
50
                $infoIrrf,
51
                "codCateg",
52
                ! empty($nIrrf->codcateg) ? $nIrrf->codcateg : null,
53
                false
54
            );
55
            $this->dom->addChild(
56
                $infoIrrf,
57
                "indResBr",
58
                $nIrrf->indresbr,
59
                true
60
            );
61
            foreach ($nIrrf->basesirrf as $base) {
62
                $basesIrrf = $this->dom->createElement("basesIrrf");
63
                $this->dom->addChild(
64
                    $basesIrrf,
65
                    "tpValor",
66
                    $base->tpvalor,
67
                    true
68
                );
69
                $this->dom->addChild(
70
                    $basesIrrf,
71
                    "valor",
72
                    $base->valor,
73
                    true
74
                );
75
                $infoIrrf->appendChild($basesIrrf);
76
            }
77
            foreach ($nIrrf->irrf as $base) {
78
                $irrf = $this->dom->createElement("irrf");
79
                $this->dom->addChild(
80
                    $irrf,
81
                    "tpCR",
82
                    $base->tpcr,
83
                    true
84
                );
85
                $this->dom->addChild(
86
                    $irrf,
87
                    "vrIrrfDesc",
88
                    $base->vrirrfdesc,
89
                    true
90
                );
91
                $infoIrrf->appendChild($irrf);
92
            }
93
            if (isset($nIrrf->idepgtoext)) {
94
                $idePgtoExt = $this->dom->createElement("idePgtoExt");
95
                $idePais    = $this->dom->createElement("idePais");
96
                $this->dom->addChild(
97
                    $idePais,
98
                    "codPais",
99
                    $nIrrf->idepgtoext->codpais,
100
                    true
101
                );
102
                $this->dom->addChild(
103
                    $idePais,
104
                    "indNIF",
105
                    $nIrrf->idepgtoext->indnif,
106
                    true
107
                );
108
                $this->dom->addChild(
109
                    $idePais,
110
                    "nifBenef",
111
                    ! empty($nIrrf->idepgtoext->nifbenef) ? $nIrrf->idepgtoext->nifbenef : null,
112
                    false
113
                );
114
                $idePgtoExt->appendChild($idePais);
115
116
                $endExt = $this->dom->createElement("endExt");
117
                $this->dom->addChild(
118
                    $endExt,
119
                    "dscLograd",
120
                    $nIrrf->idepgtoext->dsclograd,
121
                    true
122
                );
123
                $this->dom->addChild(
124
                    $endExt,
125
                    "nrLograd",
126
                    ! empty($nIrrf->idepgtoext->nrlograd) ? $nIrrf->idepgtoext->nrlograd : null,
127
                    false
128
                );
129
                $this->dom->addChild(
130
                    $endExt,
131
                    "complem",
132
                    ! empty($nIrrf->idepgtoext->complem) ? $nIrrf->idepgtoext->complem : null,
133
                    false
134
                );
135
                $this->dom->addChild(
136
                    $endExt,
137
                    "bairro",
138
                    ! empty($nIrrf->idepgtoext->bairro) ? $nIrrf->idepgtoext->bairro : null,
139
                    false
140
                );
141
                $this->dom->addChild(
142
                    $endExt,
143
                    "nmCid",
144
                    $nIrrf->idepgtoext->nmcid,
145
                    true
146
                );
147
                $this->dom->addChild(
148
                    $endExt,
149
                    "codPostal",
150
                    ! empty($nIrrf->idepgtoext->codpostal) ? $nIrrf->idepgtoext->codpostal : null,
151
                    false
152
                );
153
                $idePgtoExt->appendChild($endExt);
154
                $infoIrrf->appendChild($idePgtoExt);
155
                $this->node->appendChild($infoIrrf);
156
            }
157
        }
158
        $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...
159
        //$this->xml = $this->dom->saveXML($this->eSocial);
160
        $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...
161
    }
162
    
163
    /**
164
     * builder for version S.1.0.0
165
     */
166
    protected function toNodeS100()
167
    {
168
        throw new \Exception("TODO !!");
169
    }
170
}
171