Passed
Pull Request — master (#112)
by Roberto
02:24
created

EvtTabAmbiente::toNode()   D

Complexity

Conditions 9
Paths 12

Size

Total Lines 122
Code Lines 94

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 122
ccs 0
cts 113
cp 0
rs 4.8196
c 0
b 0
f 0
cc 9
eloc 94
nc 12
nop 0
crap 90

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;
4
5
/**
6
 * Class eSocial EvtTabAmbiente Event S-1060 constructor
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHPSocial
10
 * @copyright NFePHP Copyright (c) 2017
11
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
12
 * @license   https://opensource.org/licenses/MIT MIT
13
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
14
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
15
 * @link      http://github.com/nfephp-org/sped-esocial for the canonical source repository
16
 */
17
18
use NFePHP\Common\Certificate;
19
use NFePHP\eSocial\Common\Factory;
20
use NFePHP\eSocial\Common\FactoryId;
21
use NFePHP\eSocial\Common\FactoryInterface;
22
use stdClass;
23
24
class EvtTabAmbiente extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtTabAmbiente';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1060';
40
41
    /**
42
     * Parameters patterns
43
     *
44
     * @var array
45
     */
46
    protected $parameters = [];
47
48
    /**
49
     * Constructor
50
     *
51
     * @param string $config
52
     * @param stdClass $std
53
     * @param Certificate $certificate
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate
59
    ) {
60
        parent::__construct($config, $std, $certificate);
61
    }
62
63
    /**
64
     * Node constructor
65
     */
66
    protected function toNode()
67
    {
68
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
69
        //o idEvento pode variar de evento para evento
70
        //então cada factory individualmente terá de construir o seu
71
        $ideEvento = $this->dom->createElement("ideEvento");
72
        $this->dom->addChild(
73
            $ideEvento,
74
            "tpAmb",
75
            $this->tpAmb,
76
            true
77
        );
78
        $this->dom->addChild(
79
            $ideEvento,
80
            "procEmi",
81
            $this->procEmi,
82
            true
83
        );
84
        $this->dom->addChild(
85
            $ideEvento,
86
            "verProc",
87
            $this->verProc,
88
            true
89
        );
90
        $this->node->insertBefore($ideEvento, $ideEmpregador);
91
        
92
        $ide = $this->dom->createElement("ideAmbiente");
93
        $this->dom->addChild(
94
            $ide,
95
            "codAmb",
96
            $this->std->codamb,
97
            true
98
        );
99
        $this->dom->addChild(
100
            $ide,
101
            "iniValid",
102
            $this->std->inivalid,
103
            true
104
        );
105
        $this->dom->addChild(
106
            $ide,
107
            "fimValid",
108
            ! empty($this->std->fimvalid) ? $this->std->fimvalid : null,
109
            false
110
        );
111
        
112
        $info = $this->dom->createElement("infoAmbiente");
113
        //seleção do modo
114
        if ($this->std->modo == 'INC') {
115
            $node = $this->dom->createElement("inclusao");
116
        } elseif ($this->std->modo == 'ALT') {
117
            $node = $this->dom->createElement("alteracao");
118
        } else {
119
            $node = $this->dom->createElement("exclusao");
120
        }
121
        $node->appendChild($ide);
122
        
123
        if (!empty($this->std->dadosambiente)) {
124
            $da = $this->std->dadosambiente;
125
            $dados = $this->dom->createElement("dadosAmbiente");
126
            $this->dom->addChild(
127
                $dados,
128
                "dscAmb",
129
                $da->dscamb,
130
                true
131
            );
132
            $this->dom->addChild(
133
                $dados,
134
                "localAmb",
135
                $da->localamb,
136
                true
137
            );
138
            $this->dom->addChild(
139
                $dados,
140
                "tpInsc",
141
                $da->tpinsc,
142
                true
143
            );
144
            $this->dom->addChild(
145
                $dados,
146
                "nrInsc",
147
                $da->nrinsc,
148
                true
149
            );
150
            foreach ($this->std->dadosambiente->fatorrisco as $ftr) {
151
                $fator = $this->dom->createElement("fatorRisco");
152
                $this->dom->addChild(
153
                    $fator,
154
                    "codFatRis",
155
                    $ftr->codfatris,
156
                    true
157
                );
158
                $dados->appendChild($fator);
159
            }
160
            $node->appendChild($dados);
161
        }
162
        
163
        if (!empty($this->std->novavalidade) && $this->std->modo == 'ALT') {
164
            $nova = $this->dom->createElement("novaValidade");
165
            $this->dom->addChild(
166
                $nova,
167
                "iniValid",
168
                $this->std->novavalidade->inivalid,
169
                true
170
            );
171
            $this->dom->addChild(
172
                $nova,
173
                "fimValid",
174
                ! empty($this->std->novavalidade->fimvalid)
175
                    ? $this->std->novavalidade->fimvalid
176
                    : null,
177
                false
178
            );
179
            $node->appendChild($nova);
180
        }
181
        
182
        $info->appendChild($node);
183
        $this->node->appendChild($info);
184
        $this->eSocial->appendChild($this->node);
185
        //$this->xml = $this->dom->saveXML($this->eSocial);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
186
        $this->sign();
187
    }
188
}
189