$stream =
new \
ZipArchive();
if (!
file_exists($filename)) { throw PluginException::
cannotExtractNoSuchFile($filename);
} if (!self::
validateFileIsZip($filename)) { throw PluginException::
cannotExtractInvalidZipFile($filename);
} if (($retVal =
$stream->
open($filename)) !== true
) { throw PluginException::
cannotExtractZipOpenError(self::
getErrorMessage($retVal,
$filename));
} return $stream;
} private static function getErrorMessage(int
$retVal, string
$file): string
{ return match ($retVal) { \ZipArchive::ER_EXISTS =>
sprintf('File \'%s\' already exists.',
$file),
\ZipArchive::ER_INCONS =>
sprintf('Zip archive \'%s\' is inconsistent.',
$file),
\ZipArchive::ER_INVAL =>
sprintf('Invalid argument (%s)',
$file),