| Conditions | 11 |
| Paths | 42 |
| Total Lines | 145 |
| 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 | //o idEvento pode variar de evento para evento |
||
| 14 | //então cada factory individualmente terá de construir o seu |
||
| 15 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
| 16 | $this->dom->addChild( |
||
| 17 | $ideEvento, |
||
| 18 | "tpAmb", |
||
| 19 | $this->tpAmb, |
||
| 20 | true |
||
| 21 | ); |
||
| 22 | $this->dom->addChild( |
||
| 23 | $ideEvento, |
||
| 24 | "procEmi", |
||
| 25 | $this->procEmi, |
||
| 26 | true |
||
| 27 | ); |
||
| 28 | $this->dom->addChild( |
||
| 29 | $ideEvento, |
||
| 30 | "verProc", |
||
| 31 | $this->verProc, |
||
| 32 | true |
||
| 33 | ); |
||
| 34 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
| 35 | |||
| 36 | $ide = $this->dom->createElement("ideCargo"); |
||
| 37 | $this->dom->addChild( |
||
| 38 | $ide, |
||
| 39 | "codCargo", |
||
| 40 | $this->std->codcargo, |
||
| 41 | true |
||
| 42 | ); |
||
| 43 | $this->dom->addChild( |
||
| 44 | $ide, |
||
| 45 | "iniValid", |
||
| 46 | $this->std->inivalid, |
||
| 47 | true |
||
| 48 | ); |
||
| 49 | $this->dom->addChild( |
||
| 50 | $ide, |
||
| 51 | "fimValid", |
||
| 52 | ! empty($this->std->fimvalid) ? $this->std->fimvalid : null, |
||
| 53 | false |
||
| 54 | ); |
||
| 55 | |||
| 56 | |||
| 57 | if (!empty($this->std->dadoscargo)) { |
||
| 58 | $da = $this->std->dadoscargo; |
||
| 59 | $dados = $this->dom->createElement("dadosCargo"); |
||
| 60 | $this->dom->addChild( |
||
| 61 | $dados, |
||
| 62 | "nmCargo", |
||
| 63 | $da->nmcargo, |
||
| 64 | true |
||
| 65 | ); |
||
| 66 | $this->dom->addChild( |
||
| 67 | $dados, |
||
| 68 | "codCBO", |
||
| 69 | $da->codcbo, |
||
| 70 | true |
||
| 71 | ); |
||
| 72 | if (!empty($da->cargopublico)) { |
||
| 73 | $cpub = $this->dom->createElement("cargoPublico"); |
||
| 74 | $this->dom->addChild( |
||
| 75 | $cpub, |
||
| 76 | "acumCargo", |
||
| 77 | $da->cargopublico->acumcargo, |
||
| 78 | true |
||
| 79 | ); |
||
| 80 | $this->dom->addChild( |
||
| 81 | $cpub, |
||
| 82 | "contagemEsp", |
||
| 83 | $da->cargopublico->contagemesp, |
||
| 84 | true |
||
| 85 | ); |
||
| 86 | $this->dom->addChild( |
||
| 87 | $cpub, |
||
| 88 | "dedicExcl", |
||
| 89 | $da->cargopublico->dedicexcl, |
||
| 90 | true |
||
| 91 | ); |
||
| 92 | $lei = $this->dom->createElement("leiCargo"); |
||
| 93 | $this->dom->addChild( |
||
| 94 | $lei, |
||
| 95 | "nrLei", |
||
| 96 | $da->cargopublico->nrlei, |
||
| 97 | true |
||
| 98 | ); |
||
| 99 | $this->dom->addChild( |
||
| 100 | $lei, |
||
| 101 | "dtLei", |
||
| 102 | $da->cargopublico->dtlei, |
||
| 103 | true |
||
| 104 | ); |
||
| 105 | $this->dom->addChild( |
||
| 106 | $lei, |
||
| 107 | "sitCargo", |
||
| 108 | $da->cargopublico->sitcargo, |
||
| 109 | true |
||
| 110 | ); |
||
| 111 | $cpub->appendChild($lei); |
||
| 112 | $dados->appendChild($cpub); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | if (!empty($this->std->novavalidade)) { |
||
| 117 | $nova = $this->dom->createElement("novaValidade"); |
||
| 118 | $this->dom->addChild( |
||
| 119 | $nova, |
||
| 120 | "iniValid", |
||
| 121 | $this->std->novavalidade->inivalid, |
||
| 122 | true |
||
| 123 | ); |
||
| 124 | $this->dom->addChild( |
||
| 125 | $nova, |
||
| 126 | "fimValid", |
||
| 127 | ! empty($this->std->novavalidade->fimvalid) |
||
| 128 | ? $this->std->novavalidade->fimvalid |
||
| 129 | : null, |
||
| 130 | false |
||
| 131 | ); |
||
| 132 | } |
||
| 133 | |||
| 134 | $info = $this->dom->createElement("infoCargo"); |
||
| 135 | //seleção do modo |
||
| 136 | if ($this->std->modo == 'INC') { |
||
| 137 | $node = $this->dom->createElement("inclusao"); |
||
| 138 | $node->appendChild($ide); |
||
| 139 | isset($dados) ? $node->appendChild($dados) : null; |
||
| 140 | } elseif ($this->std->modo == 'ALT') { |
||
| 141 | $node = $this->dom->createElement("alteracao"); |
||
| 142 | $node->appendChild($ide); |
||
| 143 | isset($dados) ? $node->appendChild($dados): null; |
||
| 144 | isset($nova) ? $node->appendChild($nova): null; |
||
| 145 | } else { |
||
| 146 | $node = $this->dom->createElement("exclusao"); |
||
| 147 | $node->appendChild($ide); |
||
| 148 | } |
||
| 149 | $info->appendChild($node); |
||
| 150 | $this->node->appendChild($info); |
||
| 151 | $this->eSocial->appendChild($this->node); |
||
| 152 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
| 153 | $this->sign(); |
||
| 154 | } |
||
| 155 | |||
| 164 |
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: