Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Tools often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Tools, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class Tools extends BaseTools |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * urlPortal |
||
| 38 | * Instância do WebService |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $urlPortal = 'http://www.portalfiscal.inf.br/cte'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * errrors |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | public $erros = array(); |
||
| 48 | |||
| 49 | protected $modelo = '57'; |
||
| 50 | |||
| 51 | public function printCTe() |
||
| 54 | |||
| 55 | public function mailCTe() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * assina |
||
| 61 | * @param string $xml |
||
| 62 | * @param boolean $saveFile |
||
| 63 | * @return string |
||
| 64 | * @throws Exception\RuntimeException |
||
| 65 | */ |
||
| 66 | public function assina($xml = '', $saveFile = false) |
||
| 70 | |||
| 71 | public function sefazEnvia( |
||
| 151 | |||
| 152 | public function sefazConsultaRecibo($recibo = '', $tpAmb = '2', &$aRetorno = array()) |
||
| 208 | |||
| 209 | public function sefazConsultaChave($chave = '', $tpAmb = '2', &$aRetorno = array()) |
||
| 264 | |||
| 265 | public function sefazStatus($siglaUF = '', $tpAmb = '2', &$aRetorno = array()) |
||
| 315 | |||
| 316 | public function sefazInutiliza( |
||
| 317 | $nSerie = '1', |
||
| 318 | $nIni = '', |
||
| 319 | $nFin = '', |
||
| 320 | $xJust = '', |
||
| 321 | $tpAmb = '2', |
||
| 322 | &$aRetorno = array(), |
||
| 323 | $salvarMensagens = true |
||
| 324 | ) { |
||
| 325 | $nSerie = (integer) $nSerie; |
||
| 326 | $nIni = (integer) $nIni; |
||
| 327 | $nFin = (integer) $nFin; |
||
| 328 | $xJust = Strings::cleanString($xJust); |
||
| 329 | $this->zValidParamInut($xJust, $nSerie, $nIni, $nFin); |
||
| 330 | if ($tpAmb == '') { |
||
| 331 | $tpAmb = $this->aConfig['tpAmb']; |
||
| 332 | } |
||
| 333 | |||
| 334 | // Identificação do serviço |
||
| 335 | $servico = 'CteInutilizacao'; |
||
| 336 | //monta serviço |
||
| 337 | $siglaUF = $this->aConfig['siglaUF']; |
||
| 338 | //carrega serviço |
||
| 339 | $servico = 'CteInutilizacao'; |
||
| 340 | $this->zLoadServico( |
||
| 341 | 'cte', |
||
| 342 | $servico, |
||
| 343 | $siglaUF, |
||
| 344 | $tpAmb |
||
| 345 | ); |
||
| 346 | |||
| 347 | if ($this->urlService == '') { |
||
| 348 | $msg = "A inutilização não está disponível na SEFAZ $siglaUF!!!"; |
||
| 349 | throw new Exception\RuntimeException($msg); |
||
| 350 | } |
||
| 351 | |||
| 352 | //montagem dos dados da mensagem SOAP |
||
| 353 | $cnpj = $this->aConfig['cnpj']; |
||
| 354 | $sAno = (string) date('y'); |
||
| 355 | $sSerie = str_pad($nSerie, 3, '0', STR_PAD_LEFT); |
||
| 356 | $sInicio = str_pad($nIni, 9, '0', STR_PAD_LEFT); |
||
| 357 | $sFinal = str_pad($nFin, 9, '0', STR_PAD_LEFT); |
||
| 358 | |||
| 359 | //limpa os caracteres indesejados da justificativa |
||
| 360 | $xJust = Strings::cleanString($xJust); |
||
| 361 | |||
| 362 | // Identificador da TAG a ser assinada formada com Código da UF + |
||
| 363 | // precedida do literal “ID” |
||
| 364 | // 41 posições |
||
| 365 | $id = 'ID'.$this->urlcUF.$cnpj.'57'.$sSerie.$sInicio.$sFinal; |
||
| 366 | |||
| 367 | // Montagem do corpo da mensagem |
||
| 368 | $dXML = "<inutCTe xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">" |
||
| 369 | ."<infInut Id=\"$id\">" |
||
| 370 | ."<tpAmb>$tpAmb</tpAmb>" |
||
| 371 | ."<xServ>INUTILIZAR</xServ>" |
||
| 372 | ."<cUF>$this->urlcUF</cUF>" |
||
| 373 | ."<ano>$sAno</ano>" |
||
| 374 | ."<CNPJ>$cnpj</CNPJ>" |
||
| 375 | ."<mod>57</mod>" |
||
| 376 | ."<serie>$nSerie</serie>" |
||
| 377 | ."<nCTIni>$nIni</nCTIni>" |
||
| 378 | ."<nCTFin>$nFin</nCTFin>" |
||
| 379 | ."<xJust>$xJust</xJust>" |
||
| 380 | ."</infInut></inutCTe>"; |
||
| 381 | |||
| 382 | //assina a solicitação de inutilização |
||
| 383 | $signedMsg = $this->oCertificate->signXML($dXML, 'infInut'); |
||
| 384 | $signedMsg = Strings::clearXml($signedMsg, true); |
||
| 385 | |||
| 386 | $body = "<cteDadosMsg xmlns=\"$this->urlNamespace\">$signedMsg</cteDadosMsg>"; |
||
| 387 | |||
| 388 | //envia a solicitação via SOAP |
||
| 389 | $retorno = $this->oSoap->send( |
||
| 390 | $this->urlService, |
||
| 391 | $this->urlNamespace, |
||
| 392 | $this->urlHeader, |
||
| 393 | $body, |
||
| 394 | $this->urlMethod |
||
| 395 | ); |
||
| 396 | $lastMsg = $this->oSoap->lastMsg; |
||
| 397 | $this->soapDebug = $this->oSoap->soapDebug; |
||
| 398 | |||
| 399 | //salva mensagens |
||
| 400 | if ($salvarMensagens) { |
||
| 401 | $filename = "$sAno-$this->modelo-$sSerie-".$sInicio."_".$sFinal."-inutCTe.xml"; |
||
| 402 | $this->zGravaFile('cte', $tpAmb, $filename, $lastMsg); |
||
| 403 | $filename = "$sAno-$this->modelo-$sSerie-".$sInicio."_".$sFinal."-retInutCTe.xml"; |
||
| 404 | $this->zGravaFile('cte', $tpAmb, $filename, $retorno); |
||
| 405 | } |
||
| 406 | |||
| 407 | //tratar dados de retorno |
||
| 408 | $aRetorno = Response::readReturnSefaz($servico, $retorno); |
||
| 409 | if ($aRetorno['cStat'] == '102') { |
||
| 410 | $retorno = $this->zAddProtMsg('ProcInutCTe', 'inutCTe', $signedMsg, 'retInutCTe', $retorno); |
||
| 411 | if ($salvarMensagens) { |
||
| 412 | $filename = "$sAno-$this->modelo-$sSerie-".$sInicio."_".$sFinal."-procInutCTe.xml"; |
||
| 413 | $this->zGravaFile('cte', $tpAmb, $filename, $retorno, 'inutilizadas'); |
||
| 414 | } |
||
| 415 | } |
||
| 416 | |||
| 417 | return (string) $retorno; |
||
| 418 | } |
||
| 419 | |||
| 420 | public function sefazCancela($chCTe = '', $tpAmb = '2', $xJust = '', $nProt = '', &$aRetorno = array()) |
||
| 421 | { |
||
| 422 | $chCTe = preg_replace('/[^0-9]/', '', $chCTe); |
||
| 423 | $nProt = preg_replace('/[^0-9]/', '', $nProt); |
||
| 424 | $xJust = Strings::cleanString($xJust); |
||
| 425 | //validação dos dados de entrada |
||
| 426 | if (strlen($chCTe) != 44) { |
||
| 427 | $msg = "Uma chave de CTe válida não foi passada como parâmetro $chCTe."; |
||
| 428 | throw new Exception\InvalidArgumentException($msg); |
||
| 429 | } |
||
| 430 | if ($nProt == '') { |
||
| 431 | $msg = "Não foi passado o numero do protocolo!!"; |
||
| 432 | throw new Exception\InvalidArgumentException($msg); |
||
| 433 | } |
||
| 434 | if (strlen($xJust) < 15 || strlen($xJust) > 255) { |
||
| 435 | $msg = "A justificativa deve ter pelo menos 15 digitos e no máximo 255!!"; |
||
| 436 | throw new Exception\InvalidArgumentException($msg); |
||
| 437 | } |
||
| 438 | $siglaUF = $this->zGetSigla(substr($chCTe, 0, 2)); |
||
| 439 | |||
| 440 | //estabelece o codigo do tipo de evento CANCELAMENTO |
||
| 441 | $tpEvento = '110111'; |
||
| 442 | $descEvento = 'Cancelamento'; |
||
| 443 | $nSeqEvento = 1; |
||
| 444 | //monta mensagem |
||
| 445 | $tagAdic = "<evCancCTe>" |
||
| 446 | . "<descEvento>$descEvento</descEvento>" |
||
| 447 | . "<nProt>$nProt</nProt>" |
||
| 448 | . "<xJust>$xJust</xJust>" |
||
| 449 | . "</evCancCTe>"; |
||
| 450 | $retorno = $this->zSefazEvento($siglaUF, $chCTe, $tpAmb, $tpEvento, $nSeqEvento, $tagAdic); |
||
| 451 | $aRetorno = $this->aLastRetEvent; |
||
| 452 | return $retorno; |
||
| 453 | } |
||
| 454 | |||
| 455 | public function enviaMail($pathXml = '', $aMails = array(), $templateFile = '', $comPdf = false, $pathPdf = '') |
||
| 456 | { |
||
| 457 | $mail = new Mail($this->aMailConf); |
||
| 458 | // Se não for informado o caminho do PDF, monta um através do XML |
||
| 459 | /* |
||
| 460 | if ($comPdf && $this->modelo == '55' && $pathPdf == '') { |
||
| 461 | $docxml = Files\FilesFolders::readFile($pathXml); |
||
| 462 | $danfe = new Extras\Danfe($docxml, 'P', 'A4', $this->aDocFormat['pathLogoFile'], 'I', ''); |
||
| 463 | $id = $danfe->montaDANFE(); |
||
| 464 | $pathPdf = $this->aConfig['pathNFeFiles'] |
||
| 465 | . DIRECTORY_SEPARATOR |
||
| 466 | . $this->ambiente |
||
| 467 | . DIRECTORY_SEPARATOR |
||
| 468 | . 'pdf' |
||
| 469 | . DIRECTORY_SEPARATOR |
||
| 470 | . $id . '-danfe.pdf'; |
||
| 471 | $pdf = $danfe->printDANFE($pathPdf, 'F'); |
||
| 472 | } |
||
| 473 | * |
||
| 474 | */ |
||
| 475 | if ($mail->envia($pathXml, $aMails, $comPdf, $pathPdf) === false) { |
||
| 476 | throw new Exception\RuntimeException('Email não enviado. '.$mail->error); |
||
| 477 | } |
||
| 478 | return true; |
||
| 479 | } |
||
| 480 | |||
| 481 | /** |
||
| 482 | * zSefazEvento |
||
| 483 | * @param string $siglaUF |
||
| 484 | * @param string $chCTe |
||
| 485 | * @param string $tpAmb |
||
| 486 | * @param string $tpEvento |
||
| 487 | * @param string $nSeqEvento |
||
| 488 | * @param string $tagAdic |
||
| 489 | * @return string |
||
| 490 | * @throws Exception\RuntimeException |
||
| 491 | * @internal function zLoadServico (Common\Base\BaseTools) |
||
| 492 | */ |
||
| 493 | protected function zSefazEvento( |
||
| 494 | $siglaUF = '', |
||
| 495 | $chCTe = '', |
||
| 496 | $tpAmb = '2', |
||
| 497 | $tpEvento = '', |
||
| 498 | $nSeqEvento = '1', |
||
| 499 | $tagAdic = '' |
||
| 500 | ) { |
||
| 501 | if ($tpAmb == '') { |
||
| 502 | $tpAmb = $this->aConfig['tpAmb']; |
||
| 503 | } |
||
| 504 | //carrega serviço |
||
| 505 | $servico = 'CteRecepcaoEvento'; |
||
| 506 | $this->zLoadServico( |
||
| 507 | 'cte', |
||
| 508 | $servico, |
||
| 509 | $siglaUF, |
||
| 510 | $tpAmb |
||
| 511 | ); |
||
| 512 | if ($this->urlService == '') { |
||
| 513 | $msg = "A recepção de eventos não está disponível na SEFAZ $siglaUF!!!"; |
||
| 514 | throw new Exception\RuntimeException($msg); |
||
| 515 | } |
||
| 516 | $aRet = $this->zTpEv($tpEvento); |
||
| 517 | $aliasEvento = $aRet['alias']; |
||
| 518 | $descEvento = $aRet['desc']; |
||
| 519 | $cnpj = $this->aConfig['cnpj']; |
||
| 520 | $dhEvento = (string) str_replace(' ', 'T', date('Y-m-d H:i:s')); |
||
| 521 | // $dhEvento = (string) str_replace(' ', 'T', date('Y-m-d H:i:sP')); |
||
| 522 | $sSeqEvento = str_pad($nSeqEvento, 2, "0", STR_PAD_LEFT); |
||
| 523 | $eventId = "ID".$tpEvento.$chCTe.$sSeqEvento; |
||
| 524 | $cOrgao = $this->urlcUF; |
||
| 525 | if ($siglaUF == 'AN') { |
||
| 526 | $cOrgao = '91'; |
||
| 527 | } |
||
| 528 | $mensagem = "<infEvento Id=\"$eventId\">" |
||
| 529 | . "<cOrgao>$cOrgao</cOrgao>" |
||
| 530 | . "<tpAmb>$tpAmb</tpAmb>" |
||
| 531 | . "<CNPJ>$cnpj</CNPJ>" |
||
| 532 | . "<chCTe>$chCTe</chCTe>" |
||
| 533 | . "<dhEvento>$dhEvento</dhEvento>" |
||
| 534 | . "<tpEvento>$tpEvento</tpEvento>" |
||
| 535 | . "<nSeqEvento>$nSeqEvento</nSeqEvento>" |
||
| 536 | //. "<nSeqEvento>$sSeqEvento</nSeqEvento>" |
||
| 537 | . "<detEvento versaoEvento=\"$this->urlVersion\">" |
||
| 538 | . "$tagAdic" |
||
| 539 | . "</detEvento>" |
||
| 540 | . "</infEvento>"; |
||
| 541 | |||
| 542 | $cons = "<eventoCTe xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">" |
||
| 543 | . "$mensagem" |
||
| 544 | . "</eventoCTe>"; |
||
| 545 | |||
| 546 | $signedMsg = $this->oCertificate->signXML($cons, 'infEvento'); |
||
| 547 | $signedMsg = preg_replace("/<\?xml.*\?>/", "", $signedMsg); |
||
| 548 | |||
| 549 | //$signedMsg = Strings::clearXml($signedMsg, true); |
||
| 550 | |||
| 551 | // if (! $this->zValidMessage($signedMsg, 'cte', 'envEvento', $this->urlVersion)) { |
||
| 552 | // $msg = 'Falha na validação. '.$this->error; |
||
| 553 | // throw new Exception\RuntimeException($msg); |
||
| 554 | // } |
||
| 555 | |||
| 556 | |||
| 557 | // $filename = "../cancelamento.xml"; |
||
| 558 | // $xml = file_get_contents($filename); |
||
| 559 | |||
| 560 | |||
| 561 | //$body = "<cteDadosMsg xmlns=\"$this->urlNamespace\">$xml</cteDadosMsg>"; |
||
| 562 | $body = "<cteDadosMsg xmlns=\"$this->urlNamespace\">$signedMsg</cteDadosMsg>"; |
||
| 563 | |||
| 564 | $retorno = $this->oSoap->send( |
||
| 565 | $this->urlService, |
||
| 566 | $this->urlNamespace, |
||
| 567 | $this->urlHeader, |
||
| 568 | $body, |
||
| 569 | $this->urlMethod |
||
| 570 | ); |
||
| 571 | $lastMsg = $this->oSoap->lastMsg; |
||
| 572 | $this->soapDebug = $this->oSoap->soapDebug; |
||
| 573 | //salva mensagens |
||
| 574 | $filename = "$chCTe-$aliasEvento-envEvento.xml"; |
||
| 575 | $this->zGravaFile('cte', $tpAmb, $filename, $lastMsg); |
||
| 576 | $filename = "$chCTe-$aliasEvento-retEnvEvento.xml"; |
||
| 577 | $this->zGravaFile('cte', $tpAmb, $filename, $retorno); |
||
| 578 | //tratar dados de retorno |
||
| 579 | $this->aLastRetEvent = Response::readReturnSefaz($servico, $retorno); |
||
| 580 | if ($this->aLastRetEvent['cStat'] == '128') { |
||
| 581 | if ($this->aLastRetEvent['evento'][0]['cStat'] == '135' || |
||
| 582 | $this->aLastRetEvent['evento'][0]['cStat'] == '136' || |
||
| 583 | $this->aLastRetEvent['evento'][0]['cStat'] == '155' |
||
| 584 | ) { |
||
| 585 | $pasta = 'eventos'; //default |
||
| 586 | if ($aliasEvento == 'CanCTe') { |
||
| 587 | $pasta = 'canceladas'; |
||
| 588 | $filename = "$chCTe-$aliasEvento-procEvento.xml"; |
||
| 589 | } elseif ($aliasEvento == 'CCe') { |
||
| 590 | $pasta = 'cartacorrecao'; |
||
| 591 | $filename = "$chCTe-$aliasEvento-$nSeqEvento-procEvento.xml"; |
||
| 592 | } |
||
| 593 | $retorno = $this->zAddProtMsg('procEventoCTe', 'evento', $signedMsg, 'retEvento', $retorno); |
||
| 594 | $this->zGravaFile('cte', $tpAmb, $filename, $retorno, $pasta); |
||
| 595 | } |
||
| 596 | } |
||
| 597 | return (string) $retorno; |
||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * zAddProtMsg |
||
| 602 | * |
||
| 603 | * @param string $tagproc |
||
| 604 | * @param string $tagmsg |
||
| 605 | * @param string $xmlmsg |
||
| 606 | * @param string $tagretorno |
||
| 607 | * @param string $xmlretorno |
||
| 608 | * @return string |
||
| 609 | */ |
||
| 610 | protected function zAddProtMsg($tagproc, $tagmsg, $xmlmsg, $tagretorno, $xmlretorno) |
||
| 611 | { |
||
| 612 | $doc = new Dom(); |
||
| 613 | $doc->loadXMLString($xmlmsg); |
||
| 614 | $nodedoc = $doc->getNode($tagmsg, 0); |
||
| 615 | $procver = $nodedoc->getAttribute("versao"); |
||
| 616 | $procns = $nodedoc->getAttribute("xmlns"); |
||
| 617 | |||
| 618 | $doc1 = new Dom(); |
||
| 619 | $doc1->loadXMLString($xmlretorno); |
||
| 620 | $nodedoc1 = $doc1->getNode($tagretorno, 0); |
||
| 621 | |||
| 622 | $proc = new \DOMDocument('1.0', 'utf-8'); |
||
| 623 | $proc->formatOutput = false; |
||
| 624 | $proc->preserveWhiteSpace = false; |
||
| 625 | //cria a tag nfeProc |
||
| 626 | $procNode = $proc->createElement($tagproc); |
||
| 627 | $proc->appendChild($procNode); |
||
| 628 | //estabele o atributo de versão |
||
| 629 | $procNodeAtt1 = $procNode->appendChild($proc->createAttribute('versao')); |
||
| 630 | $procNodeAtt1->appendChild($proc->createTextNode($procver)); |
||
| 631 | //estabelece o atributo xmlns |
||
| 632 | $procNodeAtt2 = $procNode->appendChild($proc->createAttribute('xmlns')); |
||
| 633 | $procNodeAtt2->appendChild($proc->createTextNode($procns)); |
||
| 634 | //inclui a tag inutNFe |
||
| 635 | $node = $proc->importNode($nodedoc, true); |
||
| 636 | $procNode->appendChild($node); |
||
| 637 | //inclui a tag retInutNFe |
||
| 638 | $node = $proc->importNode($nodedoc1, true); |
||
| 639 | $procNode->appendChild($node); |
||
| 640 | //salva o xml como string em uma variável |
||
| 641 | $procXML = $proc->saveXML(); |
||
| 642 | //remove as informações indesejadas |
||
| 643 | $procXML = Strings::clearProt($procXML); |
||
| 644 | return $procXML; |
||
| 645 | } |
||
| 646 | |||
| 647 | /** |
||
| 648 | * zTpEv |
||
| 649 | * @param string $tpEvento |
||
| 650 | * @return array |
||
| 651 | * @throws Exception\RuntimeException |
||
| 652 | */ |
||
| 653 | private function zTpEv($tpEvento = '') |
||
| 654 | { |
||
| 655 | //montagem dos dados da mensagem SOAP |
||
| 656 | switch ($tpEvento) { |
||
| 657 | case '110110': |
||
| 658 | //CCe |
||
| 659 | $aliasEvento = 'CCe'; |
||
| 660 | $descEvento = 'Carta de Correcao'; |
||
| 661 | break; |
||
| 662 | case '110111': |
||
| 663 | //cancelamento |
||
| 664 | $aliasEvento = 'CancNFe'; |
||
| 665 | $descEvento = 'Cancelamento'; |
||
| 666 | break; |
||
| 667 | case '110140': |
||
| 668 | //EPEC |
||
| 669 | //emissão em contingência EPEC |
||
| 670 | $aliasEvento = 'EPEC'; |
||
| 671 | $descEvento = 'EPEC'; |
||
| 672 | break; |
||
| 673 | case '111500': |
||
| 674 | case '111501': |
||
| 675 | //EPP |
||
| 676 | //Pedido de prorrogação |
||
| 677 | $aliasEvento = 'EPP'; |
||
| 678 | $descEvento = 'Pedido de Prorrogacao'; |
||
| 679 | break; |
||
| 680 | case '111502': |
||
| 681 | case '111503': |
||
| 682 | //ECPP |
||
| 683 | //Cancelamento do Pedido de prorrogação |
||
| 684 | $aliasEvento = 'ECPP'; |
||
| 685 | $descEvento = 'Cancelamento de Pedido de Prorrogacao'; |
||
| 686 | break; |
||
| 687 | case '210200': |
||
| 688 | //Confirmacao da Operacao |
||
| 689 | $aliasEvento = 'EvConfirma'; |
||
| 690 | $descEvento = 'Confirmacao da Operacao'; |
||
| 691 | break; |
||
| 692 | case '210210': |
||
| 693 | //Ciencia da Operacao |
||
| 694 | $aliasEvento = 'EvCiencia'; |
||
| 695 | $descEvento = 'Ciencia da Operacao'; |
||
| 696 | break; |
||
| 697 | case '210220': |
||
| 698 | //Desconhecimento da Operacao |
||
| 699 | $aliasEvento = 'EvDesconh'; |
||
| 700 | $descEvento = 'Desconhecimento da Operacao'; |
||
| 701 | break; |
||
| 702 | case '210240': |
||
| 703 | //Operacao não Realizada |
||
| 704 | $aliasEvento = 'EvNaoRealizada'; |
||
| 705 | $descEvento = 'Operacao nao Realizada'; |
||
| 706 | break; |
||
| 707 | default: |
||
| 708 | $msg = "O código do tipo de evento informado não corresponde a " |
||
| 709 | . "nenhum evento estabelecido."; |
||
| 710 | throw new Exception\RuntimeException($msg); |
||
| 711 | } |
||
| 712 | return array('alias' => $aliasEvento, 'desc' => $descEvento); |
||
| 713 | } |
||
| 714 | |||
| 715 | private function zValidParamInut($xJust, $nSerie, $nIni, $nFin) |
||
| 716 | { |
||
| 717 | $msg = ''; |
||
| 718 | $nL = strlen($xJust); |
||
| 719 | |||
| 720 | // Valida dos dados de entrada |
||
| 721 | if ($nIni == '' || $nFin == '' || $xJust == '') { |
||
| 722 | $msg = "Não foi passado algum dos parametos necessários" |
||
| 723 | . "inicio=$nIni fim=$nFin justificativa=$xJust."; |
||
| 724 | View Code Duplication | } elseif (strlen($nSerie) == 0 || strlen($nSerie) > 3) { |
|
| 725 | $msg = "O campo serie está errado: $nSerie. Corrija e refaça o processo!!"; |
||
| 726 | } elseif (strlen($nIni) < 1 || strlen($nIni) > 9) { |
||
| 727 | $msg = "O campo numero inicial está errado: $nIni. Corrija e refaça o processo!!"; |
||
| 728 | } elseif (strlen($nFin) < 1 || strlen($nFin) > 9) { |
||
| 729 | $msg = "O campo numero final está errado: $nFin. Corrija e refaça o processo!!"; |
||
| 730 | } elseif ($nL < 15 || $nL > 255) { |
||
| 731 | $msg = "A justificativa tem que ter entre 15 e 255 caracteres, encontrado $nL. " |
||
| 732 | . "Corrija e refaça o processo!!"; |
||
| 733 | } |
||
| 734 | |||
| 735 | if ($msg != '') { |
||
| 736 | throw new Exception\InvalidArgumentException($msg); |
||
| 737 | } |
||
| 738 | } |
||
| 739 | |||
| 740 | /** |
||
| 741 | * validarXml |
||
| 742 | * Valida qualquer xml do sistema NFe com seu xsd |
||
| 743 | * NOTA: caso não exista um arquivo xsd apropriado retorna false |
||
| 744 | * @param string $xml path ou conteudo do xml |
||
| 745 | * @return boolean |
||
| 746 | */ |
||
| 747 | public function validarXml($xml = '') |
||
| 748 | { |
||
| 749 | $aResp = array(); |
||
| 750 | $schem = IdentifyCTe::identificar($xml, $aResp); |
||
| 751 | if ($schem == '') { |
||
| 752 | return true; |
||
| 753 | } |
||
| 754 | $xsdFile = $aResp['Id'].'_v'.$aResp['versao'].'.xsd'; |
||
| 755 | $xsdPath = NFEPHP_ROOT.DIRECTORY_SEPARATOR . |
||
| 756 | 'schemas' . |
||
| 757 | DIRECTORY_SEPARATOR . |
||
| 758 | $this->aConfig['schemesCTe'] . |
||
| 759 | DIRECTORY_SEPARATOR . |
||
| 760 | $xsdFile; |
||
| 761 | if (! is_file($xsdPath)) { |
||
| 762 | $this->erros[] = "O arquivo XSD $xsdFile não foi localizado."; |
||
| 763 | return false; |
||
| 764 | } |
||
| 765 | if (! ValidXsd::validar($aResp['xml'], $xsdPath)) { |
||
| 766 | $this->erros[] = ValidXsd::$errors; |
||
| 767 | return false; |
||
| 768 | } |
||
| 769 | return true; |
||
| 770 | } |
||
| 771 | |||
| 772 | public function sefazInutiliza( |
||
| 879 | } |
||
| 880 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.