Conditions | 6 |
Paths | 2 |
Total Lines | 161 |
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 |
||
332 | protected function toNodeS100() |
||
333 | { |
||
334 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
335 | //o idEvento pode variar de evento para evento |
||
336 | //então cada factory individualmente terá de construir o seu |
||
337 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
338 | $this->dom->addChild( |
||
339 | $ideEvento, |
||
340 | "indRetif", |
||
341 | $this->std->indretif, |
||
342 | true |
||
343 | ); |
||
344 | $this->dom->addChild( |
||
345 | $ideEvento, |
||
346 | "tpAmb", |
||
347 | $this->tpAmb, |
||
348 | true |
||
349 | ); |
||
350 | $this->dom->addChild( |
||
351 | $ideEvento, |
||
352 | "procEmi", |
||
353 | $this->procEmi, |
||
354 | true |
||
355 | ); |
||
356 | $this->dom->addChild( |
||
357 | $ideEvento, |
||
358 | "verProc", |
||
359 | $this->verProc, |
||
360 | true |
||
361 | ); |
||
362 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
363 | $ideVinculo = $this->dom->createElement("ideVinculo"); |
||
364 | $this->dom->addChild( |
||
365 | $ideVinculo, |
||
366 | "cpfTrab", |
||
367 | $this->std->idevinculo->cpftrab, |
||
368 | true |
||
369 | ); |
||
370 | $this->dom->addChild( |
||
371 | $ideVinculo, |
||
372 | "matricula", |
||
373 | !empty($this->std->idevinculo->matricula) ? $this->std->idevinculo->matricula : null, |
||
374 | false |
||
375 | ); |
||
376 | $this->node->appendChild($ideVinculo); |
||
377 | |||
378 | $exMedOcup = $this->dom->createElement("exMedOcup"); |
||
379 | $this->dom->addChild( |
||
380 | $exMedOcup, |
||
381 | "tpExameOcup", |
||
382 | $this->std->exmedocup->tpexameocup, |
||
383 | true |
||
384 | ); |
||
385 | $stdaso = $this->std->exmedocup->aso; |
||
386 | $aso = $this->dom->createElement("aso"); |
||
387 | $this->dom->addChild( |
||
388 | $aso, |
||
389 | "dtAso", |
||
390 | $stdaso->dtaso, |
||
391 | true |
||
392 | ); |
||
393 | $this->dom->addChild( |
||
394 | $aso, |
||
395 | "resAso", |
||
396 | $stdaso->resaso, |
||
397 | true |
||
398 | ); |
||
399 | |||
400 | foreach ($this->std->exmedocup->aso->exame as $exa) { |
||
401 | $exame = $this->dom->createElement("exame"); |
||
402 | $this->dom->addChild( |
||
403 | $exame, |
||
404 | "dtExm", |
||
405 | $exa->dtexm, |
||
406 | true |
||
407 | ); |
||
408 | $this->dom->addChild( |
||
409 | $exame, |
||
410 | "procRealizado", |
||
411 | $exa->procrealizado, |
||
412 | true |
||
413 | ); |
||
414 | $this->dom->addChild( |
||
415 | $exame, |
||
416 | "obsProc", |
||
417 | !empty($exa->obsproc) ? $exa->obsproc : null, |
||
418 | false |
||
419 | ); |
||
420 | $this->dom->addChild( |
||
421 | $exame, |
||
422 | "ordExame", |
||
423 | $exa->ordexame, |
||
424 | true |
||
425 | ); |
||
426 | $this->dom->addChild( |
||
427 | $exame, |
||
428 | "indResult", |
||
429 | !empty($exa->indresult) ? $exa->indresult : null, |
||
430 | false |
||
431 | ); |
||
432 | $aso->appendChild($exame); |
||
433 | } |
||
434 | |||
435 | $stdmed = $this->std->exmedocup->aso->medico; |
||
436 | $medico = $this->dom->createElement("medico"); |
||
437 | $this->dom->addChild( |
||
438 | $medico, |
||
439 | "nmMed", |
||
440 | $stdmed->nmmed, |
||
441 | true |
||
442 | ); |
||
443 | $this->dom->addChild( |
||
444 | $medico, |
||
445 | "nrCRM", |
||
446 | $stdmed->nrcrm, |
||
447 | true |
||
448 | ); |
||
449 | $this->dom->addChild( |
||
450 | $medico, |
||
451 | "ufCRM", |
||
452 | $stdmed->ufcrm, |
||
453 | true |
||
454 | ); |
||
455 | $aso->appendChild($medico); |
||
456 | $exMedOcup->appendChild($aso); |
||
457 | |||
458 | $stdmon = $this->std->exmedocup->respmonit; |
||
459 | $monit = $this->dom->createElement("respMonit"); |
||
460 | $this->dom->addChild( |
||
461 | $monit, |
||
462 | "cpfResp", |
||
463 | !empty($stdmon->cpfresp) ? $stdmon->cpfresp : null, |
||
464 | false |
||
465 | ); |
||
466 | $this->dom->addChild( |
||
467 | $monit, |
||
468 | "nmResp", |
||
469 | $stdmon->nmresp, |
||
470 | true |
||
471 | ); |
||
472 | $this->dom->addChild( |
||
473 | $monit, |
||
474 | "nrCRM", |
||
475 | $stdmon->nrcrm, |
||
476 | true |
||
477 | ); |
||
478 | $this->dom->addChild( |
||
479 | $monit, |
||
480 | "ufCRM", |
||
481 | $stdmon->ufcrm, |
||
482 | true |
||
483 | ); |
||
484 | $exMedOcup->appendChild($monit); |
||
485 | $this->node->appendChild($exMedOcup); |
||
486 | |||
487 | //finalização do xml |
||
488 | $this->eSocial->appendChild($this->node); |
||
489 | |||
490 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
491 | $this->sign(); |
||
492 | } |
||
493 | } |
||
494 |
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: