Skip to content

Commit e3a27bd

Browse files
committed
throw ArchiveIllegalCompressionException on bad compression level
1 parent a46f3aa commit e3a27bd

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/Archive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class Archive
1515
*
1616
* @param int $level Compression level (0 to 9)
1717
* @param int $type Type of compression to use (use COMPRESS_* constants)
18-
* @return mixed
18+
* @throws ArchiveIllegalCompressionException
1919
*/
2020
abstract public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO);
2121

src/Tar.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ class Tar extends Archive
2828
* Sets the compression to use
2929
*
3030
* @param int $level Compression level (0 to 9)
31-
* @param int $type Type of compression to use (use COMPRESS_* constants)
32-
* @return mixed
31+
* @param int $type Type of compression to use (use COMPRESS_* constants)
32+
* @throws ArchiveIllegalCompressionException
3333
*/
3434
public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO)
3535
{
3636
$this->compressioncheck($type);
37+
if ($level < -1 || $level > 9) {
38+
throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9');
39+
}
3740
$this->comptype = $type;
3841
$this->complevel = $level;
3942
if($level == 0) $this->comptype = Archive::COMPRESS_NONE;

src/Zip.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ class Zip extends Archive
3434
*
3535
* @param int $level Compression level (0 to 9)
3636
* @param int $type Type of compression to use ignored for ZIP
37-
* @return mixed
37+
* @throws ArchiveIllegalCompressionException
3838
*/
3939
public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO)
4040
{
41+
if ($level < -1 || $level > 9) {
42+
throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9');
43+
}
4144
$this->complevel = $level;
4245
}
4346

0 commit comments

Comments
 (0)