Code Duplication    Length = 49-50 lines in 2 locations

src/Tools.php 2 locations

@@ 535-583 (lines=49) @@
532
     * @throws   Exception\RuntimeException
533
     * @internal function zLoadServico (Common\Base\BaseTools)
534
     */
535
    public function sefazStatus($siglaUF = '', $tpAmb = '2', &$aRetorno = array())
536
    {
537
        if ($tpAmb == '') {
538
            $tpAmb = $this->aConfig['tpAmb'];
539
        }
540
        if ($siglaUF == '') {
541
            $siglaUF = $this->aConfig['siglaUF'];
542
        }
543
        //carrega serviço
544
        $servico = 'MDFeStatusServico';
545
        $this->zLoadServico(
546
            'mdfe',
547
            $servico,
548
            $siglaUF,
549
            $tpAmb
550
        );
551
        if ($this->urlService == '') {
552
            $msg = "O status não está disponível na SEFAZ $siglaUF!!!";
553
            throw new Exception\RuntimeException($msg);
554
        }
555
        $cons = "<consStatServMDFe xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">"
556
            . "<tpAmb>$tpAmb</tpAmb>"
557
            . "<xServ>STATUS</xServ></consStatServMDFe>";
558
        //valida mensagem com xsd
559
        //if (! $this->zValidMessage($cons, 'mdfe', 'consStatServMDFe', $version)) {
560
        //    $msg = 'Falha na validação. '.$this->error;
561
        //    throw new Exception\RuntimeException($msg);
562
        //}
563
        //montagem dos dados da mensagem SOAP
564
        $body = "<mdfeDadosMsg xmlns=\"$this->urlNamespace\">$cons</mdfeDadosMsg>";
565
        //consome o webservice e verifica o retorno do SOAP
566
        $retorno = $this->oSoap->send(
567
            $this->urlService,
568
            $this->urlNamespace,
569
            $this->urlHeader,
570
            $body,
571
            $this->urlMethod
572
        );
573
        $lastMsg = $this->oSoap->lastMsg;
574
        $this->soapDebug = $this->oSoap->soapDebug;
575
        $datahora = date('Ymd_His');
576
        $filename = $siglaUF."_"."$datahora-consStatServ.xml";
577
        $this->zGravaFile('mdfe', $tpAmb, $filename, $lastMsg);
578
        $filename = $siglaUF."_"."$datahora-retConsStatServ.xml";
579
        $this->zGravaFile('mdfe', $tpAmb, $filename, $retorno);
580
        //tratar dados de retorno
581
        $aRetorno = Response::readReturnSefaz($servico, $retorno);
582
        return (string) $retorno;
583
    }
584
585
    /**
586
     * sefazCancela
@@ 740-789 (lines=50) @@
737
     * @return string
738
     * @throws Exception\RuntimeException
739
     */
740
    public function sefazConsultaNaoEncerrados($tpAmb = '2', $cnpj = '', &$aRetorno = array())
741
    {
742
        if ($tpAmb == '') {
743
            $tpAmb = $this->aConfig['tpAmb'];
744
        }
745
        if ($cnpj == '') {
746
            $cnpj = $this->aConfig['cnpj'];
747
        }
748
        $siglaUF = $this->aConfig['siglaUF'];
749
        //carrega serviço
750
        $servico = 'MDFeConsNaoEnc';
751
        $this->zLoadServico(
752
            'mdfe',
753
            $servico,
754
            $siglaUF,
755
            $tpAmb
756
        );
757
        if ($this->urlService == '') {
758
            $msg = "O serviço não está disponível na SEFAZ $siglaUF!!!";
759
            throw new Exception\RuntimeException($msg);
760
        }
761
        $cons = "<consMDFeNaoEnc xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">"
762
            . "<tpAmb>$tpAmb</tpAmb>"
763
            . "<xServ>CONSULTAR NÃO ENCERRADOS</xServ><CNPJ>$cnpj</CNPJ></consMDFeNaoEnc>";
764
        //valida mensagem com xsd
765
        //if (! $this->zValidMessage($cons, 'mdfe', 'consMDFeNaoEnc', $version)) {
766
        //    $msg = 'Falha na validação. '.$this->error;
767
        //    throw new Exception\RuntimeException($msg);
768
        //}
769
        //montagem dos dados da mensagem SOAP
770
        $body = "<mdefDadosMsg xmlns=\"$this->urlNamespace\">$cons</mdfeDadosMsg>";
771
        //consome o webservice e verifica o retorno do SOAP
772
        $retorno = $this->oSoap->send(
773
            $this->urlService,
774
            $this->urlNamespace,
775
            $this->urlHeader,
776
            $body,
777
            $this->urlMethod
778
        );
779
        $lastMsg = $this->oSoap->lastMsg;
780
        $this->soapDebug = $this->oSoap->soapDebug;
781
        $datahora = date('Ymd_His');
782
        $filename = $siglaUF."_"."$datahora-consNaoEnc.xml";
783
        $this->zGravaFile('mdfe', $tpAmb, $filename, $lastMsg);
784
        $filename = $siglaUF."_"."$datahora-retConsNaoEnc.xml";
785
        $this->zGravaFile('mdfe', $tpAmb, $filename, $retorno);
786
        //tratar dados de retorno
787
        $aRetorno = Response::readReturnSefaz($servico, $retorno);
788
        return (string) $retorno;
789
    }
790
791
    /**
792
     * zSefazEvento