Completed
Push — master ( 330834...f31a42 )
by Roberto
12:00 queued 08:52
created

EvtTabAmbiente::toNode()   D

Complexity

Conditions 15
Paths 42

Size

Total Lines 147

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
dl 0
loc 147
ccs 0
cts 138
cp 0
rs 4.7333
c 0
b 0
f 0
cc 15
nc 42
nop 0
crap 240

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