Completed
Pull Request — master (#254)
by Roberto
02:32
created

EvtAfastTemp::toNode()   F

Complexity

Conditions 18
Paths 36

Size

Total Lines 214

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 342

Importance

Changes 0
Metric Value
dl 0
loc 214
ccs 0
cts 210
cp 0
rs 3.8933
c 0
b 0
f 0
cc 18
nc 36
nop 0
crap 342

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 EvtAfastTemp Event S-2230 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 EvtAfastTemp extends Factory implements FactoryInterface
27
{
28
    /**
29
     * @var int
30
     */
31
    public $sequencial;
32
    /**
33
     * @var string
34
     */
35
    protected $evtName = 'evtAfastTemp';
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-2230';
40
    /**
41
     * Parameters patterns
42
     *
43
     * @var array
44
     */
45
    protected $parameters = [];
46
47
    /**
48
     * Constructor
49
     *
50
     * @param string $config
51
     * @param stdClass $std
52
     * @param Certificate $certificate | null
53
     * @param string $date
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate = null,
59
        $date = ''
60
    ) {
61
        parent::__construct($config, $std, $certificate, $date);
62
    }
63
64
    /**
65
     * Node constructor
66
     */
67
    protected function toNode()
68
    {
69
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
70
        //o idEvento pode variar de evento para evento
71
        //então cada factory individualmente terá de construir o seu
72
        $ideEvento = $this->dom->createElement("ideEvento");
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "indRetif",
76
            $this->std->indretif,
77
            true
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "nrRecibo",
82
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
83
            false
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "tpAmb",
88
            $this->tpAmb,
89
            true
90
        );
91
        $this->dom->addChild(
92
            $ideEvento,
93
            "procEmi",
94
            $this->procEmi,
95
            true
96
        );
97
        $this->dom->addChild(
98
            $ideEvento,
99
            "verProc",
100
            $this->verProc,
101
            true
102
        );
103
        $this->node->insertBefore($ideEvento, $ideEmpregador);
104
        $ideVinculo = $this->dom->createElement("ideVinculo");
105
        $this->dom->addChild(
106
            $ideVinculo,
107
            "cpfTrab",
108
            $this->std->idevinculo->cpftrab,
109
            true
110
        );
111
        $this->dom->addChild(
112
            $ideVinculo,
113
            "nisTrab",
114
            $this->std->idevinculo->nistrab,
115
            true
116
        );
117
        $this->dom->addChild(
118
            $ideVinculo,
119
            "matricula",
120
            !empty($this->std->idevinculo->matricula) ? $this->std->idevinculo->matricula : null,
121
            false
122
        );
123
        $this->dom->addChild(
124
            $ideVinculo,
125
            "codCateg",
126
            !empty($this->std->idevinculo->codcateg) ? $this->std->idevinculo->codcateg : null,
127
            false
128
        );
129
        $this->node->appendChild($ideVinculo);
130
        $infoAfastamento = $this->dom->createElement("infoAfastamento");
131
        if (! empty($this->std->iniafastamento)) {
132
            $iniAfastamento = $this->dom->createElement("iniAfastamento");
133
            $this->dom->addChild(
134
                $iniAfastamento,
135
                "dtIniAfast",
136
                $this->std->iniafastamento->dtiniafast,
137
                true
138
            );
139
            $this->dom->addChild(
140
                $iniAfastamento,
141
                "codMotAfast",
142
                $this->std->iniafastamento->codmotafast,
143
                true
144
            );
145
            $this->dom->addChild(
146
                $iniAfastamento,
147
                "infoMesmoMtv",
148
                ! empty($this->std->iniafastamento->infomesmomtv) ? $this->std->iniafastamento->infomesmomtv : null,
149
                false
150
            );
151
            $this->dom->addChild(
152
                $iniAfastamento,
153
                "tpAcidTransito",
154
                ! empty($this->std->iniafastamento->tpacidtransito) ? $this->std->iniafastamento->tpacidtransito : null,
155
                false
156
            );
157
            $this->dom->addChild(
158
                $iniAfastamento,
159
                "observacao",
160
                ! empty($this->std->iniafastamento->observacao) ? $this->std->iniafastamento->observacao : null,
161
                false
162
            );
163
            if (isset($this->std->iniafastamento->infoatestado)) {
164
                foreach ($this->std->iniafastamento->infoatestado as $info) {
165
                    $infoAtestado = $this->dom->createElement("infoAtestado");
166
                    $this->dom->addChild(
167
                        $infoAtestado,
168
                        "codCID",
169
                        ! empty($info->codcid) ? $info->codcid : null,
170
                        false
171
                    );
172
                    $this->dom->addChild(
173
                        $infoAtestado,
174
                        "qtdDiasAfast",
175
                        $info->qtddiasafast,
176
                        true
177
                    );
178
                    if (isset($info->emitente)) {
179
                        $emitente = $this->dom->createElement("emitente");
180
181
                        $this->dom->addChild(
182
                            $emitente,
183
                            "nmEmit",
184
                            $info->emitente->nmemit,
185
                            true
186
                        );
187
                        $this->dom->addChild(
188
                            $emitente,
189
                            "ideOC",
190
                            $info->emitente->ideoc,
191
                            true
192
                        );
193
                        $this->dom->addChild(
194
                            $emitente,
195
                            "nrOc",
196
                            $info->emitente->nroc,
197
                            true
198
                        );
199
                        $this->dom->addChild(
200
                            $emitente,
201
                            "ufOC",
202
                            ! empty($info->emitente->ufoc) ? $info->emitente->ufoc : null,
203
                            false
204
                        );
205
                        $infoAtestado->appendChild($emitente);
206
                    }
207
                    $iniAfastamento->appendChild($infoAtestado);
208
                }
209
            }
210
            if (! empty($this->std->infocessao)) {
211
                $infoCessao = $this->dom->createElement("infoCessao");
212
                $this->dom->addChild(
213
                    $infoCessao,
214
                    "cnpjCess",
215
                    $this->std->infocessao->cnpjcess,
216
                    true
217
                );
218
                $this->dom->addChild(
219
                    $infoCessao,
220
                    "infOnus",
221
                    $this->std->infocessao->infonus,
222
                    true
223
                );
224
                $iniAfastamento->appendChild($infoCessao);
225
            }
226
            if (! empty($this->std->infomandsind)) {
227
                $infoMandSind = $this->dom->createElement("infoMandSind");
228
                $this->dom->addChild(
229
                    $infoMandSind,
230
                    "cnpjSind",
231
                    $this->std->infomandsind->cnpjsind,
232
                    true
233
                );
234
                $this->dom->addChild(
235
                    $infoMandSind,
236
                    "infOnusRemun",
237
                    $this->std->infomandsind->infonusremun,
238
                    true
239
                );
240
                $iniAfastamento->appendChild($infoMandSind);
241
            }
242
            $infoAfastamento->appendChild($iniAfastamento);
243
        }
244
        if (! empty($this->std->inforetif)) {
245
            $infoRetif = $this->dom->createElement("infoRetif");
246
            $this->dom->addChild(
247
                $infoRetif,
248
                "origRetif",
249
                $this->std->inforetif->origretif,
250
                true
251
            );
252
            $this->dom->addChild(
253
                $infoRetif,
254
                "tpProc",
255
                $this->std->inforetif->tpproc,
256
                true
257
            );
258
            $this->dom->addChild(
259
                $infoRetif,
260
                "nrProc",
261
                ! empty($this->std->inforetif->nrproc) ? $this->std->inforetif->nrproc : null,
262
                false
263
            );
264
            $infoAfastamento->appendChild($infoRetif);
265
        }
266
        if (! empty($this->std->fimafastamento)) {
267
            $fimAfastamento = $this->dom->createElement("fimAfastamento");
268
            $this->dom->addChild(
269
                $fimAfastamento,
270
                "dtTermAfast",
271
                $this->std->fimafastamento->dttermafast,
272
                true
273
            );
274
            $infoAfastamento->appendChild($fimAfastamento);
275
        }
276
        $this->node->appendChild($infoAfastamento);
277
        $this->eSocial->appendChild($this->node);
278
        //$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...
279
        $this->sign();
280
    }
281
}
282