Merge pull request #4972 from curry684/code-quality

Code quality
main
Jordi Boggiano 8 years ago
commit f2e2dd8f86

@ -18,7 +18,6 @@
namespace Composer\Autoload; namespace Composer\Autoload;
use Composer\Util\Silencer;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;

@ -125,7 +125,6 @@ EOT
// show single package or single version // show single package or single version
if ($input->getArgument('package') || !empty($package)) { if ($input->getArgument('package') || !empty($package)) {
$versions = array();
if (empty($package)) { if (empty($package)) {
list($package, $versions) = $this->getPackage($installedRepo, $repos, $input->getArgument('package'), $input->getArgument('version')); list($package, $versions) = $this->getPackage($installedRepo, $repos, $input->getArgument('package'), $input->getArgument('version'));
@ -139,7 +138,7 @@ EOT
if ($input->getOption('tree')) { if ($input->getOption('tree')) {
$this->displayPackageTree($package, $installedRepo, $repos); $this->displayPackageTree($package, $installedRepo, $repos);
} else { } else {
$this->printMeta($package, $versions, $installedRepo, $repos); $this->printMeta($package, $versions, $installedRepo);
$this->printLinks($package, 'requires'); $this->printLinks($package, 'requires');
$this->printLinks($package, 'devRequires', 'requires (dev)'); $this->printLinks($package, 'devRequires', 'requires (dev)');
if ($package->getSuggests()) { if ($package->getSuggests()) {

@ -19,7 +19,6 @@ use Composer\Downloader\ChangeReportInterface;
use Composer\Plugin\CommandEvent; use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Downloader\VcsDownloader;
use Composer\Downloader\DvcsDownloaderInterface; use Composer\Downloader\DvcsDownloaderInterface;
/** /**

@ -79,10 +79,11 @@ class JsonConfigSource implements ConfigSourceInterface
*/ */
public function addConfigSetting($name, $value) public function addConfigSetting($name, $value)
{ {
$this->manipulateJson('addConfigSetting', $name, $value, function (&$config, $key, $val) { $that = $this;
$this->manipulateJson('addConfigSetting', $name, $value, function (&$config, $key, $val) use ($that) {
if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) { if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) {
list($key, $host) = explode('.', $key, 2); list($key, $host) = explode('.', $key, 2);
if ($this->authConfig) { if ($that->authConfig) {
$config[$key][$host] = $val; $config[$key][$host] = $val;
} else { } else {
$config['config'][$key][$host] = $val; $config['config'][$key][$host] = $val;
@ -98,10 +99,11 @@ class JsonConfigSource implements ConfigSourceInterface
*/ */
public function removeConfigSetting($name) public function removeConfigSetting($name)
{ {
$this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) { $that = $this;
$this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) use ($that) {
if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) { if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) {
list($key, $host) = explode('.', $key, 2); list($key, $host) = explode('.', $key, 2);
if ($this->authConfig) { if ($that->authConfig) {
unset($config[$key][$host]); unset($config[$key][$host]);
} else { } else {
unset($config['config'][$key][$host]); unset($config['config'][$key][$host]);

@ -23,5 +23,5 @@ interface PolicyInterface
public function findUpdatePackages(Pool $pool, array $installedMap, PackageInterface $package); public function findUpdatePackages(Pool $pool, array $installedMap, PackageInterface $package);
public function selectPreferredPackages(Pool $pool, array $installedMap, array $literals); public function selectPreferredPackages(Pool $pool, array $installedMap, array $literals, $requiredPackage = null);
} }

@ -789,7 +789,6 @@ class Solver
continue; continue;
} }
$oLevel = $level;
$level = $this->selectAndInstall($level, $decisionQueue, $disableRules, $rule); $level = $this->selectAndInstall($level, $decisionQueue, $disableRules, $rule);
if (0 === $level) { if (0 === $level) {
@ -810,7 +809,6 @@ class Solver
$lastLevel = null; $lastLevel = null;
$lastBranchIndex = 0; $lastBranchIndex = 0;
$lastBranchOffset = 0; $lastBranchOffset = 0;
$l = 0;
for ($i = count($this->branches) - 1; $i >= 0; $i--) { for ($i = count($this->branches) - 1; $i >= 0; $i--) {
list($literals, $l) = $this->branches[$i]; list($literals, $l) = $this->branches[$i];
@ -833,7 +831,6 @@ class Solver
$why = $this->decisions->lastReason(); $why = $this->decisions->lastReason();
$oLevel = $level;
$level = $this->setPropagateLearn($level, $lastLiteral, $disableRules, $why); $level = $this->setPropagateLearn($level, $lastLiteral, $disableRules, $why);
if ($level == 0) { if ($level == 0) {

@ -40,6 +40,7 @@ class FileDownloader implements DownloaderInterface
protected $cache; protected $cache;
protected $outputProgress = true; protected $outputProgress = true;
private $lastCacheWrites = array(); private $lastCacheWrites = array();
private $eventDispatcher;
/** /**
* Constructor. * Constructor.

@ -21,6 +21,7 @@ use Composer\Util\Perforce;
*/ */
class PerforceDownloader extends VcsDownloader class PerforceDownloader extends VcsDownloader
{ {
/** @var Perforce */
protected $perforce; protected $perforce;
/** /**
@ -34,7 +35,7 @@ class PerforceDownloader extends VcsDownloader
$this->io->writeError(' Cloning ' . $ref); $this->io->writeError(' Cloning ' . $ref);
$this->initPerforce($package, $path, $url); $this->initPerforce($package, $path, $url);
$this->perforce->setStream($ref); $this->perforce->setStream($ref);
$this->perforce->p4Login($this->io); $this->perforce->p4Login();
$this->perforce->writeP4ClientSpec(); $this->perforce->writeP4ClientSpec();
$this->perforce->connectClient(); $this->perforce->connectClient();
$this->perforce->syncCodeBase($label); $this->perforce->syncCodeBase($label);
@ -51,7 +52,7 @@ class PerforceDownloader extends VcsDownloader
return null; return null;
} }
public function initPerforce($package, $path, $url) public function initPerforce(PackageInterface $package, $path, $url)
{ {
if (!empty($this->perforce)) { if (!empty($this->perforce)) {
$this->perforce->initializePath($path); $this->perforce->initializePath($path);

@ -23,10 +23,11 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
protected $version; protected $version;
protected $prettyVersion; protected $prettyVersion;
protected $dev; protected $dev;
protected $aliasOf;
protected $rootPackageAlias = false; protected $rootPackageAlias = false;
protected $stability; protected $stability;
/** @var PackageInterface */
protected $aliasOf;
/** @var Link[] */ /** @var Link[] */
protected $requires; protected $requires;
/** @var Link[] */ /** @var Link[] */

@ -175,10 +175,10 @@ class RootPackageLoader extends ArrayLoader
// extract all sub-constraints in case it is an OR/AND multi-constraint // extract all sub-constraints in case it is an OR/AND multi-constraint
$orSplit = preg_split('{\s*\|\|?\s*}', trim($reqVersion)); $orSplit = preg_split('{\s*\|\|?\s*}', trim($reqVersion));
foreach ($orSplit as $constraint) { foreach ($orSplit as $orConstraint) {
$andSplit = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $constraint); $andSplit = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $orConstraint);
foreach ($andSplit as $constraint) { foreach ($andSplit as $andConstraint) {
$constraints[] = $constraint; $constraints[] = $andConstraint;
} }
} }

@ -17,7 +17,6 @@ use Composer\Package\BasePackage;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\Loader\ArrayLoader; use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
use Composer\Semver\Semver;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
/** /**

@ -30,6 +30,7 @@ class ArtifactRepository extends ArrayRepository implements ConfigurableReposito
public function __construct(array $repoConfig, IOInterface $io) public function __construct(array $repoConfig, IOInterface $io)
{ {
parent::__construct();
if (!extension_loaded('zip')) { if (!extension_loaded('zip')) {
throw new \RuntimeException('The artifact repository requires PHP\'s zip extension'); throw new \RuntimeException('The artifact repository requires PHP\'s zip extension');
} }

@ -62,6 +62,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null) public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null)
{ {
parent::__construct();
if (!preg_match('{^[\w.]+\??://}', $repoConfig['url'])) { if (!preg_match('{^[\w.]+\??://}', $repoConfig['url'])) {
// assume http as the default protocol // assume http as the default protocol
$repoConfig['url'] = 'http://'.$repoConfig['url']; $repoConfig['url'] = 'http://'.$repoConfig['url'];

@ -33,6 +33,7 @@ class FilesystemRepository extends WritableArrayRepository
*/ */
public function __construct(JsonFile $repositoryFile) public function __construct(JsonFile $repositoryFile)
{ {
parent::__construct();
$this->file = $repositoryFile; $this->file = $repositoryFile;
} }

@ -31,6 +31,7 @@ class PackageRepository extends ArrayRepository
*/ */
public function __construct(array $config) public function __construct(array $config)
{ {
parent::__construct();
$this->config = $config['package']; $this->config = $config['package'];
// make sure we have an array of package definitions // make sure we have an array of package definitions

@ -74,7 +74,6 @@ abstract class BaseChannelReader
$xml = simplexml_load_string($this->requestContent($origin, $path), "SimpleXMLElement", LIBXML_NOERROR); $xml = simplexml_load_string($this->requestContent($origin, $path), "SimpleXMLElement", LIBXML_NOERROR);
if (false == $xml) { if (false == $xml) {
$url = rtrim($origin, '/') . '/' . ltrim($path, '/');
throw new \UnexpectedValueException(sprintf('The PEAR channel at ' . $origin . ' is broken. (Invalid XML at file `%s`)', $path)); throw new \UnexpectedValueException(sprintf('The PEAR channel at ' . $origin . ' is broken. (Invalid XML at file `%s`)', $path));
} }

@ -49,6 +49,7 @@ class PearRepository extends ArrayRepository implements ConfigurableRepositoryIn
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, RemoteFilesystem $rfs = null) public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, RemoteFilesystem $rfs = null)
{ {
parent::__construct();
if (!preg_match('{^https?://}', $repoConfig['url'])) { if (!preg_match('{^https?://}', $repoConfig['url'])) {
$repoConfig['url'] = 'http://'.$repoConfig['url']; $repoConfig['url'] = 'http://'.$repoConfig['url'];
} }

@ -38,9 +38,11 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
protected $loader; protected $loader;
protected $repoConfig; protected $repoConfig;
protected $branchErrorOccurred = false; protected $branchErrorOccurred = false;
private $drivers;
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null) public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null)
{ {
parent::__construct();
$this->drivers = $drivers ?: array( $this->drivers = $drivers ?: array(
'github' => 'Composer\Repository\Vcs\GitHubDriver', 'github' => 'Composer\Repository\Vcs\GitHubDriver',
'gitlab' => 'Composer\Repository\Vcs\GitLabDriver', 'gitlab' => 'Composer\Repository\Vcs\GitLabDriver',
@ -76,6 +78,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
if (isset($this->drivers[$this->type])) { if (isset($this->drivers[$this->type])) {
$class = $this->drivers[$this->type]; $class = $this->drivers[$this->type];
$driver = new $class($this->repoConfig, $this->io, $this->config); $driver = new $class($this->repoConfig, $this->io, $this->config);
/** @var VcsDriverInterface $driver */
$driver->initialize(); $driver->initialize();
return $driver; return $driver;
@ -84,6 +87,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
foreach ($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->config, $this->url)) { if ($driver::supports($this->io, $this->config, $this->url)) {
$driver = new $driver($this->repoConfig, $this->io, $this->config); $driver = new $driver($this->repoConfig, $this->io, $this->config);
/** @var VcsDriverInterface $driver */
$driver->initialize(); $driver->initialize();
return $driver; return $driver;
@ -93,6 +97,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
foreach ($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->config, $this->url, true)) { if ($driver::supports($this->io, $this->config, $this->url, true)) {
$driver = new $driver($this->repoConfig, $this->io, $this->config); $driver = new $driver($this->repoConfig, $this->io, $this->config);
/** @var VcsDriverInterface $driver */
$driver->initialize(); $driver->initialize();
return $driver; return $driver;

@ -244,6 +244,7 @@ class Perforce
return $value; return $value;
} }
} }
return null;
} else { } else {
$command = 'echo $' . $name; $command = 'echo $' . $name;
$this->executeCommand($command); $this->executeCommand($command);
@ -516,18 +517,22 @@ class Perforce
return false; return false;
} }
/**
* @param $reference
* @return mixed|null
*/
protected function getChangeList($reference) protected function getChangeList($reference)
{ {
$index = strpos($reference, '@'); $index = strpos($reference, '@');
if ($index === false) { if ($index === false) {
return; return null;
} }
$label = substr($reference, $index); $label = substr($reference, $index);
$command = $this->generateP4Command(' changes -m1 ' . $label); $command = $this->generateP4Command(' changes -m1 ' . $label);
$this->executeCommand($command); $this->executeCommand($command);
$changes = $this->commandResult; $changes = $this->commandResult;
if (strpos($changes, 'Change') !== 0) { if (strpos($changes, 'Change') !== 0) {
return; return null;
} }
$fields = explode(' ', $changes); $fields = explode(' ', $changes);
$changeList = $fields[1]; $changeList = $fields[1];
@ -535,15 +540,20 @@ class Perforce
return $changeList; return $changeList;
} }
/**
* @param $fromReference
* @param $toReference
* @return mixed|null
*/
public function getCommitLogs($fromReference, $toReference) public function getCommitLogs($fromReference, $toReference)
{ {
$fromChangeList = $this->getChangeList($fromReference); $fromChangeList = $this->getChangeList($fromReference);
if ($fromChangeList == null) { if ($fromChangeList == null) {
return; return null;
} }
$toChangeList = $this->getChangeList($toReference); $toChangeList = $this->getChangeList($toReference);
if ($toChangeList == null) { if ($toChangeList == null) {
return; return null;
} }
$index = strpos($fromReference, '@'); $index = strpos($fromReference, '@');
$main = substr($fromReference, 0, $index) . '/...'; $main = substr($fromReference, 0, $index) . '/...';

@ -25,6 +25,7 @@ class RemoteFilesystem
{ {
private $io; private $io;
private $config; private $config;
private $scheme;
private $bytesMax; private $bytesMax;
private $originUrl; private $originUrl;
private $fileUrl; private $fileUrl;

@ -247,7 +247,7 @@ EOT;
/** /**
* Convert certificate name into matching function. * Convert certificate name into matching function.
* *
* @param $certName CN/SAN * @param string $certName CN/SAN
* *
* @return callable|null * @return callable|null
*/ */

@ -25,6 +25,7 @@ use Composer\Util\Filesystem;
class PerforceDownloaderTest extends TestCase class PerforceDownloaderTest extends TestCase
{ {
protected $config; protected $config;
/** @var PerforceDownloader */
protected $downloader; protected $downloader;
protected $io; protected $io;
protected $package; protected $package;
@ -130,7 +131,7 @@ class PerforceDownloaderTest extends TestCase
$perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock();
$perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath)); $perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath));
$perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref)); $perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref));
$perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io)); $perforce->expects($this->at(2))->method('p4Login');
$perforce->expects($this->at(3))->method('writeP4ClientSpec'); $perforce->expects($this->at(3))->method('writeP4ClientSpec');
$perforce->expects($this->at(4))->method('connectClient'); $perforce->expects($this->at(4))->method('connectClient');
$perforce->expects($this->at(5))->method('syncCodeBase')->with($label); $perforce->expects($this->at(5))->method('syncCodeBase')->with($label);
@ -153,7 +154,7 @@ class PerforceDownloaderTest extends TestCase
$perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock();
$perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath)); $perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath));
$perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref)); $perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref));
$perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io)); $perforce->expects($this->at(2))->method('p4Login');
$perforce->expects($this->at(3))->method('writeP4ClientSpec'); $perforce->expects($this->at(3))->method('writeP4ClientSpec');
$perforce->expects($this->at(4))->method('connectClient'); $perforce->expects($this->at(4))->method('connectClient');
$perforce->expects($this->at(5))->method('syncCodeBase')->with($label); $perforce->expects($this->at(5))->method('syncCodeBase')->with($label);

Loading…
Cancel
Save