Passed
Push — master ( 8bd657...9b46f5 )
by Roberto
01:05
created

EvtTSVAltContr::toNode()   D

Complexity

Conditions 21
Paths 36

Size

Total Lines 344
Code Lines 234

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 462

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 344
ccs 0
cts 281
cp 0
rs 4.6955
cc 21
eloc 234
nc 36
nop 0
crap 462

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 EvtTSVAltContr Event S-2306 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 EvtTSVAltContr extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtTSVAltContr';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-2306';
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
        $evtid = FactoryId::build(
69
            $this->tpInsc,
70
            $this->nrInsc,
71
            $this->date,
72
            $this->sequencial
73
        );
74
75
        $evtTSVAltContr = $this->dom->createElement("evtTSVAltContr");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtTSVAltContr->appendChild($att);
82
83
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
84
85
        $ideEvento = $this->dom->createElement("ideEvento");
86
87
        $this->dom->addChild(
88
            $ideEvento,
89
            "indRetif",
90
            $this->std->indretif,
91
            true
92
        );
93
94
        $this->dom->addChild(
95
            $ideEvento,
96
            "tpAmb",
97
            $this->tpAmb,
98
            true
99
        );
100
        $this->dom->addChild(
101
            $ideEvento,
102
            "procEmi",
103
            $this->procEmi,
104
            true
105
        );
106
        $this->dom->addChild(
107
            $ideEvento,
108
            "verProc",
109
            $this->verProc,
110
            true
111
        );
112
113
        $this->node->insertBefore($ideEvento, $ideEmpregador);
114
115
        $ideTrabSemVinculo = $this->dom->createElement("ideTrabSemVinculo");
116
117
        $this->dom->addChild(
118
            $ideTrabSemVinculo,
119
            "cpfTrab",
120
            $this->std->trabsemvinculo->cpftrab,
121
            true
122
        );
123
124
        $this->dom->addChild(
125
            $ideTrabSemVinculo,
126
            "nisTrab",
127
            !empty($this->std->trabsemvinculo->nistrab) ? $this->std->trabsemvinculo->nistrab : null,
128
            false
129
        );
130
131
        $this->dom->addChild(
132
            $ideTrabSemVinculo,
133
            "codCateg",
134
            $this->std->trabsemvinculo->codcateg,
135
            true
136
        );
137
138
        $this->node->appendChild($ideTrabSemVinculo);
139
140
        $infoTSVAlteracao = $this->dom->createElement("infoTSVAlteracao");
141
142
        $this->dom->addChild(
143
            $infoTSVAlteracao,
144
            "dtAlteracao",
145
            $this->std->tsvalteracao->dtalteracao,
146
            true
147
        );
148
149
        $this->dom->addChild(
150
            $infoTSVAlteracao,
151
            "codFuncao",
152
            !empty($this->std->tsvalteracao->codfuncao) ? $this->std->tsvalteracao->codfuncao : null,
153
            false
154
        );
155
156
        $infoComplementares = $this->dom->createElement("infoComplementares");
157
158
        $infoTSVAlteracao->appendChild($infoComplementares);
159
160
        if (isset($this->std->cargofuncao)) {
161
            $cargoFuncao = $this->dom->createElement("cargoFuncao");
162
163
            $this->dom->addChild(
164
                $cargoFuncao,
165
                "codCargo",
166
                $this->std->cargofuncao->codcargo,
167
                true
168
            );
169
170
            $this->dom->addChild(
171
                $cargoFuncao,
172
                "codFuncao",
173
                !empty($this->std->cargofuncao->codfuncao) ? $this->std->cargofuncao->codfuncao : null,
174
                false
175
            );
176
177
            $infoComplementares->appendChild($cargoFuncao);
178
        }
179
180
        if (isset($this->std->remuneracao)) {
181
            $remuneracao = $this->dom->createElement("remuneracao");
182
183
            $this->dom->addChild(
184
                $remuneracao,
185
                "vrSalFx",
186
                $this->std->remuneracao->vrsalfx,
187
                true
188
            );
189
190
            $this->dom->addChild(
191
                $remuneracao,
192
                "undSalFixo",
193
                $this->std->remuneracao->undsalfixo,
194
                true
195
            );
196
197
            $this->dom->addChild(
198
                $remuneracao,
199
                "dscSalVar",
200
                !empty($this->std->remuneracao->dscsalVar) ? $this->std->remuneracao->dscsalVar : null,
201
                false
202
            );
203
204
            $infoComplementares->appendChild($remuneracao);
205
        }
206
207
        if (isset($this->std->estagiario)) {
208
            $infoEstagiario = $this->dom->createElement("infoEstagiario");
209
210
            $this->dom->addChild(
211
                $infoEstagiario,
212
                "natEstagio",
213
                $this->std->estagiario->natestagio,
214
                true
215
            );
216
217
            $this->dom->addChild(
218
                $infoEstagiario,
219
                "nivEstagio",
220
                $this->std->estagiario->nivestagio,
221
                true
222
            );
223
224
            $this->dom->addChild(
225
                $infoEstagiario,
226
                "areaAtuacao",
227
                !empty($this->std->estagiario->areaatuacao) ? $this->std->estagiario->areaatuacao : null,
228
                false
229
            );
230
231
            $this->dom->addChild(
232
                $infoEstagiario,
233
                "nrApol",
234
                !empty($this->std->estagiario->nrapol) ? $this->std->estagiario->nrapol : null,
235
                false
236
            );
237
238
            $this->dom->addChild(
239
                $infoEstagiario,
240
                "vlrBolsa",
241
                !empty($this->std->estagiario->vlrbolsa) ? $this->std->estagiario->vlrbolsa : null,
242
                false
243
            );
244
245
            $this->dom->addChild(
246
                $infoEstagiario,
247
                "dtPrevTerm",
248
                $this->std->estagiario->dtprevterm,
249
                true
250
            );
251
252
            if (isset($this->std->estagiario->instituicao)) {
253
                $instEnsino = $this->dom->createElement("instEnsino");
254
255
                $this->dom->addChild(
256
                    $instEnsino,
257
                    "cnpjInstEnsino",
258
                    $this->std->estagiario->instituicao->cnpjinstensino,
259
                    true
260
                );
261
262
                $this->dom->addChild(
263
                    $instEnsino,
264
                    "nmRazao",
265
                    $this->std->estagiario->instituicao->nmrazao,
266
                    true
267
                );
268
269
                $this->dom->addChild(
270
                    $instEnsino,
271
                    "dscLograd",
272
                    !empty($this->std->estagiario->instituicao->dsclograd) ?
273
                        $this->std->estagiario->instituicao->dsclograd : null,
274
                    false
275
                );
276
277
                $this->dom->addChild(
278
                    $instEnsino,
279
                    "nrLograd",
280
                    !empty($this->std->estagiario->instituicao->nrlograd) ?
281
                        $this->std->estagiario->instituicao->nrlograd : null,
282
                    false
283
                );
284
285
                $this->dom->addChild(
286
                    $instEnsino,
287
                    "bairro",
288
                    !empty($this->std->estagiario->instituicao->bairro) ? $this->std->estagiario->instituicao->bairro :
289
                        null,
290
                    false
291
                );
292
293
                $this->dom->addChild(
294
                    $instEnsino,
295
                    "cep",
296
                    !empty($this->std->estagiario->instituicao->cep) ? $this->std->estagiario->instituicao->cep : null,
297
                    false
298
                );
299
300
                $this->dom->addChild(
301
                    $instEnsino,
302
                    "codMunic",
303
                    !empty($this->std->estagiario->instituicao->codmunic) ?
304
                        $this->std->estagiario->instituicao->codmunic : null,
305
                    false
306
                );
307
308
                $this->dom->addChild(
309
                    $instEnsino,
310
                    "uf",
311
                    !empty($this->std->estagiario->instituicao->uf) ? $this->std->estagiario->instituicao->uf : null,
312
                    false
313
                );
314
315
                $infoEstagiario->appendChild($instEnsino);
316
            }
317
318
            if (isset($this->std->estagiario->ageintegracao)) {
319
                $ageIntegracao = $this->dom->createElement("ageIntegracao");
320
321
                $this->dom->addChild(
322
                    $ageIntegracao,
323
                    "cnpjAgntInteg",
324
                    $this->std->estagiario->ageintegracao->cnpjagntinteg,
325
                    true
326
                );
327
328
                $this->dom->addChild(
329
                    $ageIntegracao,
330
                    "nmRazao",
331
                    $this->std->estagiario->ageintegracao->nmrazao,
332
                    true
333
                );
334
335
                $this->dom->addChild(
336
                    $ageIntegracao,
337
                    "dscLograd",
338
                    $this->std->estagiario->ageintegracao->dsclograd,
339
                    true
340
                );
341
342
                $this->dom->addChild(
343
                    $ageIntegracao,
344
                    "nrLograd",
345
                    $this->std->estagiario->ageintegracao->nrlograd,
346
                    true
347
                );
348
349
                $this->dom->addChild(
350
                    $ageIntegracao,
351
                    "bairro",
352
                    !empty($this->std->estagiario->ageintegracao->bairro) ?
353
                        $this->std->estagiario->ageintegracao->bairro : null,
354
                    false
355
                );
356
357
                $this->dom->addChild(
358
                    $ageIntegracao,
359
                    "cep",
360
                    $this->std->estagiario->ageintegracao->cep,
361
                    true
362
                );
363
364
                $this->dom->addChild(
365
                    $ageIntegracao,
366
                    "codMunic",
367
                    $this->std->estagiario->ageintegracao->codmunic,
368
                    true
369
                );
370
371
                $this->dom->addChild(
372
                    $ageIntegracao,
373
                    "uf",
374
                    $this->std->estagiario->ageintegracao->uf,
375
                    true
376
                );
377
378
                $infoEstagiario->appendChild($ageIntegracao);
379
            }
380
381
            if (isset($this->std->estagiario->supervisor)) {
382
                $supervisorEstagio = $this->dom->createElement("supervisorEstagio");
383
384
                $this->dom->addChild(
385
                    $supervisorEstagio,
386
                    "cpfSupervisor",
387
                    $this->std->estagiario->supervisor->cpfsupervisor,
388
                    true
389
                );
390
391
                $this->dom->addChild(
392
                    $supervisorEstagio,
393
                    "nmSuperv",
394
                    $this->std->estagiario->supervisor->nmsuperv,
395
                    true
396
                );
397
398
399
                $infoEstagiario->appendChild($supervisorEstagio);
400
            }
401
402
            $infoComplementares->appendChild($infoEstagiario);
403
        }
404
405
        $this->node->appendChild($infoTSVAlteracao);
406
407
        $this->eSocial->appendChild($this->node);
408
        $this->sign();
409
    }
410
}
411