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

TraitS5013::toNode250()   C

Complexity

Conditions 13
Paths 15

Size

Total Lines 134

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 134
rs 5.2933
c 0
b 0
f 0
cc 13
nc 15
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 TraitS5013
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
            "perApur",
19
            $this->std->perapur,
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->node->insertBefore($ideEvento, $ideEmpregador);
23
        //tag deste evento em particular
24
                
25
        $infofgts = $this->dom->createElement("infoFGTS");
26
        $this->dom->addChild(
27
            $infofgts,
28
            "nrRecArqBase",
29
            $this->std->infofgts->nrrecarqbase,
30
            true
31
        );
32
        $this->dom->addChild(
33
            $infofgts,
34
            "indExistInfo",
35
            $this->std->infofgts->indexistinfo,
36
            true
37
        );
38
        if (!empty($this->std->infofgts->infobasefgts)) {
39
            $infoBaseFGTS = $this->dom->createElement("infoBaseFGTS");
40
            if (!empty($this->std->infofgts->infobasefgts->baseperapur)) {
41
                foreach ($this->std->infofgts->infobasefgts->baseperapur as $bap) {
42
                    $basePerApur = $this->dom->createElement("basePerApur");
43
                    $this->dom->addChild(
44
                        $basePerApur,
45
                        "tpValor",
46
                        $bap->tpvalor,
47
                        true
48
                    );
49
                    $this->dom->addChild(
50
                        $basePerApur,
51
                        "baseFGTS",
52
                        number_format($bap->basefgts, 2, ".", ""),
53
                        true
54
                    );
55
                    $infoBaseFGTS->appendChild($basePerApur);
56
                }
57
            }
58
            if (!empty($this->std->infofgts->infobasefgts->infobaseperante)) {
59
                foreach ($this->std->infofgts->infobasefgts->infobaseperante as $ipa) {
60
                    $infoBasePerAntE = $this->dom->createElement("infoBasePerAntE");
61
                    $this->dom->addChild(
62
                        $infoBasePerAntE,
63
                        "perRef",
64
                        $ipa->perref,
65
                        true
66
                    );
67
                    foreach ($ipa->baseperante as $bpae) {
68
                        $basePerAntE = $this->dom->createElement("basePerAntE");
69
                        $this->dom->addChild(
70
                            $basePerAntE,
71
                            "tpValorE",
72
                            $bpae->tpvalore,
73
                            true
74
                        );
75
                        $this->dom->addChild(
76
                            $basePerAntE,
77
                            "baseFGTSE",
78
                            number_format($bpae->basefgtse, 2, ".", ""),
79
                            true
80
                        );
81
                        $infoBasePerAntE->appendChild($basePerAntE);
82
                    }
83
                    $infoBaseFGTS->appendChild($infoBasePerAntE);
84
                }
85
            }
86
            $infofgts->appendChild($infoBaseFGTS);
87
        }
88
        if (!empty($this->std->infofgts->infodpsfgts)) {
89
            $infoDpsFGTS = $this->dom->createElement("infoDpsFGTS");
90
            if (!empty($this->std->infofgts->infodpsfgts->dpsperapur)) {
91
                foreach ($this->std->infofgts->infodpsfgts->dpsperapur as $dpap) {
92
                    $dpsPerApur = $this->dom->createElement("dpsPerApur");
93
                    $this->dom->addChild(
94
                        $dpsPerApur,
95
                        "tpDps",
96
                        $dpap->tpdps,
97
                        true
98
                    );
99
                    $this->dom->addChild(
100
                        $dpsPerApur,
101
                        "vrFGTS",
102
                        number_format($dpap->vrfgts, 2, ".", ""),
103
                        true
104
                    );
105
                    if (!empty($dpap->infodpsperante)) {
106
                        foreach ($dpap->infodpsperante as $ipte) {
107
                            $infoDpsPerAntE = $this->dom->createElement("infoDpsPerAntE");
108
                            $this->dom->addChild(
109
                                $infoDpsPerAntE,
110
                                "perRef",
111
                                $ipte->perref,
112
                                true
113
                            );
114
                            foreach ($ipte->dpsperante as $dpte) {
115
                                $dpsPerAntE = $this->dom->createElement("dpsPerAntE");
116
                                $this->dom->addChild(
117
                                    $dpsPerAntE,
118
                                    "tpDpsE",
119
                                    $dpte->tpDpsE,
120
                                    true
121
                                );
122
                                $this->dom->addChild(
123
                                    $dpsPerAntE,
124
                                    "vrFGTSE",
125
                                    $dpte->vrfgtse,
126
                                    true
127
                                );
128
                                $infoDpsPerAntE->appendChild($dpsPerAntE);
129
                            }
130
                            $dpsPerApur->appendChild($infoDpsPerAntE);
131
                        }
132
                    }
133
                    $infoDpsFGTS->appendChild($dpsPerApur);
134
                }
135
            }
136
            $infofgts->appendChild($infoDpsFGTS);
137
        }
138
        $this->node->appendChild($infofgts);
139
        //finalização do xml
140
        $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...
141
        //$this->xml = $this->dom->saveXML($this->eSocial);
142
        $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...
143
    }
144
    
145
    /**
146
     * builder for version S.1.0.0
147
     */
148
    protected function toNodeS100()
149
    {
150
        throw new \Exception("TODO !!");
151
    }
152
}
153