| Conditions | 22 |
| Paths | 6156 |
| Total Lines | 221 |
| 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 |
||
| 277 | protected function toNodeS100() |
||
| 278 | { |
||
| 279 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
| 280 | //o idEvento pode variar de evento para evento |
||
| 281 | //então cada factory individualmente terá de construir o seu |
||
| 282 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
| 283 | $this->dom->addChild( |
||
| 284 | $ideEvento, |
||
| 285 | "tpAmb", |
||
| 286 | $this->tpAmb, |
||
| 287 | true |
||
| 288 | ); |
||
| 289 | $this->dom->addChild( |
||
| 290 | $ideEvento, |
||
| 291 | "procEmi", |
||
| 292 | $this->procEmi, |
||
| 293 | true |
||
| 294 | ); |
||
| 295 | $this->dom->addChild( |
||
| 296 | $ideEvento, |
||
| 297 | "verProc", |
||
| 298 | $this->verProc, |
||
| 299 | true |
||
| 300 | ); |
||
| 301 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
| 302 | |||
| 303 | //tag deste evento em particular |
||
| 304 | $infoEstab = $this->dom->createElement("infoEstab"); |
||
| 305 | |||
| 306 | //tag comum a todos os modos |
||
| 307 | $ideEstab = $this->dom->createElement("ideEstab"); |
||
| 308 | $this->dom->addChild( |
||
| 309 | $ideEstab, |
||
| 310 | "tpInsc", |
||
| 311 | $this->std->tpinsc, |
||
| 312 | true |
||
| 313 | ); |
||
| 314 | $this->dom->addChild( |
||
| 315 | $ideEstab, |
||
| 316 | "nrInsc", |
||
| 317 | $this->std->nrinsc, |
||
| 318 | true |
||
| 319 | ); |
||
| 320 | $this->dom->addChild( |
||
| 321 | $ideEstab, |
||
| 322 | "iniValid", |
||
| 323 | $this->std->inivalid, |
||
| 324 | true |
||
| 325 | ); |
||
| 326 | if ($this->std->modo !== 'INC') { |
||
| 327 | $this->dom->addChild( |
||
| 328 | $ideEstab, |
||
| 329 | "fimValid", |
||
| 330 | !empty($this->std->fimvalid) ? $this->std->fimvalid : null, |
||
| 331 | false |
||
| 332 | ); |
||
| 333 | } |
||
| 334 | |||
| 335 | if ($this->std->modo == 'INC') { |
||
| 336 | $node = $this->dom->createElement("inclusao"); |
||
| 337 | } elseif ($this->std->modo == 'ALT') { |
||
| 338 | $node = $this->dom->createElement("alteracao"); |
||
| 339 | } else { |
||
| 340 | $node = $this->dom->createElement("exclusao"); |
||
| 341 | } |
||
| 342 | $node->appendChild($ideEstab); |
||
| 343 | |||
| 344 | if (!empty($this->std->dadosestab) && in_array($this->std->modo, ['INC', 'ALT'])) { |
||
| 345 | $dadosEstab = $this->dom->createElement("dadosEstab"); |
||
| 346 | $this->dom->addChild( |
||
| 347 | $dadosEstab, |
||
| 348 | "cnaePrep", |
||
| 349 | $this->std->dadosestab->cnaeprep, |
||
| 350 | true |
||
| 351 | ); |
||
| 352 | $aliqGilrat = $this->dom->createElement("aliqGilrat"); |
||
| 353 | $this->dom->addChild( |
||
| 354 | $aliqGilrat, |
||
| 355 | "aliqRat", |
||
| 356 | $this->std->dadosestab->aliqgilrat->aliqrat, |
||
| 357 | false |
||
| 358 | ); |
||
| 359 | $fap = !empty($this->std->dadosestab->aliqgilrat->fap) ? $this->std->dadosestab->aliqgilrat->fap : null; |
||
| 360 | if ($fap) { |
||
| 361 | $fap = number_format($fap, 4, '.', ''); |
||
| 362 | } |
||
| 363 | $this->dom->addChild( |
||
| 364 | $aliqGilrat, |
||
| 365 | "fap", |
||
| 366 | $fap, |
||
| 367 | false |
||
| 368 | ); |
||
| 369 | if (!empty($this->std->dadosestab->aliqgilrat->procadmjudrat)) { |
||
| 370 | $procAdmJudRat = $this->dom->createElement("procAdmJudRat"); |
||
| 371 | $this->dom->addChild( |
||
| 372 | $procAdmJudRat, |
||
| 373 | "tpProc", |
||
| 374 | $this->std->dadosestab->aliqgilrat->procadmjudrat->tpproc, |
||
| 375 | true |
||
| 376 | ); |
||
| 377 | $this->dom->addChild( |
||
| 378 | $procAdmJudRat, |
||
| 379 | "nrProc", |
||
| 380 | $this->std->dadosestab->aliqgilrat->procadmjudrat->nrproc, |
||
| 381 | true |
||
| 382 | ); |
||
| 383 | $this->dom->addChild( |
||
| 384 | $procAdmJudRat, |
||
| 385 | "codSusp", |
||
| 386 | $this->std->dadosestab->aliqgilrat->procadmjudrat->codsusp, |
||
| 387 | true |
||
| 388 | ); |
||
| 389 | $aliqGilrat->appendChild($procAdmJudRat); |
||
| 390 | } |
||
| 391 | if (!empty($this->std->dadosestab->aliqgilrat->procadmjudfap)) { |
||
| 392 | $procAdmJudFap = $this->dom->createElement("procAdmJudFap"); |
||
| 393 | $this->dom->addChild( |
||
| 394 | $procAdmJudFap, |
||
| 395 | "tpProc", |
||
| 396 | $this->std->dadosestab->aliqgilrat->procadmjudfap->tpproc, |
||
| 397 | true |
||
| 398 | ); |
||
| 399 | $this->dom->addChild( |
||
| 400 | $procAdmJudFap, |
||
| 401 | "nrProc", |
||
| 402 | $this->std->dadosestab->aliqgilrat->procadmjudfap->nrproc, |
||
| 403 | true |
||
| 404 | ); |
||
| 405 | $this->dom->addChild( |
||
| 406 | $procAdmJudFap, |
||
| 407 | "codSusp", |
||
| 408 | $this->std->dadosestab->aliqgilrat->procadmjudfap->codsusp, |
||
| 409 | true |
||
| 410 | ); |
||
| 411 | $aliqGilrat->appendChild($procAdmJudFap); |
||
| 412 | } |
||
| 413 | $dadosEstab->appendChild($aliqGilrat); |
||
| 414 | if (!empty($this->std->dadosestab->infocaepf)) { |
||
| 415 | $infoCaepf = $this->dom->createElement("infoCaepf"); |
||
| 416 | $this->dom->addChild( |
||
| 417 | $infoCaepf, |
||
| 418 | "tpCaepf", |
||
| 419 | $this->std->dadosestab->infocaepf->tpcaepf, |
||
| 420 | true |
||
| 421 | ); |
||
| 422 | $dadosEstab->appendChild($infoCaepf); |
||
| 423 | } |
||
| 424 | if (! empty($this->std->dadosestab->infoobra)) { |
||
| 425 | $infoObra = $this->dom->createElement("infoObra"); |
||
| 426 | $this->dom->addChild( |
||
| 427 | $infoObra, |
||
| 428 | "indSubstPatrObra", |
||
| 429 | $this->std->dadosestab->infoobra->indsubstpatrobra, |
||
| 430 | true |
||
| 431 | ); |
||
| 432 | $dadosEstab->appendChild($infoObra); |
||
| 433 | } |
||
| 434 | if (!empty($this->std->dadosestab->infotrab)) { |
||
| 435 | $infoTrab = $this->dom->createElement("infoTrab"); |
||
| 436 | if (!empty($this->std->dadosestab->infotrab->infoapr)) { |
||
| 437 | $infoApr = $this->dom->createElement("infoApr"); |
||
| 438 | $this->dom->addChild( |
||
| 439 | $infoApr, |
||
| 440 | "nrProcJud", |
||
| 441 | ! empty($this->std->dadosestab->infotrab->infoapr->nrprocjud) |
||
| 442 | ? $this->std->dadosestab->infotrab->infoapr->nrprocjud |
||
| 443 | : null, |
||
| 444 | false |
||
| 445 | ); |
||
| 446 | if (! empty($this->std->dadosestab->infotrab->infoapr->infoenteduc)) { |
||
| 447 | foreach ($this->std->dadosestab->infotrab->infoapr->infoenteduc as $edu) { |
||
| 448 | $infoEntEduc = $this->dom->createElement("infoEntEduc"); |
||
| 449 | $this->dom->addChild( |
||
| 450 | $infoEntEduc, |
||
| 451 | "nrInsc", |
||
| 452 | $edu->nrinsc, |
||
| 453 | true |
||
| 454 | ); |
||
| 455 | $infoApr->appendChild($infoEntEduc); |
||
| 456 | } |
||
| 457 | } |
||
| 458 | $infoTrab->appendChild($infoApr); |
||
| 459 | } |
||
| 460 | } |
||
| 461 | if (!empty($this->std->dadosestab->infotrab->infopdc)) { |
||
| 462 | $infoPCD = $this->dom->createElement("infoPCD"); |
||
| 463 | $this->dom->addChild( |
||
| 464 | $infoPCD, |
||
| 465 | "nrProcJud", |
||
| 466 | $this->std->dadosestab->infotrab->infopdc->nrprocjud, |
||
| 467 | true |
||
| 468 | ); |
||
| 469 | $infoTrab->appendChild($infoPCD); |
||
| 470 | } |
||
| 471 | $dadosEstab->appendChild($infoTrab); |
||
| 472 | $node->appendChild($dadosEstab); |
||
| 473 | } |
||
| 474 | if (!empty($this->std->novavalidade) && $this->std->modo == 'ALT') { |
||
| 475 | $newVal = $this->std->novavalidade; |
||
| 476 | $novaValidade = $this->dom->createElement("novaValidade"); |
||
| 477 | $this->dom->addChild( |
||
| 478 | $novaValidade, |
||
| 479 | "iniValid", |
||
| 480 | $newVal->inivalid, |
||
| 481 | true |
||
| 482 | ); |
||
| 483 | $this->dom->addChild( |
||
| 484 | $novaValidade, |
||
| 485 | "fimValid", |
||
| 486 | !empty($newVal->fimvalid) ? $newVal->fimvalid : null, |
||
| 487 | false |
||
| 488 | ); |
||
| 489 | $node->appendChild($novaValidade); |
||
| 490 | } |
||
| 491 | $infoEstab = $this->dom->createElement("infoEstab"); |
||
| 492 | $infoEstab->appendChild($node); |
||
| 493 | //finalização do xml |
||
| 494 | $this->node->appendChild($infoEstab); |
||
| 495 | $this->eSocial->appendChild($this->node); |
||
| 496 | $this->sign(); |
||
| 497 | } |
||
| 498 | } |
||
| 499 |
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: