diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index e2a54428..e163af1e 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -22,9 +22,6 @@
gettype($options)
-
- Exception\ExceptionInterface
-
$key
$key
@@ -175,6 +172,9 @@
+
+ []
+
$option
@@ -186,14 +186,6 @@
string
-
- int
- string
-
-
- $this->options['archive']
- $this->options['blocksize']
-
$content
$content
@@ -202,8 +194,7 @@
(int) $blocksize
(string) $archive
-
- null !== $archive
+
null !== $content
null !== $content
@@ -226,19 +217,6 @@
$size
-
- int
- string
- string
-
-
- $this->options['archive']
-
-
- $this->options['archive']
- $this->options['level']
- $this->options['mode']
-
$content
$content
@@ -247,9 +225,8 @@
(int) $level
(string) $archive
-
+
$mode === 'deflate' && null !== $content
- null !== $archive
null !== $content
null !== $content
null !== $content
@@ -336,6 +313,9 @@
$result === false
+
+ string
+
$content
@@ -348,19 +328,12 @@
$file[]
$info
-
- string
- string
- string
-
isFile
-
- $this->options['archive']
- $this->options['mode']
- $this->options['target']
-
+
+ $this->getArchive()
+
$content
$content
@@ -368,6 +341,9 @@
$content
+
+ $this->getArchive()
+
$file
$file
@@ -385,6 +361,9 @@
$res
$res
+
+ string
+
$res
$res
@@ -392,16 +371,9 @@
$res
-
- string
- string
- string
-
-
- $this->options['archive']
+
$this->options['archive']
- $this->options['target']
-
+
$content
$content
@@ -410,6 +382,9 @@
strrpos($content, DIRECTORY_SEPARATOR)
strrpos($content, DIRECTORY_SEPARATOR)
+
+ $this->getArchive()
+
(string) $target
@@ -1327,11 +1302,6 @@
$existsOrOptions !== null
-
-
- Exception\ExceptionInterface
-
-
is_string($prefix)
@@ -2194,8 +2164,6 @@
$e->getMessage()
- $e->getMessage()
- $e->getMessage()
diff --git a/src/Compress/AbstractCompressionAlgorithm.php b/src/Compress/AbstractCompressionAlgorithm.php
index c7514bb1..ef0e367a 100644
--- a/src/Compress/AbstractCompressionAlgorithm.php
+++ b/src/Compress/AbstractCompressionAlgorithm.php
@@ -12,14 +12,16 @@
/**
* Abstract compression adapter
+ *
+ * @template TOptions of array
*/
abstract class AbstractCompressionAlgorithm implements CompressionAlgorithmInterface
{
- /** @var array */
+ /** @var TOptions */
protected $options = [];
/**
- * @param null|array|Traversable $options (Optional) Options to set
+ * @param null|iterable $options (Optional) Options to set
*/
public function __construct($options = null)
{
diff --git a/src/Compress/Bz2.php b/src/Compress/Bz2.php
index e5557bbb..4e12cff2 100644
--- a/src/Compress/Bz2.php
+++ b/src/Compress/Bz2.php
@@ -5,7 +5,6 @@
namespace Laminas\Filter\Compress;
use Laminas\Filter\Exception;
-use Traversable;
use function bzclose;
use function bzcompress;
@@ -20,6 +19,12 @@
/**
* Compression adapter for Bz2
+ *
+ * @psalm-type Options = array{
+ * blocksize: int,
+ * archive: string|null,
+ * }
+ * @extends AbstractCompressionAlgorithm
*/
class Bz2 extends AbstractCompressionAlgorithm
{
@@ -30,7 +35,7 @@ class Bz2 extends AbstractCompressionAlgorithm
* 'archive' => Archive to use
* )
*
- * @var array
+ * @var Options
*/
protected $options = [
'blocksize' => 4,
@@ -38,7 +43,7 @@ class Bz2 extends AbstractCompressionAlgorithm
];
/**
- * @param null|array|Traversable $options (Optional) Options to set
+ * @param null|Options|iterable $options (Optional) Options to set
* @throws Exception\ExtensionNotLoadedException If bz2 extension not loaded.
*/
public function __construct($options = null)
@@ -79,7 +84,7 @@ public function setBlocksize($blocksize)
/**
* Returns the set archive
*
- * @return string
+ * @return string|null
*/
public function getArchive()
{
diff --git a/src/Compress/Gz.php b/src/Compress/Gz.php
index c1bacdcf..0e0f8170 100644
--- a/src/Compress/Gz.php
+++ b/src/Compress/Gz.php
@@ -5,7 +5,6 @@
namespace Laminas\Filter\Compress;
use Laminas\Filter\Exception;
-use Traversable;
use function end;
use function extension_loaded;
@@ -22,6 +21,7 @@
use function gzread;
use function gzuncompress;
use function gzwrite;
+use function is_string;
use function strpos;
use function unpack;
@@ -29,6 +29,13 @@
/**
* Compression adapter for Gzip (ZLib)
+ *
+ * @psalm-type Options = array{
+ * level: int,
+ * mode: string,
+ * archive: string|null,
+ * }
+ * @extends AbstractCompressionAlgorithm
*/
class Gz extends AbstractCompressionAlgorithm
{
@@ -40,7 +47,7 @@ class Gz extends AbstractCompressionAlgorithm
* 'archive' => Archive to use
* )
*
- * @var array
+ * @var Options
*/
protected $options = [
'level' => 9,
@@ -49,7 +56,7 @@ class Gz extends AbstractCompressionAlgorithm
];
/**
- * @param null|array|Traversable $options (Optional) Options to set
+ * @param null|Options|iterable $options (Optional) Options to set
* @throws Exception\ExtensionNotLoadedException If zlib extension not loaded.
*/
public function __construct($options = null)
@@ -117,7 +124,7 @@ public function setMode($mode)
/**
* Returns the set archive
*
- * @return string
+ * @return string|null
*/
public function getArchive()
{
@@ -146,10 +153,10 @@ public function setArchive($archive)
public function compress($content)
{
$archive = $this->getArchive();
- if (! empty($archive)) {
+ if (is_string($archive) && $archive !== '') {
$file = gzopen($archive, 'w' . $this->getLevel());
if (! $file) {
- throw new Exception\RuntimeException("Error opening the archive '" . $this->options['archive'] . "'");
+ throw new Exception\RuntimeException("Error opening the archive '" . $archive . "'");
}
gzwrite($file, $content);
diff --git a/src/Compress/Tar.php b/src/Compress/Tar.php
index 2e3c0366..e8413164 100644
--- a/src/Compress/Tar.php
+++ b/src/Compress/Tar.php
@@ -23,6 +23,13 @@
/**
* Compression adapter for Tar
+ *
+ * @psalm-type Options = array{
+ * archive?: string|null,
+ * target: string,
+ * mode?: 'gz'|'bz2'|null,
+ * }
+ * @extends AbstractCompressionAlgorithm
*/
class Tar extends AbstractCompressionAlgorithm
{
@@ -33,7 +40,7 @@ class Tar extends AbstractCompressionAlgorithm
* 'target' => Target to write the files to
* )
*
- * @var array
+ * @var Options
*/
protected $options = [
'archive' => null,
@@ -42,7 +49,7 @@ class Tar extends AbstractCompressionAlgorithm
];
/**
- * @param array $options (Optional) Options to set
+ * @param Options $options (Optional) Options to set
* @throws Exception\ExtensionNotLoadedException If Archive_Tar component not available.
*/
public function __construct($options = null)
@@ -60,11 +67,11 @@ public function __construct($options = null)
/**
* Returns the set archive
*
- * @return string
+ * @return string|null
*/
public function getArchive()
{
- return $this->options['archive'];
+ return $this->options['archive'] ?? null;
}
/**
@@ -112,11 +119,11 @@ public function setTarget($target)
/**
* Returns the set compression mode
*
- * @return string
+ * @return string|null
*/
public function getMode()
{
- return $this->options['mode'];
+ return $this->options['mode'] ?? null;
}
/**
diff --git a/src/Compress/Zip.php b/src/Compress/Zip.php
index 655cab15..72ad7410 100644
--- a/src/Compress/Zip.php
+++ b/src/Compress/Zip.php
@@ -5,7 +5,6 @@
namespace Laminas\Filter\Compress;
use Laminas\Filter\Exception;
-use Traversable;
use ZipArchive;
use function array_pop;
@@ -16,6 +15,7 @@
use function file_exists;
use function is_dir;
use function is_file;
+use function is_string;
use function realpath;
use function rtrim;
use function str_replace;
@@ -26,6 +26,13 @@
/**
* Compression adapter for zip
+ *
+ * @psalm-type Options = array{
+ * archive: string|null,
+ * password?: string|null,
+ * target: string|null,
+ * }
+ * @extends AbstractCompressionAlgorithm
*/
class Zip extends AbstractCompressionAlgorithm
{
@@ -37,7 +44,7 @@ class Zip extends AbstractCompressionAlgorithm
* 'target' => Target to write the files to
* )
*
- * @var array
+ * @var Options
*/
protected $options = [
'archive' => null,
@@ -45,7 +52,7 @@ class Zip extends AbstractCompressionAlgorithm
];
/**
- * @param null|array|Traversable $options (Optional) Options to set
+ * @param null|Options|iterable $options (Optional) Options to set
* @throws Exception\ExtensionNotLoadedException If zip extension not loaded.
*/
public function __construct($options = null)
@@ -59,7 +66,7 @@ public function __construct($options = null)
/**
* Returns the set archive
*
- * @return string
+ * @return string|null
*/
public function getArchive()
{
@@ -83,7 +90,7 @@ public function setArchive($archive)
/**
* Returns the set targetpath
*
- * @return string
+ * @return string|null
*/
public function getTarget()
{
@@ -168,7 +175,7 @@ public function compress($content)
}
} else {
$file = $this->getTarget();
- if (! is_dir($file)) {
+ if (is_string($file) && ! is_dir($file)) {
$file = basename($file);
} else {
$file = 'zip.tmp';
diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php
index 9416ed11..41eecaa0 100644
--- a/src/Exception/ExceptionInterface.php
+++ b/src/Exception/ExceptionInterface.php
@@ -4,6 +4,8 @@
namespace Laminas\Filter\Exception;
-interface ExceptionInterface
+use Throwable;
+
+interface ExceptionInterface extends Throwable
{
}