Test Failed
Push — master ( 78ef9f...88ea0f )
by Roberto
03:12 queued 11s
created

EvtInfoEmpregador   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 450
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 58
lcom 1
cbo 1
dl 0
loc 450
ccs 0
cts 392
cp 0
rs 4.5599
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
F toNode() 0 420 57

How to fix   Complexity   

Complex Class

Complex classes like EvtInfoEmpregador often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EvtInfoEmpregador, and based on these observations, apply Extract Interface, too.

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