Conditions | 30 |
Paths | 272 |
Total Lines | 203 |
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 |
||
404 | protected function toNodeS100() |
||
405 | { |
||
406 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
407 | //o idEvento pode variar de evento para evento |
||
408 | //então cada factory individualmente terá de construir o seu |
||
409 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
410 | $this->dom->addChild( |
||
411 | $ideEvento, |
||
412 | "tpAmb", |
||
413 | $this->tpAmb, |
||
414 | true |
||
415 | ); |
||
416 | $this->dom->addChild( |
||
417 | $ideEvento, |
||
418 | "procEmi", |
||
419 | $this->procEmi, |
||
420 | true |
||
421 | ); |
||
422 | $this->dom->addChild( |
||
423 | $ideEvento, |
||
424 | "verProc", |
||
425 | $this->verProc, |
||
426 | true |
||
427 | ); |
||
428 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
429 | $infoEmpregador = $this->dom->createElement("infoEmpregador"); |
||
430 | //periodo |
||
431 | $idePeriodo = $this->dom->createElement("idePeriodo"); |
||
432 | $this->dom->addChild( |
||
433 | $idePeriodo, |
||
434 | "iniValid", |
||
435 | $this->std->ideperiodo->inivalid, |
||
436 | true |
||
437 | ); |
||
438 | $this->dom->addChild( |
||
439 | $idePeriodo, |
||
440 | "fimValid", |
||
441 | !empty($this->std->ideperiodo->fimvalid) ? $this->std->ideperiodo->fimvalid : '', |
||
442 | false |
||
443 | ); |
||
444 | //infoCadastro |
||
445 | if (isset($this->std->infocadastro)) { |
||
446 | $cad = $this->std->infocadastro; |
||
447 | $infoCadastro = $this->dom->createElement("infoCadastro"); |
||
448 | $this->dom->addChild( |
||
449 | $infoCadastro, |
||
450 | "classTrib", |
||
451 | $cad->classtrib, |
||
452 | true |
||
453 | ); |
||
454 | $this->dom->addChild( |
||
455 | $infoCadastro, |
||
456 | "indCoop", |
||
457 | isset($cad->indcoop) ? $cad->indcoop : null, |
||
458 | ($this->tpInsc == 1) ? true : false //obrigatorio para pessoa juridica |
||
459 | ); |
||
460 | $this->dom->addChild( |
||
461 | $infoCadastro, |
||
462 | "indConstr", |
||
463 | isset($cad->indconstr) ? $cad->indconstr : null, |
||
464 | ($this->tpInsc == 1) ? true : false //obrigatorio para pessoa juridica |
||
465 | ); |
||
466 | $this->dom->addChild( |
||
467 | $infoCadastro, |
||
468 | "indDesFolha", |
||
469 | $cad->inddesfolha, |
||
470 | true |
||
471 | ); |
||
472 | $this->dom->addChild( |
||
473 | $infoCadastro, |
||
474 | "indOpcCP", |
||
475 | !empty($cad->indopccp) ? $cad->indopccp : null, |
||
476 | false |
||
477 | ); |
||
478 | $this->dom->addChild( |
||
479 | $infoCadastro, |
||
480 | "indPorte", |
||
481 | !empty($cad->indporte) ? $cad->indporte : null, |
||
482 | false |
||
483 | ); |
||
484 | $this->dom->addChild( |
||
485 | $infoCadastro, |
||
486 | "indOptRegEletron", |
||
487 | $cad->indoptregeletron, |
||
488 | true |
||
489 | ); |
||
490 | $this->dom->addChild( |
||
491 | $infoCadastro, |
||
492 | "cnpjEFR", |
||
493 | !empty($cad->cnpjefr) ? $cad->cnpjefr : null, |
||
494 | false |
||
495 | ); |
||
496 | } |
||
497 | if (isset($this->std->dadosisencao) && !empty($infoCadastro)) { |
||
498 | $cad = $this->std->dadosisencao; |
||
499 | $info = $this->dom->createElement("dadosIsencao"); |
||
500 | $this->dom->addChild( |
||
501 | $info, |
||
502 | "ideMinLei", |
||
503 | $cad->ideminlei, |
||
504 | true |
||
505 | ); |
||
506 | $this->dom->addChild( |
||
507 | $info, |
||
508 | "nrCertif", |
||
509 | $cad->nrcertif, |
||
510 | true |
||
511 | ); |
||
512 | $this->dom->addChild( |
||
513 | $info, |
||
514 | "dtEmisCertif", |
||
515 | $cad->dtemiscertif, |
||
516 | true |
||
517 | ); |
||
518 | $this->dom->addChild( |
||
519 | $info, |
||
520 | "dtVencCertif", |
||
521 | $cad->dtvenccertif, |
||
522 | true |
||
523 | ); |
||
524 | $this->dom->addChild( |
||
525 | $info, |
||
526 | "nrProtRenov", |
||
527 | !empty($cad->nrprotrenov) ? $cad->nrprotrenov : null, |
||
528 | false |
||
529 | ); |
||
530 | $this->dom->addChild( |
||
531 | $info, |
||
532 | "dtProtRenov", |
||
533 | !empty($cad->dtprotrenov) ? $cad->dtprotrenov : null, |
||
534 | false |
||
535 | ); |
||
536 | $this->dom->addChild( |
||
537 | $info, |
||
538 | "dtDou", |
||
539 | !empty($cad->dtdou) ? $cad->dtdou : null, |
||
540 | false |
||
541 | ); |
||
542 | $this->dom->addChild( |
||
543 | $info, |
||
544 | "pagDou", |
||
545 | !empty($cad->pagdou) ? $cad->pagdou : null, |
||
546 | false |
||
547 | ); |
||
548 | $infoCadastro->appendChild($info); |
||
549 | } |
||
550 | if (isset($this->std->infoorginternacional) && !empty($infoCadastro)) { |
||
551 | $cad = $this->std->infoorginternacional; |
||
552 | $info = $this->dom->createElement("infoOrgInternacional"); |
||
553 | $this->dom->addChild( |
||
554 | $info, |
||
555 | "indAcordoIsenMulta", |
||
556 | $cad->indacordoisenmulta, |
||
557 | true |
||
558 | ); |
||
559 | $infoCadastro->appendChild($info); |
||
560 | } |
||
561 | if (isset($this->std->novavalidade)) { |
||
562 | $sh = $this->std->novavalidade; |
||
563 | $novavalidade = $this->dom->createElement("novaValidade"); |
||
564 | $this->dom->addChild( |
||
565 | $novavalidade, |
||
566 | "iniValid", |
||
567 | $sh->inivalid, |
||
568 | true |
||
569 | ); |
||
570 | $this->dom->addChild( |
||
571 | $novavalidade, |
||
572 | "fimValid", |
||
573 | !empty($sh->fimValid) ? $sh->fimValid : null, |
||
574 | false |
||
575 | ); |
||
576 | } |
||
577 | switch ($this->std->modo) { |
||
578 | case "ALT": |
||
579 | $node = $this->dom->createElement("alteracao"); |
||
580 | $node->appendChild($idePeriodo); |
||
581 | if (isset($infoComplementares) && isset($infoCadastro)) { |
||
582 | $infoCadastro->appendChild($infoComplementares); |
||
583 | } |
||
584 | isset($infoCadastro) ? $node->appendChild($infoCadastro) : null; |
||
585 | isset($novavalidade) ? $node->appendChild($novavalidade) : null; |
||
586 | break; |
||
587 | case "EXC": |
||
588 | $node = $this->dom->createElement("exclusao"); |
||
589 | $node->appendChild($idePeriodo); |
||
590 | break; |
||
591 | case "INC": |
||
592 | default: |
||
593 | $node = $this->dom->createElement("inclusao"); |
||
594 | $node->appendChild($idePeriodo); |
||
595 | if (isset($infoComplementares) && isset($infoCadastro)) { |
||
596 | $infoCadastro->appendChild($infoComplementares); |
||
597 | } |
||
598 | isset($infoCadastro) ? $node->appendChild($infoCadastro) : null; |
||
599 | } |
||
600 | $infoEmpregador->appendChild($node); |
||
601 | $this->node->appendChild($infoEmpregador); |
||
602 | //finalização do xml |
||
603 | $this->eSocial->appendChild($this->node); |
||
604 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
605 | $this->sign(); |
||
606 | } |
||
607 | } |
||
608 |
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: