Passed
Push — master ( 8dcfdd...d8692d )
by Roberto
02:57
created

EvtAltContratual   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 441
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 32
lcom 1
cbo 1
dl 0
loc 441
ccs 0
cts 395
cp 0
rs 9.6
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
F toNode() 0 401 31
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtAltContratual Event S-2206 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 EvtAltContratual extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
    /**
31
     * @var string
32
     */
33
    protected $evtName = 'evtAltContratual';
34
    /**
35
     * @var string
36
     */
37
    protected $evtAlias = 'S-2206';
38
    /**
39
     * Parameters patterns
40
     *
41
     * @var array
42
     */
43
    protected $parameters = [];
44
45
    /**
46
     * Constructor
47
     *
48
     * @param string $config
49
     * @param stdClass $std
50
     * @param Certificate $certificate
51
     */
52
    public function __construct(
53
        $config,
54
        stdClass $std,
55
        Certificate $certificate
56
    ) {
57
        parent::__construct($config, $std, $certificate);
58
    }
59
60
    /**
61
     * Node constructor
62
     */
63
    protected function toNode()
64
    {
65
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
66
        $ideEvento = $this->dom->createElement("ideEvento");
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "indRetif",
70
            $this->std->indretif,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "nrRecibo",
76
            ! empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
77
            false
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "tpAmb",
82
            $this->tpAmb,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "procEmi",
88
            $this->procEmi,
89
            true
90
        );
91
        $this->dom->addChild(
92
            $ideEvento,
93
            "verProc",
94
            $this->verProc,
95
            true
96
        );
97
        $this->node->insertBefore($ideEvento, $ideEmpregador);
98
        
99
        $ideVinculo = $this->dom->createElement("ideVinculo");
100
        $this->dom->addChild(
101
            $ideVinculo,
102
            "cpfTrab",
103
            $this->std->cpftrab,
104
            true
105
        );
106
        $this->dom->addChild(
107
            $ideVinculo,
108
            "nisTrab",
109
            $this->std->nistrab,
110
            true
111
        );
112
        $this->dom->addChild(
113
            $ideVinculo,
114
            "matricula",
115
            $this->std->matricula,
116
            true
117
        );
118
        $this->node->appendChild($ideVinculo);
119
        
120
        $altContratual = $this->dom->createElement("altContratual");
121
        $this->dom->addChild(
122
            $altContratual,
123
            "dtAlteracao",
124
            $this->std->dtalteracao,
125
            true
126
        );
127
        $this->dom->addChild(
128
            $altContratual,
129
            "dtEf",
130
            !empty($this->std->dtef) ? $this->std->dtef : null,
131
            false
132
        );
133
        $this->dom->addChild(
134
            $altContratual,
135
            "dscAlt",
136
            !empty($this->std->dscalt) ? $this->std->dscalt : null,
137
            false
138
        );
139
        
140
        $vinculo = $this->dom->createElement("vinculo");
141
        $this->dom->addChild(
142
            $vinculo,
143
            "tpRegPrev",
144
            $this->std->tpregprev,
145
            true
146
        );
147
        $altContratual->appendChild($vinculo);
148
149
        $infoRegimeTrab = $this->dom->createElement("infoRegimeTrab");
150
        if (!empty($this->std->infoceletista)) {
151
            $ct = $this->std->infoceletista;
152
            $infoCeletista = $this->dom->createElement("infoCeletista");
153
            $this->dom->addChild(
154
                $infoCeletista,
155
                "tpRegJor",
156
                $ct->tpregjor,
157
                true
158
            );
159
            $this->dom->addChild(
160
                $infoCeletista,
161
                "natAtividade",
162
                $ct->natatividade,
163
                true
164
            );
165
            $this->dom->addChild(
166
                $infoCeletista,
167
                "dtBase",
168
                !empty($ct->dtbase) ? $ct->dtbase : null,
169
                false
170
            );
171
            $this->dom->addChild(
172
                $infoCeletista,
173
                "cnpjSindCategProf",
174
                $ct->cnpjsindcategprof,
175
                true
176
            );
177
            if (!empty($ct->trabtemp)) {
178
                $trabTemp = $this->dom->createElement("trabTemp");
179
                $this->dom->addChild(
180
                    $trabTemp,
181
                    "justProrr",
182
                    $ct->trabtemp->justprorr,
183
                    true
184
                );
185
                $infoCeletista->appendChild($trabTemp);
186
            }
187
            if (!empty($ct->aprend)) {
188
                $aprend = $this->dom->createElement("aprend");
189
                $this->dom->addChild(
190
                    $aprend,
191
                    "tpInsc",
192
                    $ct->aprend->tpinsc,
193
                    true
194
                );
195
                $this->dom->addChild(
196
                    $aprend,
197
                    "nrInsc",
198
                    $ct->aprend->nrinsc,
199
                    true
200
                );
201
                $infoCeletista->appendChild($aprend);
202
            }
203
            $infoRegimeTrab->appendChild($infoCeletista);
204
        } elseif (!empty($this->std->infoestatutario)) {
205
            $ct = $this->std->infoestatutario;
206
            $infoEstatutario = $this->dom->createElement("infoEstatutario");
207
            $this->dom->addChild(
208
                $infoEstatutario,
209
                "tpPlanRP",
210
                $ct->tpPlanRP,
211
                true
212
            );
213
            $infoRegimeTrab->appendChild($infoEstatutario);
214
        } 
215
        $altContratual->appendChild($infoRegimeTrab);
216
        
217
        $infoContrato = $this->dom->createElement("infoContrato");
218
        $ct = $this->std->infocontrato;
219
        $this->dom->addChild(
220
            $infoContrato,
221
            "codCargo",
222
            !empty($ct->codcargo) ? $ct->codcargo : null,
223
            false
224
        );
225
        $this->dom->addChild(
226
            $infoContrato,
227
            "codFuncao",
228
            !empty($ct->codfuncao) ? $ct->codfuncao : null,
229
            false
230
        );
231
        $this->dom->addChild(
232
            $infoContrato,
233
            "codCateg",
234
            $ct->codcateg,
235
            true
236
        );
237
        $this->dom->addChild(
238
            $infoContrato,
239
            "codCarreira",
240
            !empty($ct->codcarreira) ? $ct->codcarreira : null,
241
            false
242
        );
243
        $this->dom->addChild(
244
            $infoContrato,
245
            "dtIngrCarr",
246
            !empty($ct->dtingrcarr) ? $ct->dtingrcarr : null,
247
            false
248
        );
249
        $remuneracao = $this->dom->createElement("remuneracao");
250
        $this->dom->addChild(
251
            $remuneracao,
252
            "vrSalFx",
253
            $ct->vrsalfx,
254
            true
255
        );
256
        $this->dom->addChild(
257
            $remuneracao,
258
            "undSalFixo",
259
            $ct->undsalfixo,
260
            true
261
        );
262
        $this->dom->addChild(
263
            $remuneracao,
264
            "dscSalVar",
265
            !empty($ct->dscsalvar) ? $ct->dscsalvar : null,
266
            false
267
        );
268
        $infoContrato->appendChild($remuneracao);
269
        $duracao = $this->dom->createElement("duracao");
270
        $this->dom->addChild(
271
            $duracao,
272
            "tpContr",
273
            $ct->tpcontr,
274
            true
275
        );
276
        $this->dom->addChild(
277
            $duracao,
278
            "dtTerm",
279
            !empty($ct->dtterm) ? $ct->dtterm : null,
280
            false
281
        );
282
        $infoContrato->appendChild($duracao);
283
        
284
        $localTrabalho = $this->dom->createElement("localTrabalho");
285
        if (!empty($this->std->localtrabgeral)) {
286
            $tg = $this->std->localtrabgeral;
287
            $localTrabGeral = $this->dom->createElement("localTrabGeral");
288
            $this->dom->addChild(
289
                $localTrabGeral,
290
                "tpInsc",
291
                $tg->tpinsc,
292
                true
293
            );
294
            $this->dom->addChild(
295
                $localTrabGeral,
296
                "nrInsc",
297
                $tg->nrinsc,
298
                true
299
            );
300
            $this->dom->addChild(
301
                $localTrabGeral,
302
                "descComp",
303
                !empty($tg->desccomp) ? $tg->desccomp : null,
304
                false
305
            );
306
            $localTrabalho->appendChild($localTrabGeral);
307
        } elseif (!empty($this->std->localtrabdom)) {
308
            $tg = $this->std->localtrabdom;
309
            $localTrabDom = $this->dom->createElement("localTrabDom");
310
            $this->dom->addChild(
311
                $localTrabDom,
312
                "tpLograd",
313
                $tg->tplograd,
314
                true
315
            );
316
            $this->dom->addChild(
317
                $localTrabDom,
318
                "dscLograd",
319
                $tg->dsclograd,
320
                true
321
            );
322
            $this->dom->addChild(
323
                $localTrabDom,
324
                "nrLograd",
325
                $tg->nrlograd,
326
                true
327
            );
328
            $this->dom->addChild(
329
                $localTrabDom,
330
                "complemento",
331
                !empty($tg->complemento) ? $tg->complemento : null,
332
                false
333
            );
334
            $this->dom->addChild(
335
                $localTrabDom,
336
                "bairro",
337
                !empty($tg->bairro) ? $tg->bairro : null,
338
                false
339
            );
340
            $this->dom->addChild(
341
                $localTrabDom,
342
                "cep",
343
                $tg->cep,
344
                true
345
            );
346
            $this->dom->addChild(
347
                $localTrabDom,
348
                "codMunic",
349
                $tg->codmunic,
350
                true
351
            );
352
            $this->dom->addChild(
353
                $localTrabDom,
354
                "uf",
355
                $tg->uf,
356
                true
357
            );
358
            $localTrabalho->appendChild($localTrabDom);
359
        }
360
        $infoContrato->appendChild($localTrabalho);
361
        
362
        if (!empty($this->std->horcontratual)) {
363
            $hc = $this->std->horcontratual;
364
            $horContratual = $this->dom->createElement("horContratual");
365
            $this->dom->addChild(
366
                $horContratual,
367
                "qtdHrsSem",
368
                !empty($hc->qtdhrssem) ? $hc->qtdhrssem : null,
369
                false
370
            );
371
            $this->dom->addChild(
372
                $horContratual,
373
                "tpJornada",
374
                $hc->tpjornada,
375
                true
376
            );
377
            $this->dom->addChild(
378
                $horContratual,
379
                "dscTpJorn",
380
                !empty($hc->dsctpjorn) ? $hc->dsctpjorn : null,
381
                false
382
            );
383
            $this->dom->addChild(
384
                $horContratual,
385
                "tmpParc",
386
                $hc->tmpparc,
387
                true
388
            );
389
            if (!empty($hc->horario)) {
390
                foreach ($hc->horario as $hor) {
391
                    $horario = $this->dom->createElement("horario");
392
                    $this->dom->addChild(
393
                        $horario,
394
                        "dia",
395
                        $hor->dia,
396
                        true
397
                    );
398
                    $this->dom->addChild(
399
                        $horario,
400
                        "codHorContrat",
401
                        $hor->codhorcontrat,
402
                        true
403
                    );
404
                    $horContratual->appendChild($horario);
405
                }
406
            }
407
            $infoContrato->appendChild($horContratual);
408
        }
409
        
410
        if (!empty($this->std->filiacaosindical)) {
411
            foreach ($this->std->filiacaosindical as $fs) {
412
                $filiacaoSindical = $this->dom->createElement("filiacaoSindical");
413
                $this->dom->addChild(
414
                    $filiacaoSindical,
415
                    "cnpjSindTrab",
416
                    $fs->cnpjsindtrab,
417
                    true
418
                );
419
                $infoContrato->appendChild($filiacaoSindical);
420
            }
421
        }
422
        
423
        if (!empty($this->std->alvarajudicial)) {
424
            $alvaraJudicial = $this->dom->createElement("alvaraJudicial");
425
            $this->dom->addChild(
426
                $alvaraJudicial,
427
                "nrProcJud",
428
                $this->std->alvarajudicial->nrprocjud,
429
                true
430
            );
431
            $infoContrato->appendChild($alvaraJudicial);
432
        }
433
        
434
        if (!empty($this->std->observacoes)) {
435
            foreach($this->std->observacoes as $obs) {
436
                $observacoes = $this->dom->createElement("observacoes");
437
                $this->dom->addChild(
438
                    $observacoes,
439
                    "observacao",
440
                    $obs->observacao,
441
                    true
442
                );
443
                $infoContrato->appendChild($observacoes);
444
            }
445
        }
446
        
447
        if (!empty($this->std->servpubl)) {
448
            $servPubl = $this->dom->createElement("servPubl");
449
            $this->dom->addChild(
450
                $servPubl,
451
                "mtvAlter",
452
                $this->std->servpubl->mtvalter,
453
                true
454
            );
455
            $infoContrato->appendChild($servPubl);
456
        }
457
        $altContratual->appendChild($infoContrato);
458
        $this->node->appendChild($altContratual);
459
        //finalização do xml
460
        $this->eSocial->appendChild($this->node);
461
        //$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...
462
        $this->sign();
463
    }
464
}
465