Conditions | 48 |
Paths | > 20000 |
Total Lines | 604 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
10 | protected function toNode250() |
||
11 | { |
||
12 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
|
|||
13 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
14 | $this->dom->addChild( |
||
15 | $ideEvento, |
||
16 | "indRetif", |
||
17 | $this->std->indretif, |
||
18 | true |
||
19 | ); |
||
20 | $this->dom->addChild( |
||
21 | $ideEvento, |
||
22 | "nrRecibo", |
||
23 | ! empty($this->std->nrrecibo) ? $this->std->nrrecibo : null, |
||
24 | false |
||
25 | ); |
||
26 | $this->dom->addChild( |
||
27 | $ideEvento, |
||
28 | "tpAmb", |
||
29 | $this->tpAmb, |
||
30 | true |
||
31 | ); |
||
32 | $this->dom->addChild( |
||
33 | $ideEvento, |
||
34 | "procEmi", |
||
35 | $this->procEmi, |
||
36 | true |
||
37 | ); |
||
38 | $this->dom->addChild( |
||
39 | $ideEvento, |
||
40 | "verProc", |
||
41 | $this->verProc, |
||
42 | true |
||
43 | ); |
||
44 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
45 | $ideTrabalhador = $this->dom->createElement("ideTrabalhador"); |
||
46 | $this->dom->addChild( |
||
47 | $ideTrabalhador, |
||
48 | "cpfTrab", |
||
49 | $this->std->cpftrab, |
||
50 | true |
||
51 | ); |
||
52 | $this->node->appendChild($ideTrabalhador); |
||
53 | $alteracao = $this->dom->createElement("alteracao"); |
||
54 | $this->dom->addChild( |
||
55 | $alteracao, |
||
56 | "dtAlteracao", |
||
57 | $this->std->dtalteracao, |
||
58 | true |
||
59 | ); |
||
60 | $dadosTrabalhador = $this->dom->createElement("dadosTrabalhador"); |
||
61 | $this->dom->addChild( |
||
62 | $dadosTrabalhador, |
||
63 | "nisTrab", |
||
64 | !empty($this->std->nistrab) ? $this->std->nistrab : null, |
||
65 | false |
||
66 | ); |
||
67 | $this->dom->addChild( |
||
68 | $dadosTrabalhador, |
||
69 | "nmTrab", |
||
70 | $this->std->nmtrab, |
||
71 | true |
||
72 | ); |
||
73 | $this->dom->addChild( |
||
74 | $dadosTrabalhador, |
||
75 | "sexo", |
||
76 | $this->std->sexo, |
||
77 | true |
||
78 | ); |
||
79 | $this->dom->addChild( |
||
80 | $dadosTrabalhador, |
||
81 | "racaCor", |
||
82 | $this->std->racacor, |
||
83 | true |
||
84 | ); |
||
85 | $this->dom->addChild( |
||
86 | $dadosTrabalhador, |
||
87 | "estCiv", |
||
88 | !empty($this->std->estciv) ? $this->std->estciv : null, |
||
89 | false |
||
90 | ); |
||
91 | $this->dom->addChild( |
||
92 | $dadosTrabalhador, |
||
93 | "grauInstr", |
||
94 | $this->std->grauinstr, |
||
95 | true |
||
96 | ); |
||
97 | $this->dom->addChild( |
||
98 | $dadosTrabalhador, |
||
99 | "nmSoc", |
||
100 | !empty($this->std->nmsoc) ? $this->std->nmsoc : null, |
||
101 | false |
||
102 | ); |
||
103 | $nascimento = $this->dom->createElement("nascimento"); |
||
104 | $this->dom->addChild( |
||
105 | $nascimento, |
||
106 | "dtNascto", |
||
107 | $this->std->nascimento->dtnascto, |
||
108 | true |
||
109 | ); |
||
110 | $this->dom->addChild( |
||
111 | $nascimento, |
||
112 | "codMunic", |
||
113 | !empty($this->std->nascimento->codmunic) ? $this->std->nascimento->codmunic : null, |
||
114 | false |
||
115 | ); |
||
116 | $this->dom->addChild( |
||
117 | $nascimento, |
||
118 | "uf", |
||
119 | !empty($this->std->nascimento->uf) ? $this->std->nascimento->uf : null, |
||
120 | false |
||
121 | ); |
||
122 | $this->dom->addChild( |
||
123 | $nascimento, |
||
124 | "paisNascto", |
||
125 | $this->std->nascimento->paisnascto, |
||
126 | true |
||
127 | ); |
||
128 | $this->dom->addChild( |
||
129 | $nascimento, |
||
130 | "paisNac", |
||
131 | $this->std->nascimento->paisnac, |
||
132 | true |
||
133 | ); |
||
134 | $this->dom->addChild( |
||
135 | $nascimento, |
||
136 | "nmMae", |
||
137 | !empty($this->std->nascimento->nmmae) ? $this->std->nascimento->nmmae : null, |
||
138 | false |
||
139 | ); |
||
140 | $this->dom->addChild( |
||
141 | $nascimento, |
||
142 | "nmPai", |
||
143 | !empty($this->std->nascimento->nmpai) ? $this->std->nascimento->nmpai : null, |
||
144 | false |
||
145 | ); |
||
146 | $dadosTrabalhador->appendChild($nascimento); |
||
147 | $documentos = null; |
||
148 | if (!empty($this->std->ctps)) { |
||
149 | $ct = $this->std->ctps; |
||
150 | $documentos = $this->dom->createElement("documentos"); |
||
151 | $CTPS = $this->dom->createElement("CTPS"); |
||
152 | $this->dom->addChild( |
||
153 | $CTPS, |
||
154 | "nrCtps", |
||
155 | $ct->nrctps, |
||
156 | true |
||
157 | ); |
||
158 | $this->dom->addChild( |
||
159 | $CTPS, |
||
160 | "serieCtps", |
||
161 | $ct->seriectps, |
||
162 | true |
||
163 | ); |
||
164 | $this->dom->addChild( |
||
165 | $CTPS, |
||
166 | "ufCtps", |
||
167 | $ct->ufctps, |
||
168 | true |
||
169 | ); |
||
170 | $documentos->appendChild($CTPS); |
||
171 | } |
||
172 | if (!empty($this->std->ric)) { |
||
173 | $ct = $this->std->ric; |
||
174 | if (is_null($documentos)) { |
||
175 | $documentos = $this->dom->createElement("documentos"); |
||
176 | } |
||
177 | $RIC = $this->dom->createElement("RIC"); |
||
178 | $this->dom->addChild( |
||
179 | $RIC, |
||
180 | "nrRic", |
||
181 | $ct->nrric, |
||
182 | true |
||
183 | ); |
||
184 | $this->dom->addChild( |
||
185 | $RIC, |
||
186 | "orgaoEmissor", |
||
187 | $ct->orgaoemissor, |
||
188 | true |
||
189 | ); |
||
190 | $this->dom->addChild( |
||
191 | $RIC, |
||
192 | "dtExped", |
||
193 | !empty($ct->dtexped) ? $ct->dtexped : null, |
||
194 | false |
||
195 | ); |
||
196 | $documentos->appendChild($RIC); |
||
197 | } |
||
198 | if (!empty($this->std->rg)) { |
||
199 | $ct = $this->std->rg; |
||
200 | if (is_null($documentos)) { |
||
201 | $documentos = $this->dom->createElement("documentos"); |
||
202 | } |
||
203 | $RG = $this->dom->createElement("RG"); |
||
204 | $this->dom->addChild( |
||
205 | $RG, |
||
206 | "nrRg", |
||
207 | $ct->nrrg, |
||
208 | true |
||
209 | ); |
||
210 | $this->dom->addChild( |
||
211 | $RG, |
||
212 | "orgaoEmissor", |
||
213 | $ct->orgaoemissor, |
||
214 | true |
||
215 | ); |
||
216 | $this->dom->addChild( |
||
217 | $RG, |
||
218 | "dtExped", |
||
219 | !empty($ct->dtexped) ? $ct->dtexped : null, |
||
220 | false |
||
221 | ); |
||
222 | $documentos->appendChild($RG); |
||
223 | } |
||
224 | if (!empty($this->std->rne)) { |
||
225 | $ct = $this->std->rne; |
||
226 | if (is_null($documentos)) { |
||
227 | $documentos = $this->dom->createElement("documentos"); |
||
228 | } |
||
229 | $RNE = $this->dom->createElement("RNE"); |
||
230 | $this->dom->addChild( |
||
231 | $RNE, |
||
232 | "nrRne", |
||
233 | $ct->nrrne, |
||
234 | true |
||
235 | ); |
||
236 | $this->dom->addChild( |
||
237 | $RNE, |
||
238 | "orgaoEmissor", |
||
239 | $ct->orgaoemissor, |
||
240 | true |
||
241 | ); |
||
242 | $this->dom->addChild( |
||
243 | $RNE, |
||
244 | "dtExped", |
||
245 | !empty($ct->dtexped) ? $ct->dtexped : null, |
||
246 | false |
||
247 | ); |
||
248 | $documentos->appendChild($RNE); |
||
249 | } |
||
250 | if (!empty($this->std->oc)) { |
||
251 | $ct = $this->std->oc; |
||
252 | if (is_null($documentos)) { |
||
253 | $documentos = $this->dom->createElement("documentos"); |
||
254 | } |
||
255 | $OC = $this->dom->createElement("OC"); |
||
256 | $this->dom->addChild( |
||
257 | $OC, |
||
258 | "nrOc", |
||
259 | $ct->nroc, |
||
260 | true |
||
261 | ); |
||
262 | $this->dom->addChild( |
||
263 | $OC, |
||
264 | "orgaoEmissor", |
||
265 | $ct->orgaoemissor, |
||
266 | true |
||
267 | ); |
||
268 | $this->dom->addChild( |
||
269 | $OC, |
||
270 | "dtExped", |
||
271 | !empty($ct->dtexped) ? $ct->dtexped : null, |
||
272 | false |
||
273 | ); |
||
274 | $this->dom->addChild( |
||
275 | $OC, |
||
276 | "dtValid", |
||
277 | !empty($ct->dtvalid) ? $ct->dtvalid : null, |
||
278 | false |
||
279 | ); |
||
280 | $documentos->appendChild($OC); |
||
281 | } |
||
282 | if (!empty($this->std->cnh)) { |
||
283 | $ct = $this->std->cnh; |
||
284 | if (is_null($documentos)) { |
||
285 | $documentos = $this->dom->createElement("documentos"); |
||
286 | } |
||
287 | $CNH = $this->dom->createElement("CNH"); |
||
288 | $this->dom->addChild( |
||
289 | $CNH, |
||
290 | "nrRegCnh", |
||
291 | $ct->nrregcnh, |
||
292 | true |
||
293 | ); |
||
294 | $this->dom->addChild( |
||
295 | $CNH, |
||
296 | "dtExped", |
||
297 | !empty($ct->dtexped) ? $ct->dtexped : null, |
||
298 | false |
||
299 | ); |
||
300 | $this->dom->addChild( |
||
301 | $CNH, |
||
302 | "ufCnh", |
||
303 | $ct->ufcnh, |
||
304 | true |
||
305 | ); |
||
306 | $this->dom->addChild( |
||
307 | $CNH, |
||
308 | "dtValid", |
||
309 | $ct->dtvalid, |
||
310 | true |
||
311 | ); |
||
312 | $this->dom->addChild( |
||
313 | $CNH, |
||
314 | "dtPriHab", |
||
315 | !empty($ct->dtprihab) ? $ct->dtprihab : null, |
||
316 | false |
||
317 | ); |
||
318 | $this->dom->addChild( |
||
319 | $CNH, |
||
320 | "categoriaCnh", |
||
321 | $ct->categoriacnh, |
||
322 | true |
||
323 | ); |
||
324 | $documentos->appendChild($CNH); |
||
325 | } |
||
326 | if (!is_null($documentos)) { |
||
327 | $dadosTrabalhador->appendChild($documentos); |
||
328 | } |
||
329 | |||
330 | $endereco = $this->dom->createElement("endereco"); |
||
331 | if (!empty($this->std->brasil)) { |
||
332 | $ct = $this->std->brasil; |
||
333 | $brasil = $this->dom->createElement("brasil"); |
||
334 | $this->dom->addChild( |
||
335 | $brasil, |
||
336 | "tpLograd", |
||
337 | $ct->tplograd, |
||
338 | true |
||
339 | ); |
||
340 | $this->dom->addChild( |
||
341 | $brasil, |
||
342 | "dscLograd", |
||
343 | $ct->dsclograd, |
||
344 | true |
||
345 | ); |
||
346 | $this->dom->addChild( |
||
347 | $brasil, |
||
348 | "nrLograd", |
||
349 | $ct->nrlograd, |
||
350 | true |
||
351 | ); |
||
352 | $this->dom->addChild( |
||
353 | $brasil, |
||
354 | "complemento", |
||
355 | !empty($ct->complemento) ? $ct->complemento : null, |
||
356 | false |
||
357 | ); |
||
358 | $this->dom->addChild( |
||
359 | $brasil, |
||
360 | "bairro", |
||
361 | !empty($ct->bairro) ? $ct->bairro : null, |
||
362 | false |
||
363 | ); |
||
364 | $this->dom->addChild( |
||
365 | $brasil, |
||
366 | "cep", |
||
367 | $ct->cep, |
||
368 | true |
||
369 | ); |
||
370 | $this->dom->addChild( |
||
371 | $brasil, |
||
372 | "codMunic", |
||
373 | $ct->codmunic, |
||
374 | true |
||
375 | ); |
||
376 | $this->dom->addChild( |
||
377 | $brasil, |
||
378 | "uf", |
||
379 | $ct->uf, |
||
380 | true |
||
381 | ); |
||
382 | $endereco->appendChild($brasil); |
||
383 | } elseif (!empty($this->std->exterior)) { |
||
384 | $ct = $this->std->exterior; |
||
385 | $exterior = $this->dom->createElement("exterior"); |
||
386 | $this->dom->addChild( |
||
387 | $exterior, |
||
388 | "paisResid", |
||
389 | $ct->paisresid, |
||
390 | true |
||
391 | ); |
||
392 | $this->dom->addChild( |
||
393 | $exterior, |
||
394 | "dscLograd", |
||
395 | $ct->dsclograd, |
||
396 | true |
||
397 | ); |
||
398 | $this->dom->addChild( |
||
399 | $exterior, |
||
400 | "nrLograd", |
||
401 | $ct->nrlograd, |
||
402 | true |
||
403 | ); |
||
404 | $this->dom->addChild( |
||
405 | $exterior, |
||
406 | "complemento", |
||
407 | !empty($ct->complemento) ? $ct->complemento : null, |
||
408 | false |
||
409 | ); |
||
410 | $this->dom->addChild( |
||
411 | $exterior, |
||
412 | "bairro", |
||
413 | !empty($ct->bairro) ? $ct->bairro : null, |
||
414 | false |
||
415 | ); |
||
416 | $this->dom->addChild( |
||
417 | $exterior, |
||
418 | "nmCid", |
||
419 | $ct->nmcid, |
||
420 | true |
||
421 | ); |
||
422 | $this->dom->addChild( |
||
423 | $exterior, |
||
424 | "codPostal", |
||
425 | !empty($ct->codpostal) ? $ct->codpostal : null, |
||
426 | false |
||
427 | ); |
||
428 | $endereco->appendChild($exterior); |
||
429 | } |
||
430 | $dadosTrabalhador->appendChild($endereco); |
||
431 | |||
432 | if (!empty($this->std->trabestrangeiro)) { |
||
433 | $ct = $this->std->trabestrangeiro; |
||
434 | $trabEstrangeiro = $this->dom->createElement("trabEstrangeiro"); |
||
435 | $this->dom->addChild( |
||
436 | $trabEstrangeiro, |
||
437 | "dtChegada", |
||
438 | $ct->dtchegada, |
||
439 | true |
||
440 | ); |
||
441 | $this->dom->addChild( |
||
442 | $trabEstrangeiro, |
||
443 | "classTrabEstrang", |
||
444 | $ct->classtrabestrang, |
||
445 | true |
||
446 | ); |
||
447 | $this->dom->addChild( |
||
448 | $trabEstrangeiro, |
||
449 | "casadoBr", |
||
450 | $ct->casadobr, |
||
451 | true |
||
452 | ); |
||
453 | $this->dom->addChild( |
||
454 | $trabEstrangeiro, |
||
455 | "filhosBr", |
||
456 | $ct->filhosbr, |
||
457 | true |
||
458 | ); |
||
459 | $dadosTrabalhador->appendChild($trabEstrangeiro); |
||
460 | } |
||
461 | |||
462 | if (!empty($this->std->infodeficiencia)) { |
||
463 | $ct = $this->std->infodeficiencia; |
||
464 | $infoDeficiencia = $this->dom->createElement("infoDeficiencia"); |
||
465 | $this->dom->addChild( |
||
466 | $infoDeficiencia, |
||
467 | "defFisica", |
||
468 | $ct->deffisica, |
||
469 | true |
||
470 | ); |
||
471 | $this->dom->addChild( |
||
472 | $infoDeficiencia, |
||
473 | "defVisual", |
||
474 | $ct->defvisual, |
||
475 | true |
||
476 | ); |
||
477 | $this->dom->addChild( |
||
478 | $infoDeficiencia, |
||
479 | "defAuditiva", |
||
480 | $ct->defauditiva, |
||
481 | true |
||
482 | ); |
||
483 | $this->dom->addChild( |
||
484 | $infoDeficiencia, |
||
485 | "defMental", |
||
486 | $ct->defmental, |
||
487 | true |
||
488 | ); |
||
489 | $this->dom->addChild( |
||
490 | $infoDeficiencia, |
||
491 | "defIntelectual", |
||
492 | $ct->defintelectual, |
||
493 | true |
||
494 | ); |
||
495 | $this->dom->addChild( |
||
496 | $infoDeficiencia, |
||
497 | "reabReadap", |
||
498 | $ct->reabreadap, |
||
499 | true |
||
500 | ); |
||
501 | $this->dom->addChild( |
||
502 | $infoDeficiencia, |
||
503 | "infoCota", |
||
504 | !empty($ct->infocota) ? $ct->infocota : null, |
||
505 | false |
||
506 | ); |
||
507 | $this->dom->addChild( |
||
508 | $infoDeficiencia, |
||
509 | "observacao", |
||
510 | !empty($ct->observacao) ? $ct->observacao : null, |
||
511 | false |
||
512 | ); |
||
513 | $dadosTrabalhador->appendChild($infoDeficiencia); |
||
514 | } |
||
515 | |||
516 | if (!empty($this->std->dependente)) { |
||
517 | foreach ($this->std->dependente as $dep) { |
||
518 | $dependente = $this->dom->createElement("dependente"); |
||
519 | $this->dom->addChild( |
||
520 | $dependente, |
||
521 | "tpDep", |
||
522 | $dep->tpdep, |
||
523 | true |
||
524 | ); |
||
525 | $this->dom->addChild( |
||
526 | $dependente, |
||
527 | "nmDep", |
||
528 | $dep->nmdep, |
||
529 | true |
||
530 | ); |
||
531 | $this->dom->addChild( |
||
532 | $dependente, |
||
533 | "dtNascto", |
||
534 | $dep->dtnascto, |
||
535 | true |
||
536 | ); |
||
537 | $this->dom->addChild( |
||
538 | $dependente, |
||
539 | "cpfDep", |
||
540 | !empty($dep->cpfdep) ? $dep->cpfdep : null, |
||
541 | false |
||
542 | ); |
||
543 | $this->dom->addChild( |
||
544 | $dependente, |
||
545 | "depIRRF", |
||
546 | $dep->depirrf, |
||
547 | true |
||
548 | ); |
||
549 | $this->dom->addChild( |
||
550 | $dependente, |
||
551 | "depSF", |
||
552 | $dep->depsf, |
||
553 | true |
||
554 | ); |
||
555 | $this->dom->addChild( |
||
556 | $dependente, |
||
557 | "incTrab", |
||
558 | $dep->inctrab, |
||
559 | true |
||
560 | ); |
||
561 | $dadosTrabalhador->appendChild($dependente); |
||
562 | } |
||
563 | } |
||
564 | |||
565 | if (!empty($this->std->aposentadoria)) { |
||
566 | $aposentadoria = $this->dom->createElement("aposentadoria"); |
||
567 | $this->dom->addChild( |
||
568 | $aposentadoria, |
||
569 | "trabAposent", |
||
570 | $this->std->aposentadoria->trabaposent, |
||
571 | true |
||
572 | ); |
||
573 | $dadosTrabalhador->appendChild($aposentadoria); |
||
574 | } |
||
575 | |||
576 | if (!empty($this->std->contato)) { |
||
577 | $ct = $this->std->contato; |
||
578 | $contato = $this->dom->createElement("contato"); |
||
579 | $this->dom->addChild( |
||
580 | $contato, |
||
581 | "fonePrinc", |
||
582 | !empty($ct->foneprinc) ? $ct->foneprinc : null, |
||
583 | false |
||
584 | ); |
||
585 | $this->dom->addChild( |
||
586 | $contato, |
||
587 | "foneAlternat", |
||
588 | !empty($ct->fonealternat) ? $ct->fonealternat : null, |
||
589 | false |
||
590 | ); |
||
591 | $this->dom->addChild( |
||
592 | $contato, |
||
593 | "emailPrinc", |
||
594 | !empty($ct->emailprinc) ? $ct->emailprinc : null, |
||
595 | false |
||
596 | ); |
||
597 | $this->dom->addChild( |
||
598 | $contato, |
||
599 | "emailAlternat", |
||
600 | !empty($ct->emailalternat) ? $ct->emailalternat : null, |
||
601 | false |
||
602 | ); |
||
603 | $dadosTrabalhador->appendChild($contato); |
||
604 | } |
||
605 | |||
606 | $alteracao->appendChild($dadosTrabalhador); |
||
607 | |||
608 | $this->node->appendChild($alteracao); |
||
609 | //finalização do xml |
||
610 | $this->eSocial->appendChild($this->node); |
||
611 | //$this->xml = $this->dom->saveXML($this->eSocial);; |
||
612 | $this->sign(); |
||
613 | } |
||
614 | |||
623 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: