1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-10-24 19:46:24 +02:00

added static analysis

This commit is contained in:
Ne-Lexa
2021-02-23 19:44:48 +03:00
parent a85288d34b
commit 00dd097b2d
21 changed files with 84 additions and 86 deletions

View File

@@ -71,11 +71,8 @@ class ZipFileData implements ZipData
*/
public function copyDataToStream($outStream): void
{
try {
$stream = $this->getDataAsStream();
stream_copy_to_stream($stream, $outStream);
} finally {
fclose($stream);
}
$stream = $this->getDataAsStream();
stream_copy_to_stream($stream, $outStream);
fclose($stream);
}
}

View File

@@ -62,8 +62,8 @@ abstract class AbstractUnicodeExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException on error
*
@@ -92,8 +92,8 @@ abstract class AbstractUnicodeExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException on error
*

View File

@@ -21,7 +21,7 @@ use PhpZip\Model\ZipEntry;
* @see https://android.googlesource.com/platform/tools/apksig/+/master/src/main/java/com/android/apksig/ApkSigner.java
* @see https://developer.android.com/studio/command-line/zipalign
*/
class ApkAlignmentExtraField implements ZipExtraField
final class ApkAlignmentExtraField implements ZipExtraField
{
/**
* @var int Extensible data block/field header ID used for storing
@@ -31,12 +31,6 @@ class ApkAlignmentExtraField implements ZipExtraField
*/
public const HEADER_ID = 0xd935;
/**
* @var int minimum size (in bytes) of the extensible data block/field used
* for alignment of uncompressed entries
*/
public const MIN_SIZE = 6;
/** @var int */
public const ALIGNMENT_BYTES = 4;
@@ -86,8 +80,8 @@ class ApkAlignmentExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException
*
@@ -116,8 +110,8 @@ class ApkAlignmentExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException on error
*

View File

@@ -53,7 +53,7 @@ use PhpZip\Model\ZipEntry;
*
* @see ftp://ftp.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip Info-ZIP version Specification
*/
class AsiExtraField implements ZipExtraField
final class AsiExtraField implements ZipExtraField
{
/** @var int Header id */
public const HEADER_ID = 0x756e;
@@ -99,12 +99,12 @@ class AsiExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws Crc32Exception
*
* @return static
* @return AsiExtraField
*/
public static function unpackLocalFileData(string $buffer, ?ZipEntry $entry = null): self
{
@@ -134,8 +134,8 @@ class AsiExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws Crc32Exception
*
@@ -216,7 +216,7 @@ class AsiExtraField implements ZipExtraField
*
* @return int the type with the mode
*/
protected function getPermissionsMode(int $mode): int
private function getPermissionsMode(int $mode): int
{
$type = 0;

View File

@@ -73,7 +73,7 @@ use PhpZip\Model\ZipEntry;
*
* @see ftp://ftp.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip Info-ZIP version Specification
*/
class ExtendedTimestampExtraField implements ZipExtraField
final class ExtendedTimestampExtraField implements ZipExtraField
{
/** @var int Header id */
public const HEADER_ID = 0x5455;
@@ -158,8 +158,8 @@ class ExtendedTimestampExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @return ExtendedTimestampExtraField
*/
@@ -195,8 +195,8 @@ class ExtendedTimestampExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @return ExtendedTimestampExtraField
*/

View File

@@ -24,7 +24,7 @@ use PhpZip\Model\ZipEntry;
* If this extra field is added as the very first extra field of
* the archive, Solaris will consider it an executable jar file.
*/
class JarMarkerExtraField implements ZipExtraField
final class JarMarkerExtraField implements ZipExtraField
{
/** @var int Header id. */
public const HEADER_ID = 0xCAFE;
@@ -79,8 +79,8 @@ class JarMarkerExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException on error
*
@@ -98,8 +98,8 @@ class JarMarkerExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException on error
*

View File

@@ -51,7 +51,7 @@ use PhpZip\Model\ZipEntry;
* and this extra field are present, the values in this extra field
* supercede the values in that extra field.
*/
class NewUnixExtraField implements ZipExtraField
final class NewUnixExtraField implements ZipExtraField
{
/** @var int header id */
public const HEADER_ID = 0x7875;
@@ -88,8 +88,8 @@ class NewUnixExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException
*
@@ -120,8 +120,8 @@ class NewUnixExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException
*

View File

@@ -19,9 +19,9 @@ use PhpZip\Model\ZipEntry;
/**
* NTFS Extra Field.
*
* @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification
* @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification
*/
class NtfsExtraField implements ZipExtraField
final class NtfsExtraField implements ZipExtraField
{
/** @var int Header id */
public const HEADER_ID = 0x000a;
@@ -84,8 +84,8 @@ class NtfsExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException
*
@@ -127,8 +127,8 @@ class NtfsExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @throws ZipException
*

View File

@@ -62,7 +62,7 @@ use PhpZip\Model\ZipEntry;
* mid-1994. Therefore future archiving software should continue to
* support it.
*/
class OldUnixExtraField implements ZipExtraField
final class OldUnixExtraField implements ZipExtraField
{
/** @var int Header id */
public const HEADER_ID = 0x5855;
@@ -100,8 +100,8 @@ class OldUnixExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @return OldUnixExtraField
*/
@@ -133,8 +133,8 @@ class OldUnixExtraField implements ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @return OldUnixExtraField
*/

View File

@@ -55,7 +55,7 @@ namespace PhpZip\Model\Extra\Fields;
*
* @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT section 4.6.8
*/
class UnicodeCommentExtraField extends AbstractUnicodeExtraField
final class UnicodeCommentExtraField extends AbstractUnicodeExtraField
{
public const HEADER_ID = 0x6375;

View File

@@ -56,7 +56,7 @@ namespace PhpZip\Model\Extra\Fields;
*
* @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT section 4.6.9
*/
class UnicodePathExtraField extends AbstractUnicodeExtraField
final class UnicodePathExtraField extends AbstractUnicodeExtraField
{
public const HEADER_ID = 0x7075;

View File

@@ -18,7 +18,7 @@ use PhpZip\Model\ZipEntry;
/**
* Simple placeholder for all those extra fields we don't want to deal with.
*/
class UnrecognizedExtraField implements ZipExtraField
final class UnrecognizedExtraField implements ZipExtraField
{
private int $headerId;

View File

@@ -24,7 +24,7 @@ use PhpZip\Model\ZipEntry;
*
* @see http://www.winzip.com/win/en/aes_tips.htm AES Coding Tips for Developers
*/
class WinZipAesExtraField implements ZipExtraField
final class WinZipAesExtraField implements ZipExtraField
{
/** @var int Header id */
public const HEADER_ID = 0x9901;

View File

@@ -22,7 +22,7 @@ use PhpZip\Model\ZipEntry;
*
* @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification
*/
class Zip64ExtraField implements ZipExtraField
final class Zip64ExtraField implements ZipExtraField
{
/** @var int The Header ID for a ZIP64 Extended Information Extra Field. */
public const HEADER_ID = 0x0001;

View File

@@ -30,8 +30,8 @@ interface ZipExtraField
/**
* Populate data from this array as if it was in local file data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @return static
*/
@@ -40,8 +40,8 @@ interface ZipExtraField
/**
* Populate data from this array as if it was in central directory data.
*
* @param string $buffer the buffer to read data from
* @param ?ZipEntry $entry
* @param string $buffer the buffer to read data from
* @param ZipEntry|null $entry optional zip entry
*
* @return static
*/

View File

@@ -943,13 +943,10 @@ class ZipEntry
*/
public function setEncryptionMethod(?int $encryptionMethod): self
{
if ($encryptionMethod === null) {
$encryptionMethod = ZipEncryptionMethod::NONE;
}
$method = $encryptionMethod ?? ZipEncryptionMethod::NONE;
$encryptionMethod = (int) $encryptionMethod;
ZipEncryptionMethod::checkSupport($encryptionMethod);
$this->encryptionMethod = $encryptionMethod;
ZipEncryptionMethod::checkSupport($method);
$this->encryptionMethod = $method;
$this->setEncrypted($this->encryptionMethod !== ZipEncryptionMethod::NONE);
$this->extractVersion = self::UNKNOWN;