Conditions | 18 |
Paths | 102 |
Total Lines | 211 |
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 |
||
231 | protected function toNodeS100() |
||
232 | { |
||
233 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
234 | //o idEvento pode variar de evento para evento |
||
235 | //então cada factory individualmente terá de construir o seu |
||
236 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
237 | $this->dom->addChild( |
||
238 | $ideEvento, |
||
239 | "tpAmb", |
||
240 | $this->tpAmb, |
||
241 | true |
||
242 | ); |
||
243 | $this->dom->addChild( |
||
244 | $ideEvento, |
||
245 | "procEmi", |
||
246 | $this->procEmi, |
||
247 | true |
||
248 | ); |
||
249 | $this->dom->addChild( |
||
250 | $ideEvento, |
||
251 | "verProc", |
||
252 | $this->verProc, |
||
253 | true |
||
254 | ); |
||
255 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
256 | |||
257 | //tag deste evento em particular |
||
258 | $infoRubrica = $this->dom->createElement("infoRubrica"); |
||
259 | //tag comum a todos os modos |
||
260 | $ideRubrica = $this->dom->createElement("ideRubrica"); |
||
261 | $this->dom->addChild( |
||
262 | $ideRubrica, |
||
263 | "codRubr", |
||
264 | $this->std->codrubr, |
||
265 | true |
||
266 | ); |
||
267 | $this->dom->addChild( |
||
268 | $ideRubrica, |
||
269 | "ideTabRubr", |
||
270 | $this->std->idetabrubr, |
||
271 | true |
||
272 | ); |
||
273 | $this->dom->addChild( |
||
274 | $ideRubrica, |
||
275 | "iniValid", |
||
276 | $this->std->inivalid, |
||
277 | true |
||
278 | ); |
||
279 | $this->dom->addChild( |
||
280 | $ideRubrica, |
||
281 | "fimValid", |
||
282 | ! empty($this->std->fimvalid) ? $this->std->fimvalid : null, |
||
283 | false |
||
284 | ); |
||
285 | //seleção do modo |
||
286 | if ($this->std->modo == 'INC') { |
||
287 | $node = $this->dom->createElement("inclusao"); |
||
288 | } elseif ($this->std->modo == 'ALT') { |
||
289 | $node = $this->dom->createElement("alteracao"); |
||
290 | } else { |
||
291 | $node = $this->dom->createElement("exclusao"); |
||
292 | } |
||
293 | $node->appendChild($ideRubrica); |
||
294 | |||
295 | if (!empty($this->std->dadosrubrica) && $this->std->modo != 'EXC') { |
||
296 | $dadosRubrica = $this->dom->createElement("dadosRubrica"); |
||
297 | $this->dom->addChild( |
||
298 | $dadosRubrica, |
||
299 | "dscRubr", |
||
300 | $this->std->dadosrubrica->dscrubr, |
||
301 | true |
||
302 | ); |
||
303 | $this->dom->addChild( |
||
304 | $dadosRubrica, |
||
305 | "natRubr", |
||
306 | $this->std->dadosrubrica->natrubr, |
||
307 | true |
||
308 | ); |
||
309 | $this->dom->addChild( |
||
310 | $dadosRubrica, |
||
311 | "tpRubr", |
||
312 | $this->std->dadosrubrica->tprubr, |
||
313 | true |
||
314 | ); |
||
315 | $this->dom->addChild( |
||
316 | $dadosRubrica, |
||
317 | "codIncCP", |
||
318 | $this->std->dadosrubrica->codinccp, |
||
319 | true |
||
320 | ); |
||
321 | $this->dom->addChild( |
||
322 | $dadosRubrica, |
||
323 | "codIncIRRF", |
||
324 | $this->std->dadosrubrica->codincirrf, |
||
325 | true |
||
326 | ); |
||
327 | $this->dom->addChild( |
||
328 | $dadosRubrica, |
||
329 | "codIncFGTS", |
||
330 | $this->std->dadosrubrica->codincfgts, |
||
331 | true |
||
332 | ); |
||
333 | $this->dom->addChild( |
||
334 | $dadosRubrica, |
||
335 | "observacao", |
||
336 | ! empty($this->std->dadosrubrica->observacao) |
||
337 | ? $this->std->dadosrubrica->observacao |
||
338 | : null, |
||
339 | false |
||
340 | ); |
||
341 | |||
342 | if (! empty($this->std->dadosrubrica->ideprocessocp)) { |
||
343 | foreach ($this->std->dadosrubrica->ideprocessocp as $cp) { |
||
344 | $ideProcessoCP = $this->dom->createElement("ideProcessoCP"); |
||
345 | $this->dom->addChild( |
||
346 | $ideProcessoCP, |
||
347 | "tpProc", |
||
348 | $cp->tpproc, |
||
349 | true |
||
350 | ); |
||
351 | $this->dom->addChild( |
||
352 | $ideProcessoCP, |
||
353 | "nrProc", |
||
354 | $cp->nrproc, |
||
355 | true |
||
356 | ); |
||
357 | $this->dom->addChild( |
||
358 | $ideProcessoCP, |
||
359 | "extDecisao", |
||
360 | $cp->extdecisao, |
||
361 | true |
||
362 | ); |
||
363 | $this->dom->addChild( |
||
364 | $ideProcessoCP, |
||
365 | "codSusp", |
||
366 | $cp->codsusp, |
||
367 | true |
||
368 | ); |
||
369 | $dadosRubrica->appendChild($ideProcessoCP); |
||
370 | } |
||
371 | } |
||
372 | |||
373 | if (! empty($this->std->dadosrubrica->ideprocessoirrf)) { |
||
374 | foreach ($this->std->dadosrubrica->ideprocessoirrf as $irrf) { |
||
375 | $ideProcessoIRRF = $this->dom->createElement("ideProcessoIRRF"); |
||
376 | $this->dom->addChild( |
||
377 | $ideProcessoIRRF, |
||
378 | "nrProc", |
||
379 | $irrf->nrproc, |
||
380 | true |
||
381 | ); |
||
382 | $this->dom->addChild( |
||
383 | $ideProcessoIRRF, |
||
384 | "codSusp", |
||
385 | $irrf->codsusp, |
||
386 | true |
||
387 | ); |
||
388 | $dadosRubrica->appendChild($ideProcessoIRRF); |
||
389 | } |
||
390 | } |
||
391 | if (! empty($this->std->dadosrubrica->ideprocessofgts)) { |
||
392 | foreach ($this->std->dadosrubrica->ideprocessofgts as $fgts) { |
||
393 | $ideProcessoFGTS = $this->dom->createElement("ideProcessoFGTS"); |
||
394 | $this->dom->addChild( |
||
395 | $ideProcessoFGTS, |
||
396 | "nrProc", |
||
397 | $fgts->nrproc, |
||
398 | true |
||
399 | ); |
||
400 | $dadosRubrica->appendChild($ideProcessoFGTS); |
||
401 | } |
||
402 | } |
||
403 | if (! empty($this->std->dadosrubrica->ideprocessosind)) { |
||
404 | foreach ($this->std->dadosrubrica->ideprocessosind as $sind) { |
||
405 | $ideProcessoSIND = $this->dom->createElement("ideProcessoSIND"); |
||
406 | $this->dom->addChild( |
||
407 | $ideProcessoSIND, |
||
408 | "nrProc", |
||
409 | $sind->nrproc, |
||
410 | true |
||
411 | ); |
||
412 | $dadosRubrica->appendChild($ideProcessoSIND); |
||
413 | } |
||
414 | } |
||
415 | $node->appendChild($dadosRubrica); |
||
416 | } |
||
417 | if (! empty($this->std->novavalidade) && $this->std->modo == 'ALT') { |
||
418 | $newVal = $this->std->novavalidade; |
||
419 | $novaValidade = $this->dom->createElement("novaValidade"); |
||
420 | $this->dom->addChild( |
||
421 | $novaValidade, |
||
422 | "iniValid", |
||
423 | $newVal->inivalid, |
||
424 | true |
||
425 | ); |
||
426 | $this->dom->addChild( |
||
427 | $novaValidade, |
||
428 | "fimValid", |
||
429 | ! empty($newVal->fimvalid) ? $newVal->fimvalid : null, |
||
430 | false |
||
431 | ); |
||
432 | $node->appendChild($novaValidade); |
||
433 | } |
||
434 | |||
435 | //finalização do xml |
||
436 | $infoRubrica->appendChild($node); |
||
437 | $this->node->appendChild($infoRubrica); |
||
438 | $this->eSocial->appendChild($this->node); |
||
439 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
440 | $this->sign(); |
||
441 | } |
||
442 | } |
||
443 |
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: