Passed
Push — master ( 30228e...92c369 )
by Roberto
02:42
created

EvtInfoEmpregador::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 2
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtInfoEmpregador Event S-1000 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\FactoryInterface;
23
use stdClass;
24
25
class EvtInfoEmpregador extends Factory implements FactoryInterface
26
{
27
    /**
28
     * @var string
29
     */
30
    protected $evtName = 'evtInfoEmpregador';
31
    /**
32
     * @var string
33
     */
34
    protected $evtAlias = 'S-1000';
35
36
    /**
37
     * Constructor
38
     * @param string $config
39
     * @param stdClass $std
40
     * @param Certificate $certificate
41
     */
42
    public function __construct(
43
        $config,
44
        stdClass $std,
45
        Certificate $certificate = null,
46
        $date = ''
47
    ) {
48
        parent::__construct($config, $std, $certificate);
49
    }
50
51
    /**
52
     * Node constructor
53
     */
54
    protected function toNode()
55
    {
56
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
57
        //o idEvento pode variar de evento para evento
58
        //então cada factory individualmente terá de construir o seu
59
        $ideEvento = $this->dom->createElement("ideEvento");
60
        $this->dom->addChild(
61
            $ideEvento,
62
            "tpAmb",
63
            $this->tpAmb,
64
            true
65
        );
66
        $this->dom->addChild(
67
            $ideEvento,
68
            "procEmi",
69
            $this->procEmi,
70
            true
71
        );
72
        $this->dom->addChild(
73
            $ideEvento,
74
            "verProc",
75
            $this->verProc,
76
            true
77
        );
78
        $this->node->insertBefore($ideEvento, $ideEmpregador);
79
        $infoEmpregador = $this->dom->createElement("infoEmpregador");
80
        //periodo
81
        $idePeriodo = $this->dom->createElement("idePeriodo");
82
        $this->dom->addChild(
83
            $idePeriodo,
84
            "iniValid",
85
            $this->std->ideperiodo->inivalid,
86
            true
87
        );
88
        $this->dom->addChild(
89
            $idePeriodo,
90
            "fimValid",
91
            !empty($this->std->ideperiodo->fimvalid) ? $this->std->ideperiodo->fimvalid : '',
92
            false
93
        );
94
        //infoCadastro
95
        if (isset($this->std->infocadastro)) {
96
            $cad = $this->std->infocadastro;
97
            $infoCadastro = $this->dom->createElement("infoCadastro");
98
            $this->dom->addChild(
99
                $infoCadastro,
100
                "nmRazao",
101
                $cad->nmrazao,
102
                true
103
            );
104
            $this->dom->addChild(
105
                $infoCadastro,
106
                "classTrib",
107
                $cad->classtrib,
108
                true
109
            );
110
            $this->dom->addChild(
111
                $infoCadastro,
112
                "natJurid",
113
                !empty($cad->natjurid) ? $cad->natjurid : null,
114
                ($this->tpInsc == 1) ? true : false //obrigatorio para pessoa juridica
115
            );
116
            $this->dom->addChild(
117
                $infoCadastro,
118
                "indCoop",
119
                !empty($cad->indcoop) ? $cad->indcoop : null,
120
                ($this->tpInsc == 1) ? true : false //obrigatorio para pessoa juridica
121
            );
122
            $this->dom->addChild(
123
                $infoCadastro,
124
                "indConstr",
125
                !empty($cad->indconstr) ? $cad->indconstr : null,
126
                ($this->tpInsc == 1) ? true : false //obrigatorio para pessoa juridica
127
            );
128
            $this->dom->addChild(
129
                $infoCadastro,
130
                "indDesFolha",
131
                $cad->inddesfolha,
132
                true
133
            );
134
            $this->dom->addChild(
135
                $infoCadastro,
136
                "indOpcCP",
137
                !empty($cad->indopccp) ? $cad->indopccp : null,
138
                false
139
            );
140
            $this->dom->addChild(
141
                $infoCadastro,
142
                "indOptRegEletron",
143
                $cad->indoptregeletron,
144
                true
145
            );
146
            $this->dom->addChild(
147
                $infoCadastro,
148
                "indEntEd",
149
                !empty($cad->indented) ? $cad->indented : null,
150
                false
151
            );
152
            $this->dom->addChild(
153
                $infoCadastro,
154
                "indEtt",
155
                !empty($cad->indett) ? $cad->indett : null,
156
                false
157
            );
158
            $this->dom->addChild(
159
                $infoCadastro,
160
                "nrRegEtt",
161
                !empty($cad->nrregett) ? $cad->nrregett : null,
162
                false
163
            );
164
        }
165
        if (isset($this->std->dadosisencao) && !empty($infoCadastro)) {
166
            $cad  = $this->std->dadosisencao;
167
            $info = $this->dom->createElement("dadosIsencao");
168
            $this->dom->addChild(
169
                $info,
170
                "ideMinLei",
171
                $cad->ideminlei,
172
                true
173
            );
174
            $this->dom->addChild(
175
                $info,
176
                "nrCertif",
177
                $cad->nrcertif,
178
                true
179
            );
180
            $this->dom->addChild(
181
                $info,
182
                "dtEmisCertif",
183
                $cad->dtemiscertif,
184
                true
185
            );
186
            $this->dom->addChild(
187
                $info,
188
                "dtVencCertif",
189
                $cad->dtcenccertif,
190
                true
191
            );
192
            $this->dom->addChild(
193
                $info,
194
                "nrProtRenov",
195
                !empty($cad->nrprotrenov) ? $cad->nrprotrenov : null,
196
                false
197
            );
198
            $this->dom->addChild(
199
                $info,
200
                "dtProtRenov",
201
                !empty($cad->dtprotrenov) ? $cad->dtprotrenov : null,
202
                false
203
            );
204
            $this->dom->addChild(
205
                $info,
206
                "dtDou",
207
                !empty($cad->dtdou) ? $cad->dtdou : null,
208
                false
209
            );
210
            $this->dom->addChild(
211
                $info,
212
                "pagDou",
213
                !empty($cad->pagdou) ? $cad->pagdou : null,
214
                false
215
            );
216
            $infoCadastro->appendChild($info);
217
        }
218
        if (isset($this->std->contato) && !empty($infoCadastro)) {
219
            $cad  = $this->std->contato;
220
            $info = $this->dom->createElement("contato");
221
            $this->dom->addChild(
222
                $info,
223
                "nmCtt",
224
                $cad->nmctt,
225
                true
226
            );
227
            $this->dom->addChild(
228
                $info,
229
                "cpfCtt",
230
                $cad->cpfctt,
231
                true
232
            );
233
            $this->dom->addChild(
234
                $info,
235
                "foneFixo",
236
                !empty($cad->fonefixo) ? $cad->fonefixo : '',
237
                false
238
            );
239
            $this->dom->addChild(
240
                $info,
241
                "foneCel",
242
                !empty($cad->fonecel) ? $cad->fonecel : null,
243
                false
244
            );
245
            $this->dom->addChild(
246
                $info,
247
                "email",
248
                !empty($cad->email) ? $cad->email : null,
249
                false
250
            );
251
            $infoCadastro->appendChild($info);
252
        }
253
        if (isset($this->std->infoop)  && !empty($infoCadastro)) {
254
            $cad  = $this->std->infoop;
255
            $infoOP = $this->dom->createElement("infoOP");
256
            $this->dom->addChild(
257
                $infoOP,
258
                "nrSiafi",
259
                $cad->nrsiafi,
260
                true
261
            );
262
            if (isset($this->std->infoefr)) {
263
                $cad  = $this->std->infoefr;
264
                $infoEFR = $this->dom->createElement("infoEFR");
265
                $this->dom->addChild(
266
                    $infoEFR,
267
                    "ideEFR",
268
                    $cad->ideefr,
269
                    true
270
                );
271
                $this->dom->addChild(
272
                    $infoEFR,
273
                    "cnpjEFR",
274
                    !empty($cad->cnpjefr) ? $cad->cnpjefr : null,
275
                    false
276
                );
277
                $infoOP->appendChild($infoEFR);
278
            }
279
            if (isset($this->std->infoente)) {
280
                $cad  = $this->std->infoente;
281
                $infoEnte = $this->dom->createElement("infoEnte");
282
                $this->dom->addChild(
283
                    $infoEnte,
284
                    "nmEnte",
285
                    $cad->nmente,
286
                    true
287
                );
288
                $this->dom->addChild(
289
                    $infoEnte,
290
                    "uf",
291
                    $cad->uf,
292
                    true
293
                );
294
                $this->dom->addChild(
295
                    $infoEnte,
296
                    "codMunic",
297
                    !empty($cad->codmunic) ? $cad->codmunic : null,
298
                    false
299
                );
300
                $this->dom->addChild(
301
                    $infoEnte,
302
                    "indRPPS",
303
                    $cad->indrpps,
304
                    true
305
                );
306
                $this->dom->addChild(
307
                    $infoEnte,
308
                    "subteto",
309
                    $cad->subteto,
310
                    true
311
                );
312
                $this->dom->addChild(
313
                    $infoEnte,
314
                    "vrSubteto",
315
                    number_format($cad->vrsubteto, 2, ".", ""),
316
                    true
317
                );
318
                $infoOP->appendChild($infoEnte);
319
            }
320
            $infoCadastro->appendChild($infoOP);
321
        }
322
        if (isset($this->std->infoorginternacional) && !empty($infoCadastro)) {
323
            $cad = $this->std->infoorginternacional;
324
            $info = $this->dom->createElement("infoorgInternacional");
325
            $this->dom->addChild(
326
                $info,
327
                "indAcordoIsenMulta",
328
                $cad->indacordoisenmulta,
329
                true
330
            );
331
            $infoCadastro->appendChild($info);
332
        }
333
        if (isset($this->std->softwarehouse) && !empty($infoCadastro)) {
334
            foreach ($this->std->softwarehouse as $sh) {
335
                $info = $this->dom->createElement("softwareHouse");
336
                $this->dom->addChild(
337
                    $info,
338
                    "cnpjSoftHouse",
339
                    $sh->cnpjsofthouse,
340
                    true
341
                );
342
                $this->dom->addChild(
343
                    $info,
344
                    "nmRazao",
345
                    $sh->nmrazao,
346
                    true
347
                );
348
                $this->dom->addChild(
349
                    $info,
350
                    "nmCont",
351
                    $sh->nmcont,
352
                    true
353
                );
354
                $this->dom->addChild(
355
                    $info,
356
                    "telefone",
357
                    $sh->telefone,
358
                    true
359
                );
360
                $this->dom->addChild(
361
                    $info,
362
                    "email",
363
                    !empty($sh->email) ? $sh->email : null,
364
                    false
365
                );
366
                $infoCadastro->appendChild($info);
367
            }
368
        }
369
        if (isset($this->std->situacaopj)) {
370
            $infoComplementares = $this->dom->createElement("infoComplementares");
371
            $sh = $this->std->situacaopj;
372
            $info = $this->dom->createElement("situacaoPJ");
373
            $this->dom->addChild(
374
                $info,
375
                "indSitPJ",
376
                $sh->indsitpj,
377
                true
378
            );
379
            $infoComplementares->appendChild($info);
380
        } elseif (isset($this->std->situacaopf)) {
381
            $infoComplementares = $this->dom->createElement("infoComplementares");
382
            $sh = $this->std->situacaopf;
383
            $info = $this->dom->createElement("situacaoPF");
384
            $this->dom->addChild(
385
                $info,
386
                "indSitPF",
387
                $sh->indsitpf,
388
                true
389
            );
390
            $infoComplementares->appendChild($info);
391
        }
392
        if (isset($this->std->novavalidade)) {
393
            $sh = $this->std->novavalidade;
394
            $novavalidade = $this->dom->createElement("novaValidade");
395
            $this->dom->addChild(
396
                $novavalidade,
397
                "iniValid",
398
                $sh->inivalid,
399
                true
400
            );
401
            $this->dom->addChild(
402
                $novavalidade,
403
                "fimValid",
404
                !empty($sh->fimValid) ? $sh->fimValid : null,
405
                false
406
            );
407
        }
408
        switch ($this->std->modo) {
409
            case "ALT":
410
                $node = $this->dom->createElement("alteracao");
411
                $node->appendChild($idePeriodo);
412
                if (isset($infoComplementares) && isset($infoCadastro)) {
413
                    $infoCadastro->appendChild($infoComplementares);
414
                }
415
                isset($infoCadastro) ? $node->appendChild($infoCadastro) : null;
416
                isset($novavalidade) ? $node->appendChild($novavalidade) : null;
417
                break;
418
            case "EXC":
419
                $node = $this->dom->createElement("exclusao");
420
                $node->appendChild($idePeriodo);
421
                break;
422
            case "INC":
423
            default:
424
                $node = $this->dom->createElement("inclusao");
425
                $node->appendChild($idePeriodo);
426
                if (isset($infoComplementares) && isset($infoCadastro)) {
427
                    $infoCadastro->appendChild($infoComplementares);
428
                }
429
                isset($infoCadastro) ? $node->appendChild($infoCadastro) : null;
430
        }
431
        $infoEmpregador->appendChild($node);
432
        $this->node->appendChild($infoEmpregador);
433
        //finalização do xml
434
        $this->eSocial->appendChild($this->node);
435
        //$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...
436
        $this->sign();
437
    }
438
}
439