1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00
This commit is contained in:
Jordi Boggiano 2014-06-10 16:02:44 +02:00
parent d036b2390e
commit ac497feaba
53 changed files with 166 additions and 156 deletions

View file

@ -646,7 +646,7 @@ FOOTER;
$computing = array();
$computed = array();
$computeImportance = function($name) use(&$computeImportance, &$computing, &$computed, $usageList) {
$computeImportance = function ($name) use (&$computeImportance, &$computing, &$computed, $usageList) {
// reusing computed importance
if (isset($computed[$name])) {
return $computed[$name];
@ -679,17 +679,17 @@ FOOTER;
$weightList[$name] = $weight;
}
$stable_sort = function(&$array) {
$stable_sort = function (&$array) {
static $transform, $restore;
$i = 0;
if (!$transform) {
$transform = function(&$v, $k) use(&$i) {
$transform = function (&$v, $k) use (&$i) {
$v = array($v, ++$i, $k, $v);
};
$restore = function(&$v, $k) {
$restore = function (&$v, $k) {
$v = $v[3];
};
}

View file

@ -205,7 +205,8 @@ class ClassLoader
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*/
public function setPsr4($prefix, $paths) {
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {

View file

@ -144,8 +144,7 @@ class Cache
public function gc($ttl, $maxSize)
{
if ($this->enabled)
{
if ($this->enabled) {
$expire = new \DateTime();
$expire->modify('-'.$ttl.' seconds');

View file

@ -69,6 +69,7 @@ EOT
if (0 === $returnCode) {
$this->getComposer()->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ARCHIVE_CMD);
}
return $returnCode;
}

View file

@ -19,7 +19,6 @@ use Composer\Installer\ProjectInstaller;
use Composer\Installer\InstallationManager;
use Composer\IO\IOInterface;
use Composer\Package\BasePackage;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\Repository\ComposerRepository;

View file

@ -64,6 +64,7 @@ EOT
{
if ($args = $input->getArgument('packages')) {
$output->writeln('<error>Invalid argument '.implode(' ', $args).'. Use "composer require '.implode(' ', $args).'" instead to add packages to your composer.json.</error>');
return 1;
}

View file

@ -187,6 +187,7 @@ class JsonConfigSource implements ConfigSourceInterface
{
$return = array_unshift($array, '');
$array[0] =& $value;
return $return;
}
}

View file

@ -13,7 +13,6 @@
namespace Composer\DependencyResolver;
use Composer\Package\AliasPackage;
use Composer\DependencyResolver\Operation;
/**
* @author Nils Adermann <naderman@naderman.de>

View file

@ -13,7 +13,6 @@
namespace Composer\Downloader;
use Composer\Package\PackageInterface;
use Composer\Downloader\DownloaderInterface;
use Composer\IO\IOInterface;
use Composer\Util\Filesystem;

View file

@ -21,7 +21,6 @@ use Composer\Plugin\PluginEvents;
use Composer\Plugin\PreFileDownloadEvent;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\Filesystem;
use Composer\Util\GitHub;
use Composer\Util\RemoteFilesystem;
/**
@ -60,7 +59,6 @@ class FileDownloader implements DownloaderInterface
$this->filesystem = $filesystem ?: new Filesystem();
$this->cache = $cache;
if ($this->cache && $this->cache->gcIsNecessary()) {
$this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
}

View file

@ -47,7 +47,7 @@ class GitDownloader extends VcsDownloader
$command = 'git clone --no-checkout %s %s && cd '.$flag.'%2$s && git remote add composer %1$s && git fetch composer';
$this->io->write(" Cloning ".$ref);
$commandCallable = function($url) use ($ref, $path, $command) {
$commandCallable = function ($url) use ($ref, $path, $command) {
return sprintf($command, escapeshellarg($url), escapeshellarg($path), escapeshellarg($ref));
};
@ -77,7 +77,7 @@ class GitDownloader extends VcsDownloader
$this->io->write(" Checking out ".$ref);
$command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer';
$commandCallable = function($url) use ($command) {
$commandCallable = function ($url) use ($command) {
return sprintf($command, escapeshellarg($url));
};

View file

@ -68,4 +68,3 @@ class GzipDownloader extends ArchiveDownloader
return $path.'/'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME);
}
}

View file

@ -44,10 +44,10 @@ class PerforceDownloader extends VcsDownloader
private function getLabelFromSourceReference($ref)
{
$pos = strpos($ref,'@');
if (false !== $pos)
{
if (false !== $pos) {
return substr($ref, $pos + 1);
}
return null;
}
@ -55,6 +55,7 @@ class PerforceDownloader extends VcsDownloader
{
if (!empty($this->perforce)) {
$this->perforce->initializePath($path);
return;
}

View file

@ -45,7 +45,7 @@ class ZipDownloader extends ArchiveDownloader
}
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
} catch(\Exception $e) {
} catch (\Exception $e) {
$processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage();
}
}

View file

@ -26,7 +26,6 @@ use Composer\DependencyResolver\SolverProblemsException;
use Composer\Downloader\DownloadManager;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Installer\InstallationManager;
use Composer\Config;
use Composer\Installer\NoopInstaller;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;

View file

@ -13,7 +13,6 @@
namespace Composer\Json;
use JsonSchema\Validator;
use JsonSchema\Uri\UriRetriever;
use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;
use Composer\Util\RemoteFilesystem;

View file

@ -66,7 +66,7 @@ class JsonFormatter
if ($unescapeUnicode && function_exists('mb_convert_encoding')) {
// http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha
$buffer = preg_replace_callback('/(\\\\+)u([0-9a-f]{4})/i', function($match) {
$buffer = preg_replace_callback('/(\\\\+)u([0-9a-f]{4})/i', function ($match) {
$l = strlen($match[1]);
if ($l % 2) {
@ -76,6 +76,7 @@ class JsonFormatter
'UCS-2BE'
);
}
return $match[0];
}, $buffer);
}

View file

@ -13,7 +13,6 @@
namespace Composer\Package;
use Composer\Package\LinkConstraint\LinkConstraintInterface;
use Composer\Package\PackageInterface;
/**
* Represents a link between two packages, represented by their names

View file

@ -320,6 +320,7 @@ class RootPackageLoader extends ArrayLoader
if ('9999999-dev' === $version) {
$version = 'dev-'.$matches[3];
}
return $version;
}

View file

@ -16,7 +16,6 @@ use Composer\Json\JsonFile;
use Composer\Installer\InstallationManager;
use Composer\Repository\RepositoryManager;
use Composer\Util\ProcessExecutor;
use Composer\Package\AliasPackage;
use Composer\Repository\ArrayRepository;
use Composer\Package\Dumper\ArrayDumper;
use Composer\Package\Loader\ArrayLoader;

View file

@ -81,13 +81,14 @@ class ArtifactRepository extends ArrayRepository
* @param $filename
* @return bool|int
*/
private function locateFile(\ZipArchive $zip, $filename) {
private function locateFile(\ZipArchive $zip, $filename)
{
$indexOfShortestMatch = false;
$lengthOfShortestMatch = -1;
for ($i = 0; $i < $zip->numFiles; $i++ ){
for ($i = 0; $i < $zip->numFiles; $i++) {
$stat = $zip->statIndex($i);
if (strcmp(basename($stat['name']), $filename) === 0){
if (strcmp(basename($stat['name']), $filename) === 0) {
$directoryName = dirname($stat['name']);
if ($directoryName == '.') {
//if composer.json is in root directory

View file

@ -275,6 +275,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
foreach ($package->getDistUrls() as $url) {
if (strpos($url, $this->baseUrl) === 0) {
$package->setTransportOptions($this->options);
return;
}
}

View file

@ -161,7 +161,6 @@ class PlatformRepository extends ArrayRepository
}
}
private function buildPackageName($name)
{
return 'ext-' . str_replace(' ', '-', $name);

View file

@ -67,7 +67,7 @@ class GitDriver extends VcsDriver
$gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs);
$repoDir = $this->repoDir;
$commandCallable = function($url) use ($repoDir) {
$commandCallable = function ($url) use ($repoDir) {
return sprintf('git clone --mirror %s %s', escapeshellarg($url), escapeshellarg($repoDir));
};

View file

@ -54,6 +54,7 @@ class GitHubDriver extends VcsDriver
if (isset($this->repoConfig['no-api']) && $this->repoConfig['no-api']) {
$this->setupGitDriver($this->url);
return;
}

View file

@ -140,6 +140,7 @@ class PerforceDriver extends VcsDriver
{
$this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier);
$this->composerInfoIdentifier = $identifier;
return !empty($this->composerInfo);
}

View file

@ -150,7 +150,7 @@ class GitHub
if (in_array($e->getCode(), array(403, 401))) {
// 401 when authentication was supplied, handle 2FA if required.
if ($this->io->hasAuthentication($originUrl)) {
$headerNames = array_map(function($header) {
$headerNames = array_map(function ($header) {
return strtolower(strstr($header, ':', true));
}, $e->getHeaders());

View file

@ -53,12 +53,14 @@ class Perforce
{
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
$perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows, $io);
return $perforce;
}
public static function checkServerExists($url, ProcessExecutor $processExecutor)
{
$output = null;
return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s', $output);
}
@ -119,6 +121,7 @@ class Perforce
{
$this->commandResult = "";
$exit_code = $this->process->execute($command, $this->commandResult);
return $exit_code;
}
@ -248,6 +251,7 @@ class Perforce
$command = 'echo $' . $name;
$this->executeCommand($command);
$result = trim($this->commandResult);
return $result;
}
}
@ -283,18 +287,19 @@ class Perforce
{
$command = $this->generateP4Command('login -s', false);
$exitCode = $this->executeCommand($command);
if ($exitCode){
if ($exitCode) {
$errorOutput = $this->process->getErrorOutput();
$index = strpos($errorOutput, $this->getUser());
if ($index === false){
if ($index === false) {
$index = strpos($errorOutput, 'p4');
if ($index===false){
if ($index === false) {
return false;
}
throw new \Exception('p4 command not found in path: ' . $errorOutput);
}
throw new \Exception('Invalid user name: ' . $this->getUser() );
}
return true;
}
@ -384,7 +389,7 @@ class Perforce
$command = 'echo ' . $password . ' | ' . $this->generateP4Command(' login -a', false);
$exitCode = $this->executeCommand($command);
$result = trim($this->commandResult);
if ($exitCode){
if ($exitCode) {
throw new \Exception("Error logging in:" . $this->process->getErrorOutput());
}
}
@ -471,6 +476,7 @@ class Perforce
$lastCommitNum = $lastCommitArr[1];
$branches = array('master' => $possibleBranches[$this->p4Branch] . '@'. $lastCommitNum);
return $branches;
}
@ -488,6 +494,7 @@ class Perforce
$tags[$fields[1]] = $this->getStream() . '@' . $fields[1];
}
}
return $tags;
}
@ -552,14 +559,13 @@ class Perforce
public function getFilesystem()
{
if (empty($this->filesystem))
{
if (empty($this->filesystem)) {
$this->filesystem = new Filesystem($this->process);
}
return $this->filesystem;
}
public function setFilesystem(Filesystem $fs)
{
$this->filesystem = $fs;

View file

@ -124,7 +124,7 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
$testDir = sys_get_temp_dir().'/composer_functional_test'.uniqid(mt_rand(), true);
$this->testDir = $testDir;
$varRegex = '#%([a-zA-Z_-]+)%#';
$variableReplacer = function($match) use (&$data, $testDir) {
$variableReplacer = function ($match) use (&$data, $testDir) {
list(, $var) = $match;
switch ($var) {

View file

@ -109,7 +109,7 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
$ioMock = $this->getMock('Composer\IO\IOInterface');
$ioMock->expects($this->any())
->method('write')
->will($this->returnCallback(function($messages, $newline = true) use ($path) {
->will($this->returnCallback(function ($messages, $newline = true) use ($path) {
if (is_file($path.'/script.js')) {
unlink($path.'/script.js');
}

View file

@ -65,6 +65,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
$config = new Config();
$settings = array('config' => array('home' => $this->testPath));
$config->merge($settings);
return $config;
}
@ -77,6 +78,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
{
$package = $this->getMock('Composer\Package\PackageInterface');
$package->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
return $package;
}
@ -92,6 +94,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
$args = array($repoConfig, $io, $config);
$repository = $this->getMock($class, $methods, $args);
$repository->expects($this->any())->method('getRepoConfig')->will($this->returnValue($repoConfig));
return $repository;
}

View file

@ -43,6 +43,7 @@ class JsonFormatterTest extends \PHPUnit_Framework_TestCase
for ($i = 0; $i < strlen($string); $i++) {
$codes[] = ord($string[$i]);
}
return implode('+', $codes);
}

View file

@ -35,7 +35,7 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
$self = $this;
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self, $commitHash) {
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self, $commitHash) {
if (0 === strpos($command, 'git describe')) {
// simulate not being on a tag
return 1;
@ -69,7 +69,7 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
$self = $this;
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
$self->assertEquals('git describe --exact-match --tags', $command);
$output = "v2.0.5-alpha2";
@ -98,7 +98,7 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
$self = $this;
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
if ('git describe --exact-match --tags' === $command) {
$output = "foo-bar";
@ -124,7 +124,7 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) {
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) {
return 1;
});

View file

@ -198,6 +198,7 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase
{
if (!$mustCheck) {
$this->assertTrue(true);
return;
}
$internalLoader = $this->getMock('Composer\Package\Loader\LoaderInterface');

View file

@ -54,7 +54,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
);
$self = $this;
$createPackage = function($arr) use ($self) {
$createPackage = function ($arr) use ($self) {
$package = $self->getMock('\Composer\Package\PackageInterface');
$package->expects($self->once())->method('isDev')->will($self->returnValue(true));
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));

View file

@ -35,7 +35,7 @@ class ArtifactRepositoryTest extends TestCase
$coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts');
$repo = new ArtifactRepository($coordinates, new NullIO(), new Config());
$foundPackages = array_map(function(BasePackage $package) {
$foundPackages = array_map(function (BasePackage $package) {
return "{$package->getPrettyName()}-{$package->getPrettyVersion()}";
}, $repo->getPackages());
@ -73,7 +73,7 @@ class ArtifactRepositoryTest extends TestCase
// ),
//);
//
//foreach($archivesToCreate as $archiveName => $fileDetails) {
//foreach ($archivesToCreate as $archiveName => $fileDetails) {
// $zipFile = new ZipArchive();
// $zipFile->open("$archiveName.zip", ZIPARCHIVE::CREATE);
//
@ -83,4 +83,3 @@ class ArtifactRepositoryTest extends TestCase
//
// $zipFile->close();
//}

View file

@ -12,7 +12,6 @@
namespace Composer\Repository;
use Composer\Repository\FilesystemRepository;
use Composer\TestCase;
class FilesystemRepositoryTest extends TestCase

View file

@ -74,6 +74,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
{
$config = new Config();
$config->merge(array('config'=>array('home'=>$testPath)));
return $config;
}
@ -104,6 +105,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
protected function getMockPerforce()
{
$methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec');
return $this->getMockBuilder('Composer\Util\Perforce', $methods)->disableOriginalConstructor()->getMock();
}

View file

@ -139,9 +139,9 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
$this->createNewPerforceWithWindowsFlag(true);
$this->perforce->setUser(null);
$expectedCommand = 'p4 set';
$callback = function($command, &$output)
{
$callback = function ($command, &$output) {
$output = 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL;
return true;
};
$this->processExecutor->expects($this->at(0))
@ -157,9 +157,9 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
$this->createNewPerforceWithWindowsFlag(false);
$this->perforce->setUser(null);
$expectedCommand = 'echo $P4USER';
$callback = function($command, &$output)
{
$callback = function ($command, &$output) {
$output = 'TEST_P4VARIABLE_USER' . PHP_EOL;
return true;
};
$this->processExecutor->expects($this->at(0))
@ -233,9 +233,9 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
{
$this->createNewPerforceWithWindowsFlag(true);
$expectedCommand = 'p4 set';
$callback = function($command, &$output)
{
$callback = function ($command, &$output) {
$output = 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL;
return true;
};
$this->processExecutor->expects($this->at(0))
@ -250,9 +250,9 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
{
$this->createNewPerforceWithWindowsFlag(false);
$expectedCommand = 'echo $P4PASSWD';
$callback = function($command, &$output)
{
$callback = function ($command, &$output) {
$output = 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL;
return true;
};
$this->processExecutor->expects($this->at(0))
@ -357,9 +357,9 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
)
);
$expectedCommand2 = 'p4 -u user -p port changes //depot/branch/...';
$expectedCallback = function($command, &$output)
{
$expectedCallback = function ($command, &$output) {
$output = 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\'';
return true;
};
$this->processExecutor->expects($this->at(1))
@ -374,9 +374,9 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
public function testGetBranchesWithoutStream()
{
$expectedCommand = 'p4 -u user -p port changes //depot/...';
$expectedCallback = function($command, &$output)
{
$expectedCallback = function ($command, &$output) {
$output = 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\'';
return true;
};
$this->processExecutor->expects($this->once())

View file

@ -52,7 +52,7 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
),
array(
$a = array('http' => array('method' => 'GET', 'max_redirects' => 20, 'follow_location' => 1)), array('http' => array('method' => 'GET')),
array('options' => $a, 'notification' => $f = function() {}), array('notification' => $f)
array('options' => $a, 'notification' => $f = function () {}), array('notification' => $f)
),
);
}