diff --git a/composer.json b/composer.json index 7a56479..8f3ca0a 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ } ], "require": { + "ext-zlib": "*", "php": "^5.5 || ^7.0", "psr/http-message": "^1.0" }, diff --git a/src/PhpZip/Crypto/WinZipAesEngine.php b/src/PhpZip/Crypto/WinZipAesEngine.php index e070bd5..5bdd7a7 100644 --- a/src/PhpZip/Crypto/WinZipAesEngine.php +++ b/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().'"'); } diff --git a/src/PhpZip/Extra/ExtraFieldsCollection.php b/src/PhpZip/Extra/ExtraFieldsCollection.php index e7922de..b93a8d4 100644 --- a/src/PhpZip/Extra/ExtraFieldsCollection.php +++ b/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); diff --git a/src/PhpZip/Model/Entry/ZipChangesEntry.php b/src/PhpZip/Model/Entry/ZipChangesEntry.php index 100512c..17e8144 100644 --- a/src/PhpZip/Model/Entry/ZipChangesEntry.php +++ b/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() { diff --git a/src/PhpZip/Model/Entry/ZipSourceEntry.php b/src/PhpZip/Model/Entry/ZipSourceEntry.php index f443fd4..dc80c27 100644 --- a/src/PhpZip/Model/Entry/ZipSourceEntry.php +++ b/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; } diff --git a/src/PhpZip/Model/ZipInfo.php b/src/PhpZip/Model/ZipInfo.php index c9de660..4fbb608 100644 --- a/src/PhpZip/Model/ZipInfo.php +++ b/src/PhpZip/Model/ZipInfo.php @@ -1,4 +1,4 @@ -> 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) != diff --git a/src/PhpZip/Stream/ZipInputStream.php b/src/PhpZip/Stream/ZipInputStream.php index 8ea5e24..37dd6be 100644 --- a/src/PhpZip/Stream/ZipInputStream.php +++ b/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 diff --git a/src/PhpZip/Stream/ZipOutputStream.php b/src/PhpZip/Stream/ZipOutputStream.php index 3afe057..ce0cd74 100644 --- a/src/PhpZip/Stream/ZipOutputStream.php +++ b/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); diff --git a/src/PhpZip/Util/CryptoUtil.php b/src/PhpZip/Util/CryptoUtil.php index 8108f7f..d7a659c 100644 --- a/src/PhpZip/Util/CryptoUtil.php +++ b/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'); diff --git a/src/PhpZip/ZipFile.php b/src/PhpZip/ZipFile.php index 50a23e4..2ae2583 100644 --- a/src/PhpZip/ZipFile.php +++ b/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"); diff --git a/tests/PhpZip/ZipFileTest.php b/tests/PhpZip/ZipFileTest.php index 35a7e4f..db3a36e 100644 --- a/tests/PhpZip/ZipFileTest.php +++ b/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'); }