Fix CS issues, refs #6159

main
Jordi Boggiano 7 years ago
parent 0a337e7c75
commit 61511cfed6

@ -29,10 +29,11 @@ use ZipArchive;
*/
class ZipDownloader extends ArchiveDownloader
{
private static $hasSystemUnzip;
private static $hasZipArchive;
private static $isWindows;
protected $process;
public static $hasSystemUnzip;
public static $hasZipArchive;
public static $isWindows;
private $zipArchiveObject;
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
@ -80,12 +81,12 @@ class ZipDownloader extends ArchiveDownloader
*/
protected function extractWithSystemUnzip($file, $path, $isLastChance)
{
if (! self::$hasZipArchive) {
if (!self::$hasZipArchive) {
// Force Exception throwing if the Other alternative is not available
$isLastChance = true;
}
if (! self::$hasSystemUnzip && ! $isLastChance) {
if (!self::$hasSystemUnzip && !$isLastChance) {
// This was call as the favorite extract way, but is not available
// We switch to the alternative
return $this->extractWithZipArchive($file, $path, true);
@ -107,17 +108,14 @@ class ZipDownloader extends ArchiveDownloader
$processError = $e;
}
if (! self::$hasZipArchive) {
$isLastChance = true;
}
if ($isLastChance) {
throw $processError;
} else {
$this->io->write($processError->getMessage());
$this->io->write('Unzip with unzip command failed, falling back to ZipArchive class');
return $this->extractWithZipArchive($file, $path, true);
}
$this->io->writeError(' '.$processError->getMessage());
$this->io->writeError(' Unzip with unzip command failed, falling back to ZipArchive class');
return $this->extractWithZipArchive($file, $path, true);
}
/**
@ -130,12 +128,12 @@ class ZipDownloader extends ArchiveDownloader
*/
protected function extractWithZipArchive($file, $path, $isLastChance)
{
if (! self::$hasSystemUnzip) {
if (!self::$hasSystemUnzip) {
// Force Exception throwing if the Other alternative is not available
$isLastChance = true;
}
if (! self::$hasZipArchive && ! $isLastChance) {
if (!self::$hasZipArchive && !$isLastChance) {
// This was call as the favorite extract way, but is not available
// We switch to the alternative
return $this->extractWithSystemUnzip($file, $path, true);
@ -150,10 +148,11 @@ class ZipDownloader extends ArchiveDownloader
if (true === $extractResult) {
$zipArchive->close();
return true;
} else {
$processError = new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n"));
}
$processError = new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n"));
} else {
$processError = new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file)."\n"), $retval);
}
@ -163,11 +162,12 @@ class ZipDownloader extends ArchiveDownloader
if ($isLastChance) {
throw $processError;
} else {
$this->io->write($processError->getMessage());
$this->io->write('Unzip with ZipArchive class failed, falling back to unzip command');
return $this->extractWithSystemUnzip($file, $path, true);
}
$this->io->writeError(' '.$processError->getMessage());
$this->io->writeError(' Unzip with ZipArchive class failed, falling back to unzip command');
return $this->extractWithSystemUnzip($file, $path, true);
}
/**

@ -37,8 +37,8 @@ class ZipDownloaderTest extends TestCase
{
$fs = new Filesystem;
$fs->removeDirectory($this->testDir);
ZipDownloader::$hasSystemUnzip = null;
ZipDownloader::$hasZipArchive = null;
$this->setPrivateProperty('hasSystemUnzip', null);
$this->setPrivateProperty('hasZipArchive', null);
}
public function setPrivateProperty($name, $value, $obj = null)
@ -95,7 +95,7 @@ class ZipDownloaderTest extends TestCase
$downloader = new ZipDownloader($this->io, $this->config);
ZipDownloader::$hasSystemUnzip = false;
$this->setPrivateProperty('hasSystemUnzip', false);
try {
$downloader->download($packageMock, sys_get_temp_dir().'/composer-zip-test');
@ -111,8 +111,8 @@ class ZipDownloaderTest extends TestCase
*/
public function testZipArchiveOnlyFailed()
{
MockedZipDownloader::$hasSystemUnzip = false;
MockedZipDownloader::$hasZipArchive = true;
$this->setPrivateProperty('hasSystemUnzip', false);
$this->setPrivateProperty('hasZipArchive', true);
$downloader = new MockedZipDownloader($this->io, $this->config);
$zipArchive = $this->getMock('ZipArchive');
@ -132,8 +132,8 @@ class ZipDownloaderTest extends TestCase
*/
public function testZipArchiveOnlyGood()
{
MockedZipDownloader::$hasSystemUnzip = false;
MockedZipDownloader::$hasZipArchive = true;
$this->setPrivateProperty('hasSystemUnzip', false);
$this->setPrivateProperty('hasZipArchive', true);
$downloader = new MockedZipDownloader($this->io, $this->config);
$zipArchive = $this->getMock('ZipArchive');
@ -154,8 +154,8 @@ class ZipDownloaderTest extends TestCase
*/
public function testSystemUnzipOnlyFailed()
{
MockedZipDownloader::$hasSystemUnzip = true;
MockedZipDownloader::$hasZipArchive = false;
$this->setPrivateProperty('hasSystemUnzip', true);
$this->setPrivateProperty('hasZipArchive', false);
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->at(0))
->method('execute')
@ -167,8 +167,8 @@ class ZipDownloaderTest extends TestCase
public function testSystemUnzipOnlyGood()
{
MockedZipDownloader::$hasSystemUnzip = true;
MockedZipDownloader::$hasZipArchive = false;
$this->setPrivateProperty('hasSystemUnzip', true);
$this->setPrivateProperty('hasZipArchive', false);
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->at(0))
->method('execute')
@ -180,9 +180,9 @@ class ZipDownloaderTest extends TestCase
public function testNonWindowsFallbackGood()
{
MockedZipDownloader::$isWindows = false;
MockedZipDownloader::$hasSystemUnzip = true;
MockedZipDownloader::$hasZipArchive = true;
$this->setPrivateProperty('isWindows', false);
$this->setPrivateProperty('hasSystemUnzip', true);
$this->setPrivateProperty('hasZipArchive', true);
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->at(0))
@ -208,9 +208,9 @@ class ZipDownloaderTest extends TestCase
*/
public function testNonWindowsFallbackFailed()
{
MockedZipDownloader::$isWindows = false;
MockedZipDownloader::$hasSystemUnzip = true;
MockedZipDownloader::$hasZipArchive = true;
$this->setPrivateProperty('isWindows', false);
$this->setPrivateProperty('hasSystemUnzip', true);
$this->setPrivateProperty('hasZipArchive', true);
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->at(0))
@ -232,9 +232,9 @@ class ZipDownloaderTest extends TestCase
public function testWindowsFallbackGood()
{
MockedZipDownloader::$isWindows = true;
MockedZipDownloader::$hasSystemUnzip = true;
MockedZipDownloader::$hasZipArchive = true;
$this->setPrivateProperty('isWindows', true);
$this->setPrivateProperty('hasSystemUnzip', true);
$this->setPrivateProperty('hasZipArchive', true);
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->atLeastOnce())
@ -260,9 +260,9 @@ class ZipDownloaderTest extends TestCase
*/
public function testWindowsFallbackFailed()
{
MockedZipDownloader::$isWindows = true;
MockedZipDownloader::$hasSystemUnzip = true;
MockedZipDownloader::$hasZipArchive = true;
$this->setPrivateProperty('isWindows', true);
$this->setPrivateProperty('hasSystemUnzip', true);
$this->setPrivateProperty('hasZipArchive', true);
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->atLeastOnce())

Loading…
Cancel
Save