Conditions | 14 |
Paths | 40 |
Total Lines | 186 |
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 |
||
200 | protected function toNodeS100() |
||
201 | { |
||
202 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
203 | //o idEvento pode variar de evento para evento |
||
204 | //então cada factory individualmente terá de construir o seu |
||
205 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
206 | $this->dom->addChild( |
||
207 | $ideEvento, |
||
208 | "tpAmb", |
||
209 | $this->tpAmb, |
||
210 | true |
||
211 | ); |
||
212 | $this->dom->addChild( |
||
213 | $ideEvento, |
||
214 | "procEmi", |
||
215 | $this->procEmi, |
||
216 | true |
||
217 | ); |
||
218 | $this->dom->addChild( |
||
219 | $ideEvento, |
||
220 | "verProc", |
||
221 | $this->verProc, |
||
222 | true |
||
223 | ); |
||
224 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
225 | |||
226 | $ide = $this->dom->createElement("ideLotacao"); |
||
227 | $this->dom->addChild( |
||
228 | $ide, |
||
229 | "codLotacao", |
||
230 | $this->std->codlotacao, |
||
231 | true |
||
232 | ); |
||
233 | $this->dom->addChild( |
||
234 | $ide, |
||
235 | "iniValid", |
||
236 | $this->std->inivalid, |
||
237 | true |
||
238 | ); |
||
239 | $this->dom->addChild( |
||
240 | $ide, |
||
241 | "fimValid", |
||
242 | ! empty($this->std->fimvalid) ? $this->std->fimvalid : null, |
||
243 | false |
||
244 | ); |
||
245 | |||
246 | |||
247 | if (!empty($this->std->dadoslotacao)) { |
||
248 | $da = $this->std->dadoslotacao; |
||
249 | $dados = $this->dom->createElement("dadosLotacao"); |
||
250 | $this->dom->addChild( |
||
251 | $dados, |
||
252 | "tpLotacao", |
||
253 | $da->tplotacao, |
||
254 | true |
||
255 | ); |
||
256 | $this->dom->addChild( |
||
257 | $dados, |
||
258 | "tpInsc", |
||
259 | !empty($da->tpinsc) ? $da->tpinsc : null, |
||
260 | false |
||
261 | ); |
||
262 | $this->dom->addChild( |
||
263 | $dados, |
||
264 | "nrInsc", |
||
265 | !empty($da->nrinsc) ? $da->nrinsc : null, |
||
266 | false |
||
267 | ); |
||
268 | $fpasLotacao = $this->dom->createElement("fpasLotacao"); |
||
269 | $this->dom->addChild( |
||
270 | $fpasLotacao, |
||
271 | "fpas", |
||
272 | $da->fpas, |
||
273 | true |
||
274 | ); |
||
275 | $this->dom->addChild( |
||
276 | $fpasLotacao, |
||
277 | "codTercs", |
||
278 | $da->codtercs, |
||
279 | true |
||
280 | ); |
||
281 | $this->dom->addChild( |
||
282 | $fpasLotacao, |
||
283 | "codTercsSusp", |
||
284 | !empty($da->codtercssusp) ? $da->codtercssusp : null, |
||
285 | false |
||
286 | ); |
||
287 | |||
288 | if (!empty($da->procjudterceiro)) { |
||
289 | $procjud = $this->dom->createElement("infoProcJudTerceiros"); |
||
290 | foreach ($da->procjudterceiro as $proc) { |
||
291 | $pjt = $this->dom->createElement("procJudTerceiro"); |
||
292 | $this->dom->addChild( |
||
293 | $pjt, |
||
294 | "codTerc", |
||
295 | $proc->codterc, |
||
296 | true |
||
297 | ); |
||
298 | $this->dom->addChild( |
||
299 | $pjt, |
||
300 | "nrProcJud", |
||
301 | $proc->nrprocjud, |
||
302 | true |
||
303 | ); |
||
304 | $this->dom->addChild( |
||
305 | $pjt, |
||
306 | "codSusp", |
||
307 | $proc->codsusp, |
||
308 | true |
||
309 | ); |
||
310 | $procjud->appendChild($pjt); |
||
311 | } |
||
312 | $fpasLotacao->appendChild($procjud); |
||
313 | } |
||
314 | $dados->appendChild($fpasLotacao); |
||
315 | |||
316 | if (!empty($da->infoemprparcial)) { |
||
317 | $parcial = $this->dom->createElement("infoEmprParcial"); |
||
318 | $this->dom->addChild( |
||
319 | $parcial, |
||
320 | "tpInscContrat", |
||
321 | $da->infoemprparcial->tpinsccontrat, |
||
322 | true |
||
323 | ); |
||
324 | $this->dom->addChild( |
||
325 | $parcial, |
||
326 | "nrInscContrat", |
||
327 | $da->infoemprparcial->nrinsccontrat, |
||
328 | true |
||
329 | ); |
||
330 | $this->dom->addChild( |
||
331 | $parcial, |
||
332 | "tpInscProp", |
||
333 | $da->infoemprparcial->tpinscprop, |
||
334 | true |
||
335 | ); |
||
336 | $this->dom->addChild( |
||
337 | $parcial, |
||
338 | "nrInscProp", |
||
339 | $da->infoemprparcial->nrinscprop, |
||
340 | true |
||
341 | ); |
||
342 | $dados->appendChild($parcial); |
||
343 | } |
||
344 | } |
||
345 | |||
346 | if (!empty($this->std->novavalidade)) { |
||
347 | $nova = $this->dom->createElement("novaValidade"); |
||
348 | $this->dom->addChild( |
||
349 | $nova, |
||
350 | "iniValid", |
||
351 | $this->std->novavalidade->inivalid, |
||
352 | true |
||
353 | ); |
||
354 | $this->dom->addChild( |
||
355 | $nova, |
||
356 | "fimValid", |
||
357 | ! empty($this->std->novavalidade->fimvalid) |
||
358 | ? $this->std->novavalidade->fimvalid |
||
359 | : null, |
||
360 | false |
||
361 | ); |
||
362 | } |
||
363 | |||
364 | $info = $this->dom->createElement("infoLotacao"); |
||
365 | //seleção do modo |
||
366 | if ($this->std->modo == 'INC') { |
||
367 | $node = $this->dom->createElement("inclusao"); |
||
368 | $node->appendChild($ide); |
||
369 | $node->appendChild($dados); |
||
370 | } elseif ($this->std->modo == 'ALT') { |
||
371 | $node = $this->dom->createElement("alteracao"); |
||
372 | $node->appendChild($ide); |
||
373 | $node->appendChild($dados); |
||
374 | isset($nova) ? $node->appendChild($nova) : null; |
||
375 | } else { |
||
376 | $node = $this->dom->createElement("exclusao"); |
||
377 | $node->appendChild($ide); |
||
378 | } |
||
379 | |||
380 | $info->appendChild($node); |
||
381 | $this->node->appendChild($info); |
||
382 | $this->eSocial->appendChild($this->node); |
||
383 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
384 | $this->sign(); |
||
385 | } |
||
386 | } |
||
387 |
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: