Passed
Pull Request — master (#153)
by Roberto
03:57 queued 01:28
created

EvtCAT::toNode()   D

Complexity

Conditions 27
Paths 16

Size

Total Lines 342
Code Lines 280

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 756

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 342
ccs 0
cts 336
cp 0
rs 4.509
cc 27
eloc 280
nc 16
nop 0
crap 756

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 EvtCAT Event S-2210 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 EvtCAT extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $evtName = 'evtCAT';
30
    /**
31
     * @var string
32
     */
33
    protected $evtAlias = 'S-2210';
34
    /**
35
     * Parameters patterns
36
     *
37
     * @var array
38
     */
39
    protected $parameters = [];
40
41
    /**
42
     * Constructor
43
     *
44
     * @param string $config
45
     * @param stdClass $std
46
     * @param Certificate $certificate
47
     */
48
    public function __construct(
49
        $config,
50
        stdClass $std,
51
        Certificate $certificate
52
    ) {
53
        parent::__construct($config, $std, $certificate);
54
    }
55
56
    /**
57
     * Node constructor
58
     */
59
    protected function toNode()
60
    {
61
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
62
        $ideEvento = $this->dom->createElement("ideEvento");
63
        $this->dom->addChild(
64
            $ideEvento,
65
            "indRetif",
66
            $this->std->indretif,
67
            true
68
        );
69
        $this->dom->addChild(
70
            $ideEvento,
71
            "nrRecibo",
72
            ! empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
73
            false
74
        );
75
        $this->dom->addChild(
76
            $ideEvento,
77
            "tpAmb",
78
            $this->tpAmb,
79
            true
80
        );
81
        $this->dom->addChild(
82
            $ideEvento,
83
            "procEmi",
84
            $this->procEmi,
85
            true
86
        );
87
        $this->dom->addChild(
88
            $ideEvento,
89
            "verProc",
90
            $this->verProc,
91
            true
92
        );
93
        $this->node->insertBefore($ideEvento, $ideEmpregador);
94
        
95
        $ideRegistrador = $this->dom->createElement("ideRegistrador");
96
        $this->dom->addChild(
97
            $ideRegistrador,
98
            "tpRegistrador",
99
            $this->std->tpregistrador,
100
            true
101
        );
102
        $this->dom->addChild(
103
            $ideRegistrador,
104
            "tpInsc",
105
            !empty($this->std->tpinsc) ? $this->std->tpinsc : null,
106
            false
107
        );
108
        $this->dom->addChild(
109
            $ideRegistrador,
110
            "nrInsc",
111
            !empty($this->std->nrinsc) ? $this->std->nrinsc : null,
112
            false
113
        );
114
        $this->node->insertBefore($ideRegistrador, $ideEmpregador);
115
        
116
        $ideTrabalhador = $this->dom->createElement("ideTrabalhador");
117
        $this->dom->addChild(
118
            $ideTrabalhador,
119
            "cpfTrab",
120
            $this->std->cpftrab,
121
            true
122
        );
123
        $this->dom->addChild(
124
            $ideTrabalhador,
125
            "nisTrab",
126
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
127
            false
128
        );
129
        $this->node->appendChild($ideTrabalhador);
130
131
        $cat = $this->dom->createElement("cat");
132
        $this->dom->addChild(
133
            $cat,
134
            "dtAcid",
135
            $this->std->dtacid,
136
            true
137
        );
138
        $this->dom->addChild(
139
            $cat,
140
            "tpAcid",
141
            $this->std->tpacid,
142
            true
143
        );
144
        $this->dom->addChild(
145
            $cat,
146
            "hrAcid",
147
            $this->std->hracid,
148
            true
149
        );
150
        $this->dom->addChild(
151
            $cat,
152
            "hrsTrabAntesAcid",
153
            $this->std->hrstrabantesacid,
154
            true
155
        );
156
        $this->dom->addChild(
157
            $cat,
158
            "tpCat",
159
            $this->std->tpcat,
160
            true
161
        );
162
        $this->dom->addChild(
163
            $cat,
164
            "indCatObito",
165
            $this->std->indcatobito,
166
            true
167
        );
168
        $this->dom->addChild(
169
            $cat,
170
            "dtObito",
171
            !empty($this->std->dtobito) ? $this->std->dtobito : null,
172
            false
173
        );
174
        $this->dom->addChild(
175
            $cat,
176
            "indComunPolicia",
177
            $this->std->indcomunpolicia,
178
            true
179
        );
180
        $this->dom->addChild(
181
            $cat,
182
            "codSitGeradora",
183
            !empty($this->std->codsitgeradora) ? $this->std->codsitgeradora : null,
184
            false
185
        );
186
        $this->dom->addChild(
187
            $cat,
188
            "iniciatCAT",
189
            $this->std->iniciatcat,
190
            true
191
        );
192
        $this->dom->addChild(
193
            $cat,
194
            "observacao",
195
            !empty($this->std->observacao) ? $this->std->observacao : null,
196
            false
197
        );
198
        $localAcidente = $this->dom->createElement("localAcidente");
199
        $this->dom->addChild(
200
            $localAcidente,
201
            "tpLocal",
202
            $this->std->tplocal,
203
            true
204
        );
205
        $this->dom->addChild(
206
            $localAcidente,
207
            "dscLocal",
208
            !empty($this->std->dsclocal) ? $this->std->dsclocal : null,
209
            false
210
        );
211
        $this->dom->addChild(
212
            $localAcidente,
213
            "dscLograd",
214
            !empty($this->std->dsclograd) ? $this->std->dsclograd : null,
215
            false
216
        );
217
        $this->dom->addChild(
218
            $localAcidente,
219
            "nrLograd",
220
            !empty($this->std->nrlograd) ? $this->std->nrlograd : null,
221
            false
222
        );
223
        $this->dom->addChild(
224
            $localAcidente,
225
            "codMunic",
226
            !empty($this->std->codmunic) ? $this->std->codmunic : null,
227
            false
228
        );
229
        $this->dom->addChild(
230
            $localAcidente,
231
            "uf",
232
            !empty($this->std->uf) ? $this->std->uf : null,
233
            false
234
        );
235
        $this->dom->addChild(
236
            $localAcidente,
237
            "cnpjLocalAcid",
238
            !empty($this->std->cnpjlocalacid) ? $this->std->cnpjlocalacid : null,
239
            false
240
        );
241
        $this->dom->addChild(
242
            $localAcidente,
243
            "pais",
244
            !empty($this->std->pais) ? $this->std->pais : null,
245
            false
246
        );
247
        $this->dom->addChild(
248
            $localAcidente,
249
            "codPostal",
250
            !empty($this->std->codpostal) ? $this->std->codpostal : null,
251
            false
252
        );
253
        $cat->appendChild($localAcidente);
254
        
255
        foreach ($this->std->parteatingida as $pa) {
256
            $parteAtingida = $this->dom->createElement("parteAtingida");
257
            $this->dom->addChild(
258
                $parteAtingida,
259
                "codParteAting",
260
                $pa->codparteating,
261
                true
262
            );
263
            $this->dom->addChild(
264
                $parteAtingida,
265
                "lateralidade",
266
                $pa->lateralidade,
267
                true
268
            );
269
            $cat->appendChild($parteAtingida);
270
        }
271
272
        foreach ($this->std->agentecausador as $pa) {
273
            $agenteCausador = $this->dom->createElement("agenteCausador");
274
            $this->dom->addChild(
275
                $agenteCausador,
276
                "codAgntCausador",
277
                $pa->codagntcausador,
278
                true
279
            );
280
            $cat->appendChild($agenteCausador);
281
        }
282
        if (!empty($this->std->atestado)) {
283
            $pa = $this->std->atestado;
284
            $atestado = $this->dom->createElement("atestado");
285
            $this->dom->addChild(
286
                $atestado,
287
                "codCNES",
288
                !empty($pa->codcnes) ? $pa->codcnes : null,
289
                false
290
            );
291
            $this->dom->addChild(
292
                $atestado,
293
                "dtAtendimento",
294
                $pa->dtatendimento,
295
                true
296
            );
297
            $this->dom->addChild(
298
                $atestado,
299
                "hrAtendimento",
300
                $pa->hratendimento,
301
                true
302
            );
303
            $this->dom->addChild(
304
                $atestado,
305
                "indInternacao",
306
                $pa->indinternacao,
307
                true
308
            );
309
            $this->dom->addChild(
310
                $atestado,
311
                "durTrat",
312
                $pa->durtrat,
313
                true
314
            );
315
            $this->dom->addChild(
316
                $atestado,
317
                "indAfast",
318
                $pa->indafast,
319
                true
320
            );
321
            $this->dom->addChild(
322
                $atestado,
323
                "dscLesao",
324
                !empty($pa->dsclesao) ? $pa->dsclesao : null,
325
                false
326
            );
327
            $this->dom->addChild(
328
                $atestado,
329
                "dscCompLesao",
330
                !empty($pa->dsccomplesao) ? $pa->dsccomplesao : null,
331
                false
332
            );
333
            $this->dom->addChild(
334
                $atestado,
335
                "diagProvavel",
336
                !empty($pa->diagprovavel) ? $pa->diagprovavel : null,
337
                false
338
            );
339
            $this->dom->addChild(
340
                $atestado,
341
                "codCID",
342
                $pa->codcid,
343
                true
344
            );
345
            $this->dom->addChild(
346
                $atestado,
347
                "observacao",
348
                !empty($pa->observacao) ? $pa->observacao : null,
349
                false
350
            );
351
            $emitente = $this->dom->createElement("emitente");
352
            $this->dom->addChild(
353
                $emitente,
354
                "nmEmit",
355
                $pa->nmemit,
356
                true
357
            );
358
            $this->dom->addChild(
359
                $emitente,
360
                "ideOC",
361
                $pa->ideoc,
362
                true
363
            );
364
            $this->dom->addChild(
365
                $emitente,
366
                "nrOc",
367
                $pa->nroc,
368
                true
369
            );
370
            $this->dom->addChild(
371
                $emitente,
372
                "ufOC",
373
                !empty($pa->ufoc) ? $pa->ufoc : null,
374
                true
375
            );
376
            $atestado->appendChild($emitente);
377
            $cat->appendChild($atestado);
378
        }
379
        if (!empty($this->std->catorigem)) {
380
            $pa = $this->std->catorigem;
381
            $catOrigem = $this->dom->createElement("catOrigem");
382
            $this->dom->addChild(
383
                $catOrigem,
384
                "dtCatOrig",
385
                $pa->dtcatorig,
386
                true
387
            );
388
            $this->dom->addChild(
389
                $catOrigem,
390
                "nrCatOrig",
391
                !empty($pa->nrcatorig) ? $pa->nrcatorig : null,
392
                false
393
            );
394
            $cat->appendChild($catOrigem);
395
        }
396
        $this->node->appendChild($cat);
397
        $this->eSocial->appendChild($this->node);
398
        //$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...
399
        $this->sign();
400
    }
401
}
402