diff --git a/src/Ws/Services/BaseSunat.php b/src/Ws/Services/BaseSunat.php index 4e005b5..3b89dca 100644 --- a/src/Ws/Services/BaseSunat.php +++ b/src/Ws/Services/BaseSunat.php @@ -11,7 +11,8 @@ use Greenter\Model\Response\Error; use Greenter\Ws\Reader\DomCdrReader; use Greenter\Ws\Reader\XmlErrorReader; -use Greenter\Zip\ZipFactory; +use Greenter\Zip\ZipReader; +use Greenter\Zip\ZipWriter; /** * Class BaseSunat @@ -78,7 +79,8 @@ protected function getErrorFromFault(\SoapFault $fault) */ protected function compress($filename, $xml) { - return (new ZipFactory())->compress($filename, $xml); + return (new ZipWriter()) + ->compress($filename, $xml); } /** @@ -87,11 +89,11 @@ protected function compress($filename, $xml) */ protected function extractResponse($zipContent) { - $zip = new ZipFactory(); - $xml = $zip->decompressXmlFile($zipContent); - $reader = new DomCdrReader(); + $xml = (new ZipReader()) + ->decompressXmlFile($zipContent); - return $reader->getCdrResponse($xml); + return (new DomCdrReader()) + ->getCdrResponse($xml); } /** @@ -100,8 +102,8 @@ protected function extractResponse($zipContent) */ protected function getMessageError($code) { - $search = new XmlErrorReader(); - $msg = $search->getMessageByCode(intval($code)); + $msg = (new XmlErrorReader()) + ->getMessageByCode(intval($code)); return $msg; } diff --git a/src/Ws/Services/BillSender.php b/src/Ws/Services/BillSender.php index e7aca22..690b236 100644 --- a/src/Ws/Services/BillSender.php +++ b/src/Ws/Services/BillSender.php @@ -17,7 +17,6 @@ */ class BillSender extends BaseSunat implements SenderInterface { - /** * @param string $filename * @param string $content diff --git a/src/Zip/ZipFactory.php b/src/Zip/ZipReader.php similarity index 77% rename from src/Zip/ZipFactory.php rename to src/Zip/ZipReader.php index 62a7150..974ac10 100644 --- a/src/Zip/ZipFactory.php +++ b/src/Zip/ZipReader.php @@ -12,25 +12,10 @@ * Class ZipFactory * @package Greenter\Zip */ -final class ZipFactory +final class ZipReader { const UNZIP_FORMAT = 'Vsig/vver/vflag/vmeth/vmodt/vmodd/Vcrc/Vcsize/Vsize/vnamelen/vexlen'; - /** - * Comprime el contenido del archivo con el nombre especifico y retorna el contenido del zip. - * - * @param string $filename - * @param string $content - * @return string - */ - public function compress($filename, $content) - { - $archive = new ZipFile(); - $archive->addFile($content, $filename); - - return $archive->file(); - } - /** * Retorna el contenido del primer xml dentro del zip. * diff --git a/src/Zip/ZipFile.php b/src/Zip/ZipWriter.php similarity index 93% rename from src/Zip/ZipFile.php rename to src/Zip/ZipWriter.php index 85ca3c4..c7c0afd 100644 --- a/src/Zip/ZipFile.php +++ b/src/Zip/ZipWriter.php @@ -11,7 +11,7 @@ /** * Class ZipFile. */ -class ZipFile +class ZipWriter { /** * Array to store compressed data. @@ -65,8 +65,6 @@ public function unix2DosTime($unixtime = 0) | ($timearray['seconds'] >> 1); } - // end of the 'unix2DosTime()' method - /** * Adds "file" to archive. * @@ -148,5 +146,18 @@ public function file() return $data.$header; } + /** + * Comprime el contenido del archivo con el nombre especifico y retorna el contenido del zip. + * + * @param string $filename + * @param string $content + * @return string + */ + public function compress($filename, $content) + { + $this->addFile($content, $filename); + + return $this->file(); + } // end of the 'file()' method } diff --git a/tests/Ws/Zip/ZipFactoryTest.php b/tests/Ws/Zip/ZipFactoryTest.php index 4891e31..938a639 100644 --- a/tests/Ws/Zip/ZipFactoryTest.php +++ b/tests/Ws/Zip/ZipFactoryTest.php @@ -8,8 +8,8 @@ namespace Tests\Greenter\Zip; -use Greenter\Zip\ZipFactory; -use Greenter\Zip\ZipFile; +use Greenter\Zip\ZipReader; +use Greenter\Zip\ZipWriter; /** * Class ZipFactoryTest @@ -29,7 +29,7 @@ public function testCompressFile() public function testDecompressLastFile() { $zipContent = $this->createZip(); - $helper = new ZipFactory(); + $helper = new ZipReader(); $content = $helper->decompressXmlFile($zipContent); $this->assertEquals(self::DATA_XML, $content); @@ -37,7 +37,7 @@ public function testDecompressLastFile() public function testUnixTime() { - $zip = new ZipFile(); + $zip = new ZipWriter(); $result = $zip->unix2DosTime(181233012); $this->assertEquals(2162688, $result); @@ -45,7 +45,7 @@ public function testUnixTime() public function testInvalidZip() { - $zip = new ZipFactory(); + $zip = new ZipReader(); $res = $zip->decompressXmlFile(''); $this->assertEmpty($res); @@ -53,17 +53,17 @@ public function testInvalidZip() public function testNotXmlZip() { - $helper = new ZipFactory(); + $helper = new ZipWriter(); $zip = $helper->compress('myFile.txt', 'TEST TEXT 1'); - $res = $helper->decompressXmlFile($zip); + $res = (new ZipReader())->decompressXmlFile($zip); $this->assertEmpty($res); } private function createZip() { - $helper = new ZipFactory(); + $helper = new ZipWriter(); $zip = $helper->compress('myFile.xml', self::DATA_XML); return $zip;