| Conditions | 14 |
| Paths | 12 |
| Total Lines | 241 |
| 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 |
||
| 18 | protected function toNodeS100() |
||
| 19 | { |
||
| 20 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
| 21 | //o idEvento pode variar de evento para evento |
||
| 22 | //então cada factory individualmente terá de construir o seu |
||
| 23 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
| 24 | $this->dom->addChild( |
||
| 25 | $ideEvento, |
||
| 26 | "indRetif", |
||
| 27 | $this->std->indretif, |
||
| 28 | true |
||
| 29 | ); |
||
| 30 | if ($this->std->indretif == 2) { |
||
| 31 | $this->dom->addChild( |
||
| 32 | $ideEvento, |
||
| 33 | "nrRecibo", |
||
| 34 | $this->std->nrrecibo, |
||
| 35 | true |
||
| 36 | ); |
||
| 37 | } |
||
| 38 | $this->dom->addChild( |
||
| 39 | $ideEvento, |
||
| 40 | "tpAmb", |
||
| 41 | $this->tpAmb, |
||
| 42 | true |
||
| 43 | ); |
||
| 44 | $this->dom->addChild( |
||
| 45 | $ideEvento, |
||
| 46 | "procEmi", |
||
| 47 | $this->procEmi, |
||
| 48 | true |
||
| 49 | ); |
||
| 50 | $this->dom->addChild( |
||
| 51 | $ideEvento, |
||
| 52 | "verProc", |
||
| 53 | $this->verProc, |
||
| 54 | true |
||
| 55 | ); |
||
| 56 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
| 57 | $ideBenef = $this->dom->createElement("ideBenef"); |
||
| 58 | $this->dom->addChild( |
||
| 59 | $ideBenef, |
||
| 60 | "cpfBenef", |
||
| 61 | $this->std->cpfbenef, |
||
| 62 | true |
||
| 63 | ); |
||
| 64 | $this->node->appendChild($ideBenef); |
||
| 65 | $alteracao = $this->dom->createElement("alteracao"); |
||
| 66 | $this->dom->addChild( |
||
| 67 | $alteracao, |
||
| 68 | "dtAlteracao", |
||
| 69 | $this->std->dtalteracao, |
||
| 70 | true |
||
| 71 | ); |
||
| 72 | $dadosBenef = $this->dom->createElement("dadosBenef"); |
||
| 73 | $this->dom->addChild( |
||
| 74 | $dadosBenef, |
||
| 75 | "nmBenefic", |
||
| 76 | $this->std->dadosbenef->nmbenefic, |
||
| 77 | true |
||
| 78 | ); |
||
| 79 | $this->dom->addChild( |
||
| 80 | $dadosBenef, |
||
| 81 | "sexo", |
||
| 82 | $this->std->dadosbenef->sexo, |
||
| 83 | true |
||
| 84 | ); |
||
| 85 | $this->dom->addChild( |
||
| 86 | $dadosBenef, |
||
| 87 | "racaCor", |
||
| 88 | $this->std->dadosbenef->racacor, |
||
| 89 | true |
||
| 90 | ); |
||
| 91 | $this->dom->addChild( |
||
| 92 | $dadosBenef, |
||
| 93 | "estCiv", |
||
| 94 | !empty($this->std->dadosbenef->estciv) ? $this->std->dadosbenef->estciv : null, |
||
| 95 | false |
||
| 96 | ); |
||
| 97 | $this->dom->addChild( |
||
| 98 | $dadosBenef, |
||
| 99 | "incFisMen", |
||
| 100 | $this->std->dadosbenef->incfismen, |
||
| 101 | true |
||
| 102 | ); |
||
| 103 | $endereco = $this->dom->createElement("endereco"); |
||
| 104 | if (!empty($this->std->dadosbenef->endereco->brasil)) { |
||
| 105 | $end = $this->std->dadosbenef->endereco->brasil; |
||
| 106 | $brasil = $this->dom->createElement("brasil"); |
||
| 107 | $this->dom->addChild( |
||
| 108 | $brasil, |
||
| 109 | "tpLograd", |
||
| 110 | !empty($end->tplograd) ? $end->tplograd : null, |
||
| 111 | false |
||
| 112 | ); |
||
| 113 | $this->dom->addChild( |
||
| 114 | $brasil, |
||
| 115 | "dscLograd", |
||
| 116 | $end->dsclograd, |
||
| 117 | true |
||
| 118 | ); |
||
| 119 | $this->dom->addChild( |
||
| 120 | $brasil, |
||
| 121 | "nrLograd", |
||
| 122 | $end->nrlograd, |
||
| 123 | true |
||
| 124 | ); |
||
| 125 | $this->dom->addChild( |
||
| 126 | $brasil, |
||
| 127 | "complemento", |
||
| 128 | !empty($end->complemento) ? $end->complemento : null, |
||
| 129 | false |
||
| 130 | ); |
||
| 131 | $this->dom->addChild( |
||
| 132 | $brasil, |
||
| 133 | "bairro", |
||
| 134 | !empty($end->bairro) ? $end->bairro : null, |
||
| 135 | false |
||
| 136 | ); |
||
| 137 | $this->dom->addChild( |
||
| 138 | $brasil, |
||
| 139 | "cep", |
||
| 140 | $end->cep, |
||
| 141 | true |
||
| 142 | ); |
||
| 143 | $this->dom->addChild( |
||
| 144 | $brasil, |
||
| 145 | "codMunic", |
||
| 146 | $end->codmunic, |
||
| 147 | true |
||
| 148 | ); |
||
| 149 | $this->dom->addChild( |
||
| 150 | $brasil, |
||
| 151 | "uf", |
||
| 152 | $end->uf, |
||
| 153 | true |
||
| 154 | ); |
||
| 155 | $endereco->appendChild($brasil); |
||
| 156 | } elseif (!empty($this->std->dadosbenef->endereco->exterior)) { |
||
| 157 | $end = $this->std->dadosbenef->endereco->exterior; |
||
| 158 | $exterior = $this->dom->createElement("exterior"); |
||
| 159 | $this->dom->addChild( |
||
| 160 | $exterior, |
||
| 161 | "paisResid", |
||
| 162 | $end->paisresid, |
||
| 163 | true |
||
| 164 | ); |
||
| 165 | $this->dom->addChild( |
||
| 166 | $exterior, |
||
| 167 | "dscLograd", |
||
| 168 | $end->dsclograd, |
||
| 169 | true |
||
| 170 | ); |
||
| 171 | $this->dom->addChild( |
||
| 172 | $exterior, |
||
| 173 | "nrLograd", |
||
| 174 | $end->nrlograd, |
||
| 175 | true |
||
| 176 | ); |
||
| 177 | $this->dom->addChild( |
||
| 178 | $exterior, |
||
| 179 | "complemento", |
||
| 180 | !empty($end->complemento) ? $end->complemento : null, |
||
| 181 | false |
||
| 182 | ); |
||
| 183 | $this->dom->addChild( |
||
| 184 | $exterior, |
||
| 185 | "bairro", |
||
| 186 | !empty($end->bairro) ? $end->bairro : null, |
||
| 187 | false |
||
| 188 | ); |
||
| 189 | $this->dom->addChild( |
||
| 190 | $exterior, |
||
| 191 | "nmCid", |
||
| 192 | $end->nmcid, |
||
| 193 | true |
||
| 194 | ); |
||
| 195 | $this->dom->addChild( |
||
| 196 | $exterior, |
||
| 197 | "codPostal", |
||
| 198 | !empty($end->codpostal) ? $end->codpostal : null, |
||
| 199 | false |
||
| 200 | ); |
||
| 201 | $endereco->appendChild($exterior); |
||
| 202 | } |
||
| 203 | $dadosBenef->appendChild($endereco); |
||
| 204 | if (!empty($this->std->dadosbenef->dependente)) { |
||
| 205 | foreach ($this->std->dadosbenef->dependente as $num => $dep) { |
||
| 206 | $dependente = $this->dom->createElement("dependente"); |
||
| 207 | $this->dom->addChild( |
||
| 208 | $dependente, |
||
| 209 | "tpDep", |
||
| 210 | $dep->tpdep, |
||
| 211 | true |
||
| 212 | ); |
||
| 213 | $this->dom->addChild( |
||
| 214 | $dependente, |
||
| 215 | "nmDep", |
||
| 216 | $dep->nmdep, |
||
| 217 | true |
||
| 218 | ); |
||
| 219 | $this->dom->addChild( |
||
| 220 | $dependente, |
||
| 221 | "dtNascto", |
||
| 222 | $dep->dtnascto, |
||
| 223 | true |
||
| 224 | ); |
||
| 225 | $this->dom->addChild( |
||
| 226 | $dependente, |
||
| 227 | "cpfDep", |
||
| 228 | !empty($dep->cpfdep) ? $dep->cpfdep : null, |
||
| 229 | false |
||
| 230 | ); |
||
| 231 | $this->dom->addChild( |
||
| 232 | $dependente, |
||
| 233 | "sexoDep", |
||
| 234 | $dep->sexodep, |
||
| 235 | true |
||
| 236 | ); |
||
| 237 | $this->dom->addChild( |
||
| 238 | $dependente, |
||
| 239 | "depIRRF", |
||
| 240 | $dep->depirrf, |
||
| 241 | true |
||
| 242 | ); |
||
| 243 | $this->dom->addChild( |
||
| 244 | $dependente, |
||
| 245 | "incFisMen", |
||
| 246 | $dep->incfismen, |
||
| 247 | true |
||
| 248 | ); |
||
| 249 | $dadosBenef->appendChild($dependente); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | $alteracao->appendChild($dadosBenef); |
||
| 253 | $this->node->appendChild($alteracao); |
||
| 254 | //finalização do xml |
||
| 255 | $this->eSocial->appendChild($this->node); |
||
| 256 | $this->xml = $this->dom->saveXML($this->eSocial); |
||
| 257 | //$this->sign(); |
||
| 258 | } |
||
| 259 | } |
||
| 260 |
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: