mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-10-12 13:54:28 +02:00
Update README
This commit is contained in:
@@ -213,7 +213,7 @@ class TraditionalPkwareEncryptionEngine implements CryptoEngine
|
||||
*/
|
||||
private function encryptData($content)
|
||||
{
|
||||
if ($content === null) {
|
||||
if (null === $content) {
|
||||
throw new ZipCryptoException('content is null');
|
||||
}
|
||||
$buff = '';
|
||||
|
@@ -119,7 +119,7 @@ class WinZipAesEngine implements CryptoEngine
|
||||
$content = substr($content, $start, $size);
|
||||
$mac = hash_hmac('sha1', $content, $sha1MacParam, true);
|
||||
|
||||
if ($authenticationCode !== substr($mac, 0, 10)) {
|
||||
if (substr($mac, 0, 10) !== $authenticationCode) {
|
||||
throw new ZipAuthenticationException($this->entry->getName() .
|
||||
" (authenticated WinZip AES entry content has been tampered with)");
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class WinZipAesEngine implements CryptoEngine
|
||||
for ($i = 0; $i < $numOfBlocks; ++$i) {
|
||||
for ($j = 0; $j < 16; ++$j) {
|
||||
$n = ord($iv[$j]);
|
||||
if (++$n === 0x100) {
|
||||
if (0x100 === ++$n) {
|
||||
// overflow, set this one to 0, increment next
|
||||
$iv[$j] = chr(0);
|
||||
} else {
|
||||
|
@@ -45,7 +45,7 @@ abstract class ExtraField implements ExtraFieldHeader
|
||||
if (isset(self::getRegistry()[$headerId])) {
|
||||
$extraClassName = self::getRegistry()[$headerId];
|
||||
$extraField = new $extraClassName;
|
||||
if ($headerId !== $extraField::getHeaderId()) {
|
||||
if ($extraField::getHeaderId() !== $headerId) {
|
||||
throw new ZipException('Runtime error support headerId ' . $headerId);
|
||||
}
|
||||
} else {
|
||||
@@ -61,7 +61,7 @@ abstract class ExtraField implements ExtraFieldHeader
|
||||
*/
|
||||
private static function getRegistry()
|
||||
{
|
||||
if (self::$registry === null) {
|
||||
if (null === self::$registry) {
|
||||
self::$registry[WinZipAesEntryExtraField::getHeaderId()] = WinZipAesEntryExtraField::class;
|
||||
self::$registry[NtfsExtraField::getHeaderId()] = NtfsExtraField::class;
|
||||
}
|
||||
|
@@ -86,7 +86,7 @@ class NtfsExtraField extends ExtraField
|
||||
fseek($handle, $off, SEEK_SET);
|
||||
|
||||
$unpack = unpack('vtag/vsizeAttr', fread($handle, 4));
|
||||
if ($unpack['sizeAttr'] === 24) {
|
||||
if (24 === $unpack['sizeAttr']) {
|
||||
$tagData = fread($handle, $unpack['sizeAttr']);
|
||||
|
||||
$this->mtime = PackUtil::unpackLongLE(substr($tagData, 0, 8)) / 10000000 - 11644473600;
|
||||
@@ -110,7 +110,7 @@ class NtfsExtraField extends ExtraField
|
||||
*/
|
||||
public function writeTo($handle, $off)
|
||||
{
|
||||
if ($this->mtime !== null && $this->atime !== null && $this->ctime !== null) {
|
||||
if (null !== $this->mtime && null !== $this->atime && null !== $this->ctime) {
|
||||
fseek($handle, $off, SEEK_SET);
|
||||
fwrite($handle, pack('Vvv', 0, 1, 8 * 3 + strlen($this->rawData)));
|
||||
$mtimeLong = ($this->mtime + 11644473600) * 10000000;
|
||||
|
@@ -224,7 +224,7 @@ class CentralDirectory
|
||||
*/
|
||||
public function setZipAlign($zipAlign = null)
|
||||
{
|
||||
if ($zipAlign === null) {
|
||||
if (null === $zipAlign) {
|
||||
$this->zipAlign = null;
|
||||
return;
|
||||
}
|
||||
@@ -331,7 +331,7 @@ class CentralDirectory
|
||||
if (isset($this->modifiedEntries[$entryName])) continue;
|
||||
|
||||
if (
|
||||
($this->password !== null || $this->clearPassword) &&
|
||||
(null !== $this->password || $this->clearPassword) &&
|
||||
$entry->isEncrypted() &&
|
||||
$entry->getPassword() !== null &&
|
||||
(
|
||||
@@ -359,7 +359,7 @@ class CentralDirectory
|
||||
if (null === $outputEntry) { // remove marked entry
|
||||
unset($memoryEntriesResult[$entryName]);
|
||||
} else {
|
||||
if ($this->password !== null) {
|
||||
if (null !== $this->password) {
|
||||
$outputEntry->setPassword($this->password, $this->encryptionMethod);
|
||||
}
|
||||
$memoryEntriesResult[$entryName] = $outputEntry;
|
||||
|
@@ -168,8 +168,7 @@ abstract class ZipAbstractEntry implements ZipEntry
|
||||
if (0x0000 > $length || $length > 0xffff) {
|
||||
throw new ZipException('Illegal zip entry name parameter');
|
||||
}
|
||||
$encoding = mb_detect_encoding($this->name, "ASCII, UTF-8", true);
|
||||
$this->setGeneralPurposeBitFlag(self::GPBF_UTF8, $encoding === 'UTF-8');
|
||||
$this->setGeneralPurposeBitFlag(self::GPBF_UTF8, true);
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
@@ -792,10 +791,7 @@ abstract class ZipAbstractEntry implements ZipEntry
|
||||
throw new ZipException("Comment too long");
|
||||
}
|
||||
}
|
||||
$encoding = mb_detect_encoding($this->name, "ASCII, UTF-8", true);
|
||||
if ($encoding === 'UTF-8') {
|
||||
$this->setGeneralPurposeBitFlag(self::GPBF_UTF8, true);
|
||||
}
|
||||
$this->setGeneralPurposeBitFlag(self::GPBF_UTF8, true);
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
@@ -853,7 +849,7 @@ abstract class ZipAbstractEntry implements ZipEntry
|
||||
public function setPassword($password, $encryptionMethod = null)
|
||||
{
|
||||
$this->password = $password;
|
||||
if ($encryptionMethod !== null) {
|
||||
if (null !== $encryptionMethod) {
|
||||
$this->setEncryptionMethod($encryptionMethod);
|
||||
}
|
||||
$this->setEncrypted(!empty($this->password));
|
||||
|
@@ -240,7 +240,7 @@ abstract class ZipNewEntry extends ZipAbstractEntry
|
||||
fwrite($outputStream, str_repeat(chr(0), $padding));
|
||||
}
|
||||
|
||||
if ($entryContent !== null) {
|
||||
if (null !== $entryContent) {
|
||||
fwrite($outputStream, $entryContent);
|
||||
}
|
||||
|
||||
|
@@ -47,7 +47,7 @@ class ZipNewStreamEntry extends ZipNewEntry
|
||||
*/
|
||||
function __destruct()
|
||||
{
|
||||
if ($this->stream !== null) {
|
||||
if (null !== $this->stream) {
|
||||
fclose($this->stream);
|
||||
$this->stream = null;
|
||||
}
|
||||
|
@@ -118,7 +118,7 @@ class ZipReadEntry extends ZipAbstractEntry
|
||||
*/
|
||||
public function getEntryContent()
|
||||
{
|
||||
if ($this->entryContent === null) {
|
||||
if (null === $this->entryContent) {
|
||||
if ($this->isDirectory()) {
|
||||
$this->entryContent = null;
|
||||
return $this->entryContent;
|
||||
@@ -319,7 +319,7 @@ class ZipReadEntry extends ZipAbstractEntry
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
if ($this->entryContent !== null && is_resource($this->entryContent)) {
|
||||
if (null !== $this->entryContent && is_resource($this->entryContent)) {
|
||||
fclose($this->entryContent);
|
||||
}
|
||||
}
|
||||
|
@@ -193,7 +193,7 @@ class ZipInfo
|
||||
$ctime = null;
|
||||
|
||||
$field = $entry->getExtraField(NtfsExtraField::getHeaderId());
|
||||
if ($field !== null && $field instanceof NtfsExtraField) {
|
||||
if (null !== $field && $field instanceof NtfsExtraField) {
|
||||
/**
|
||||
* @var NtfsExtraField $field
|
||||
*/
|
||||
@@ -311,7 +311,7 @@ class ZipInfo
|
||||
if ($entry->getMethod() === ZipEntry::METHOD_WINZIP_AES) {
|
||||
$field = $entry->getExtraField(WinZipAesEntryExtraField::getHeaderId());
|
||||
$return = ucfirst(self::$valuesCompressionMethod[$entry->getMethod()]);
|
||||
if ($field !== null) {
|
||||
if (null !== $field) {
|
||||
/**
|
||||
* @var WinZipAesEntryExtraField $field
|
||||
*/
|
||||
|
@@ -356,7 +356,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
touch($dir, $entry->getTime());
|
||||
}
|
||||
if (file_put_contents($file, $entry->getEntryContent()) === false) {
|
||||
throw new ZipException('Can not extract file '.$entry->getName());
|
||||
throw new ZipException('Can not extract file ' . $entry->getName());
|
||||
}
|
||||
touch($file, $entry->getTime());
|
||||
}
|
||||
@@ -427,7 +427,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
*/
|
||||
public function addFile($filename, $localName = null, $compressionMethod = null)
|
||||
{
|
||||
if ($filename === null) {
|
||||
if (null === $filename) {
|
||||
throw new InvalidArgumentException("Filename is null");
|
||||
}
|
||||
if (!is_file($filename)) {
|
||||
@@ -438,9 +438,9 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
if (function_exists('mime_content_type')) {
|
||||
$mimeType = @mime_content_type($filename);
|
||||
$type = strtok($mimeType, '/');
|
||||
if ($type === 'image') {
|
||||
if ('image' === $type) {
|
||||
$compressionMethod = self::METHOD_STORED;
|
||||
} elseif ($type === 'text' && filesize($filename) < 150) {
|
||||
} elseif ('text' === $type && filesize($filename) < 150) {
|
||||
$compressionMethod = self::METHOD_STORED;
|
||||
} else {
|
||||
$compressionMethod = self::METHOD_DEFLATED;
|
||||
@@ -457,7 +457,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
if (!($handle = @fopen($filename, 'rb'))) {
|
||||
throw new InvalidArgumentException('File ' . $filename . ' can not open.');
|
||||
}
|
||||
if ($localName === null) {
|
||||
if (null === $localName) {
|
||||
$localName = basename($filename);
|
||||
}
|
||||
$this->addFromStream($handle, $localName, $compressionMethod);
|
||||
@@ -570,7 +570,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
public function addDir($inputDir, $localPath = "/", $compressionMethod = null)
|
||||
{
|
||||
$inputDir = (string)$inputDir;
|
||||
if ($inputDir === null || strlen($inputDir) === 0) {
|
||||
if (null === $inputDir || strlen($inputDir) === 0) {
|
||||
throw new InvalidArgumentException('Input dir empty');
|
||||
}
|
||||
if (!is_dir($inputDir)) {
|
||||
@@ -600,7 +600,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
public function addDirRecursive($inputDir, $localPath = "/", $compressionMethod = null)
|
||||
{
|
||||
$inputDir = (string)$inputDir;
|
||||
if ($inputDir === null || strlen($inputDir) === 0) {
|
||||
if (null === $inputDir || strlen($inputDir) === 0) {
|
||||
throw new InvalidArgumentException('Input dir empty');
|
||||
}
|
||||
if (!is_dir($inputDir)) {
|
||||
@@ -660,7 +660,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
}
|
||||
}
|
||||
}
|
||||
if(empty($files)){
|
||||
if (empty($files)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -752,7 +752,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
$globPattern = $inputDir . $globPattern;
|
||||
|
||||
$filesFound = FilesUtil::globFileSearch($globPattern, GLOB_BRACE, $recursive);
|
||||
if ($filesFound === false || empty($filesFound)) {
|
||||
if (false === $filesFound || empty($filesFound)) {
|
||||
return $this;
|
||||
}
|
||||
if (!empty($localPath) && is_string($localPath)) {
|
||||
@@ -846,7 +846,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
$inputDir = rtrim($inputDir, '/\\') . DIRECTORY_SEPARATOR;
|
||||
|
||||
$files = FilesUtil::regexFileSearch($inputDir, $regexPattern, $recursive);
|
||||
if ($files === false || empty($files)) {
|
||||
if (false === $files || empty($files)) {
|
||||
return $this;
|
||||
}
|
||||
if (!empty($localPath) && is_string($localPath)) {
|
||||
@@ -882,7 +882,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
*/
|
||||
public function rename($oldName, $newName)
|
||||
{
|
||||
if ($oldName === null || $newName === null) {
|
||||
if (null === $oldName || null === $newName) {
|
||||
throw new InvalidArgumentException("name is null");
|
||||
}
|
||||
$this->centralDirectory->rename($oldName, $newName);
|
||||
@@ -913,7 +913,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
*/
|
||||
public function deleteFromGlob($globPattern)
|
||||
{
|
||||
if ($globPattern === null || !is_string($globPattern) || empty($globPattern)) {
|
||||
if (null === $globPattern || !is_string($globPattern) || empty($globPattern)) {
|
||||
throw new InvalidArgumentException("Glob pattern is empty");
|
||||
}
|
||||
$globPattern = '~' . FilesUtil::convertGlobToRegEx($globPattern) . '~si';
|
||||
@@ -930,7 +930,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
*/
|
||||
public function deleteFromRegex($regexPattern)
|
||||
{
|
||||
if ($regexPattern === null || !is_string($regexPattern) || empty($regexPattern)) {
|
||||
if (null === $regexPattern || !is_string($regexPattern) || empty($regexPattern)) {
|
||||
throw new InvalidArgumentException("Regex pattern is empty.");
|
||||
}
|
||||
$this->centralDirectory->deleteEntriesFromRegex($regexPattern);
|
||||
@@ -1087,13 +1087,13 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
*/
|
||||
public function rewrite()
|
||||
{
|
||||
if($this->inputStream === null){
|
||||
if (null === $this->inputStream) {
|
||||
throw new ZipException('input stream is null');
|
||||
}
|
||||
$meta = stream_get_meta_data($this->inputStream);
|
||||
$content = $this->outputAsString();
|
||||
$this->close();
|
||||
if ($meta['wrapper_type'] === 'plainfile') {
|
||||
if ('plainfile' === $meta['wrapper_type']) {
|
||||
if (file_put_contents($meta['uri'], $content) === false) {
|
||||
throw new ZipException("Can not overwrite the zip file in the {$meta['uri']} file.");
|
||||
}
|
||||
@@ -1110,11 +1110,11 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if ($this->inputStream !== null) {
|
||||
if (null !== $this->inputStream) {
|
||||
fclose($this->inputStream);
|
||||
$this->inputStream = null;
|
||||
}
|
||||
if ($this->centralDirectory !== null) {
|
||||
if (null !== $this->centralDirectory) {
|
||||
$this->centralDirectory->release();
|
||||
$this->centralDirectory = null;
|
||||
}
|
||||
@@ -1165,7 +1165,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
*/
|
||||
public function offsetSet($entryName, $contents)
|
||||
{
|
||||
if ($entryName === null) {
|
||||
if (null === $entryName) {
|
||||
throw new InvalidArgumentException('entryName is null');
|
||||
}
|
||||
$entryName = (string)$entryName;
|
||||
@@ -1181,7 +1181,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
||||
return;
|
||||
}
|
||||
$contents = (string)$contents;
|
||||
if ($entryName[strlen($entryName) - 1] === '/') {
|
||||
if ('/' === $entryName[strlen($entryName) - 1]) {
|
||||
$this->addEmptyDir($entryName);
|
||||
} else {
|
||||
$this->addFromString($entryName, $contents);
|
||||
|
Reference in New Issue
Block a user