wapplay 7 年 前
コミット
e1866215a6

+ 1 - 0
composer.json

@@ -21,6 +21,7 @@
         }
     ],
     "require": {
+        "ext-zlib": "*",
         "php": "^5.5 || ^7.0",
         "psr/http-message": "^1.0"
     },

+ 5 - 1
src/PhpZip/Crypto/WinZipAesEngine.php

@@ -179,9 +179,11 @@ class WinZipAesEngine implements ZipEncryptionEngine
     {
         if (extension_loaded("openssl")) {
             $numBits = strlen($key) * 8;
+            /** @noinspection PhpComposerExtensionStubsInspection */
             return openssl_encrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv);
         } elseif (extension_loaded("mcrypt")) {
             /** @noinspection PhpDeprecationInspection */
+            /** @noinspection PhpComposerExtensionStubsInspection */
             return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv);
         } else {
             throw new RuntimeException('Extension openssl or mcrypt not loaded');
@@ -200,9 +202,11 @@ class WinZipAesEngine implements ZipEncryptionEngine
     {
         if (extension_loaded("openssl")) {
             $numBits = strlen($key) * 8;
+            /** @noinspection PhpComposerExtensionStubsInspection */
             return openssl_decrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv);
         } elseif (extension_loaded("mcrypt")) {
             /** @noinspection PhpDeprecationInspection */
+            /** @noinspection PhpComposerExtensionStubsInspection */
             return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv);
         } else {
             throw new RuntimeException('Extension openssl or mcrypt not loaded');
@@ -220,7 +224,7 @@ class WinZipAesEngine implements ZipEncryptionEngine
     {
         // Init key strength.
         $password = $this->entry->getPassword();
-        if ($password === null){
+        if ($password === null) {
             throw new ZipException('No password was set for the entry "'.$this->entry->getName().'"');
         }
 

+ 1 - 1
src/PhpZip/Extra/ExtraFieldsCollection.php

@@ -152,7 +152,7 @@ class ExtraFieldsCollection implements \Countable, \ArrayAccess, \Iterator
     public function offsetSet($offset, $value)
     {
         if ($value instanceof ExtraField) {
-            if ($offset !== $value::getHeaderId()){
+            if ($offset !== $value::getHeaderId()) {
                 throw new InvalidArgumentException("Value header id !== array access key");
             }
             $this->add($value);

+ 1 - 0
src/PhpZip/Model/Entry/ZipChangesEntry.php

@@ -48,6 +48,7 @@ class ZipChangesEntry extends ZipAbstractEntry
      * Returns an string content of the given entry.
      *
      * @return null|string
+     * @throws ZipException
      */
     public function getEntryContent()
     {

+ 1 - 2
src/PhpZip/Model/Entry/ZipSourceEntry.php

@@ -57,7 +57,6 @@ class ZipSourceEntry extends ZipAbstractEntry
      * Returns an string content of the given entry.
      *
      * @return string
-     * @throws ZipException
      */
     public function getEntryContent()
     {
@@ -74,7 +73,7 @@ class ZipSourceEntry extends ZipAbstractEntry
         }
         if (is_resource($this->entryContent)) {
             rewind($this->entryContent);
-            return stream_get_contents($this->entryContent, -1, 0);
+            return stream_get_contents($this->entryContent);
         }
         return $this->entryContent;
     }

+ 1 - 3
src/PhpZip/Model/ZipInfo.php

@@ -1,4 +1,4 @@
-<?php
+<?php /** @noinspection PhpMissingBreakStatementInspection */
 
 namespace PhpZip\Model;
 
@@ -233,8 +233,6 @@ class ZipInfo
         $xattr = (($externalAttributes >> 16) & 0xFFFF);
         switch ($entry->getPlatform()) {
             case self::MADE_BY_MS_DOS:
-                // no break
-                /** @noinspection PhpMissingBreakStatementInspection */
             case self::MADE_BY_WINDOWS_NTFS:
                 if ($entry->getPlatform() != self::MADE_BY_MS_DOS ||
                     ($xattr & 0700) !=

+ 2 - 1
src/PhpZip/Stream/ZipInputStream.php

@@ -446,6 +446,7 @@ class ZipInputStream implements ZipInputStreamInterface
                 if (!extension_loaded('bz2')) {
                     throw new ZipException('Extension bzip2 not install');
                 }
+                /** @noinspection PhpComposerExtensionStubsInspection */
                 $content = bzdecompress($content);
                 break;
             default:
@@ -552,7 +553,7 @@ class ZipInputStream implements ZipInputStreamInterface
             // skip source extraLength from input stream
             fseek($this->in, $sourceExtraLength, SEEK_CUR);
         } else {
-            $copyInToOutLength += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $sourceExtraLength + $nameLength;;
+            $copyInToOutLength += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $sourceExtraLength + $nameLength;
         }
         if ($entry->getGeneralPurposeBitFlag(ZipEntry::GPBF_DATA_DESCRIPTOR)) {
 //            crc-32                          4 bytes

+ 1 - 0
src/PhpZip/Stream/ZipOutputStream.php

@@ -255,6 +255,7 @@ class ZipOutputStream implements ZipOutputStreamInterface
                         $compressionLevel = $entry->getCompressionLevel() === ZipFileInterface::LEVEL_DEFAULT_COMPRESSION ?
                             ZipEntry::LEVEL_DEFAULT_BZIP2_COMPRESSION :
                             $entry->getCompressionLevel();
+                        /** @noinspection PhpComposerExtensionStubsInspection */
                         $entryContent = bzcompress($entryContent, $compressionLevel);
                         if (is_int($entryContent)) {
                             throw new ZipException('Error bzip2 compress. Error code: ' . $entryContent);

+ 2 - 0
src/PhpZip/Util/CryptoUtil.php

@@ -26,9 +26,11 @@ class CryptoUtil
                 throw new \RuntimeException("Could not generate a random string.");
             }
         } elseif (function_exists('openssl_random_pseudo_bytes')) {
+            /** @noinspection PhpComposerExtensionStubsInspection */
             return openssl_random_pseudo_bytes($length);
         } elseif (function_exists('mcrypt_create_iv')) {
             /** @noinspection PhpDeprecationInspection */
+            /** @noinspection PhpComposerExtensionStubsInspection */
             return mcrypt_create_iv($length);
         } else {
             throw new RuntimeException('Extension openssl or mcrypt not loaded');

+ 4 - 6
src/PhpZip/ZipFile.php

@@ -423,6 +423,7 @@ class ZipFile implements ZipFileInterface
 
         if ($compressionMethod === null) {
             if (function_exists('mime_content_type')) {
+                /** @noinspection PhpComposerExtensionStubsInspection */
                 $mimeType = @mime_content_type($filename);
                 $type = strtok($mimeType, '/');
                 if ($type === 'image') {
@@ -611,8 +612,7 @@ class ZipFile implements ZipFileInterface
         \Iterator $iterator,
         $localPath = '/',
         $compressionMethod = null
-    )
-    {
+    ) {
         $localPath = (string)$localPath;
         if (strlen($localPath) !== 0) {
             $localPath = trim($localPath, '\\/');
@@ -696,8 +696,7 @@ class ZipFile implements ZipFileInterface
         $localPath = '/',
         $recursive = true,
         $compressionMethod = null
-    )
-    {
+    ) {
         $inputDir = (string)$inputDir;
         if (strlen($inputDir) === 0) {
             throw new InvalidArgumentException('Input dir empty');
@@ -793,8 +792,7 @@ class ZipFile implements ZipFileInterface
         $localPath = "/",
         $recursive = true,
         $compressionMethod = null
-    )
-    {
+    ) {
         $regexPattern = (string)$regexPattern;
         if (empty($regexPattern)) {
             throw new InvalidArgumentException("regex pattern empty");

+ 5 - 0
tests/PhpZip/ZipFileTest.php

@@ -33,6 +33,7 @@ class ZipFileTest extends ZipTestCase
      */
     public function testOpenFileCantOpen()
     {
+        /** @noinspection PhpComposerExtensionStubsInspection */
         if (0 === posix_getuid()) {
             $this->markTestSkipped('Skip the test for a user with root privileges');
         }
@@ -152,6 +153,7 @@ class ZipFileTest extends ZipTestCase
         if (!extension_loaded("gd")) {
             $this->markTestSkipped('not extension gd');
         }
+        /** @noinspection PhpComposerExtensionStubsInspection */
         $zipFile->openFromStream(imagecreate(1, 1));
     }
 
@@ -1057,6 +1059,7 @@ class ZipFileTest extends ZipTestCase
      */
     public function testExtractFail3()
     {
+        /** @noinspection PhpComposerExtensionStubsInspection */
         if (0 === posix_getuid()) {
             $this->markTestSkipped('Skip the test for a user with root privileges');
         }
@@ -1275,6 +1278,7 @@ class ZipFileTest extends ZipTestCase
      */
     public function testAddFileCantOpen()
     {
+        /** @noinspection PhpComposerExtensionStubsInspection */
         if (posix_getuid() === 0) {
             $this->markTestSkipped('Skip the test for a user with root privileges');
         }
@@ -1588,6 +1592,7 @@ class ZipFileTest extends ZipTestCase
      */
     public function testSaveAsFileNotWritable()
     {
+        /** @noinspection PhpComposerExtensionStubsInspection */
         if (0 === posix_getuid()) {
             $this->markTestSkipped('Skip the test for a user with root privileges');
         }