1
0
Fork 0

Merge remote-tracking branch 'curry684/code-quality' into 1.0

pull/5202/merge
Jordi Boggiano 2016-04-11 14:39:37 +01:00
commit da9b43dcc8
36 changed files with 93 additions and 52 deletions

View File

@ -18,7 +18,7 @@ use Composer\Installer\InstallationManager;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface; use Composer\Repository\WritableRepositoryInterface;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
@ -85,7 +85,7 @@ class AutoloadGenerator
$this->runScripts = (boolean) $runScripts; $this->runScripts = (boolean) $runScripts;
} }
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '') public function dump(Config $config, WritableRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '')
{ {
if ($this->classMapAuthoritative) { if ($this->classMapAuthoritative) {
// Force scanPsr0Packages when classmap is authoritative // Force scanPsr0Packages when classmap is authoritative

View File

@ -209,8 +209,9 @@ class BaseDependencyCommand extends BaseCommand
/** /**
* Recursively prints a tree of the selected results. * Recursively prints a tree of the selected results.
* *
* @param array $results * @param array $results Results to be printed at this level.
* @param string $prefix * @param string $prefix Prefix of the current tree level.
* @param int $level Current level of recursion.
*/ */
protected function printTree($results, $prefix = '', $level = 1) protected function printTree($results, $prefix = '', $level = 1)
{ {
@ -220,6 +221,7 @@ class BaseDependencyCommand extends BaseCommand
/** /**
* @var PackageInterface $package * @var PackageInterface $package
* @var Link $link * @var Link $link
* @var array|bool $children
*/ */
list($package, $link, $children) = $result; list($package, $link, $children) = $result;

View File

@ -373,6 +373,7 @@ EOT
* @param InputInterface $input * @param InputInterface $input
* @param bool $preferSource * @param bool $preferSource
* @param bool $preferDist * @param bool $preferDist
* @param bool $keepVcsRequiresPreferSource
*/ */
protected function updatePreferredOptions(Config $config, InputInterface $input, &$preferSource, &$preferDist, $keepVcsRequiresPreferSource = false) protected function updatePreferredOptions(Config $config, InputInterface $input, &$preferSource, &$preferDist, $keepVcsRequiresPreferSource = false)
{ {

View File

@ -69,7 +69,7 @@ EOT
); );
} }
return; return 0;
} }
$binary = $input->getArgument('binary'); $binary = $input->getArgument('binary');

View File

@ -67,7 +67,7 @@ EOT
foreach ($repos as $repo) { foreach ($repos as $repo) {
foreach ($repo->findPackages($packageName) as $package) { foreach ($repo->findPackages($packageName) as $package) {
$packageExists = true; $packageExists = true;
if ($this->handlePackage($package, $input->getOption('homepage'), $input->getOption('show'))) { if ($package instanceof CompletePackageInterface && $this->handlePackage($package, $input->getOption('homepage'), $input->getOption('show'))) {
$handled = true; $handled = true;
break 2; break 2;
} }

View File

@ -114,6 +114,8 @@ EOT
* *
* @param RepositoryInterface $repo * @param RepositoryInterface $repo
* @param PackageInterface $package * @param PackageInterface $package
* @param array $bucket
* @return array
*/ */
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()) private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
{ {

View File

@ -70,7 +70,7 @@ EOT
if ($input->getOption('list')) { if ($input->getOption('list')) {
return $this->listScripts(); return $this->listScripts();
} elseif (!$input->getArgument('script')) { } elseif (!$input->getArgument('script')) {
throw new \RunTimeException('Missing required argument "script"'); throw new \RuntimeException('Missing required argument "script"');
} }
$script = $input->getArgument('script'); $script = $input->getArgument('script');

View File

@ -19,7 +19,6 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositoryFactory;
use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface;
use Composer\Plugin\CommandEvent; use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;

View File

@ -305,6 +305,8 @@ TAGSPUBKEY
* @param string $localFilename * @param string $localFilename
* @param string $newFilename * @param string $newFilename
* @param string $backupTarget * @param string $backupTarget
* @return \Exception|null
* @throws \Exception
*/ */
protected function setLocalPhar($localFilename, $newFilename, $backupTarget = null) protected function setLocalPhar($localFilename, $newFilename, $backupTarget = null)
{ {
@ -323,6 +325,7 @@ TAGSPUBKEY
} }
rename($newFilename, $localFilename); rename($newFilename, $localFilename);
return null;
} catch (\Exception $e) { } catch (\Exception $e) {
if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) { if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
throw $e; throw $e;

View File

@ -89,7 +89,7 @@ EOT
if ($input->getOption('tree') && ($input->getOption('all') || $input->getOption('available'))) { if ($input->getOption('tree') && ($input->getOption('all') || $input->getOption('available'))) {
$io->writeError('The --tree (-t) option is not usable in combination with --all or --available (-a)'); $io->writeError('The --tree (-t) option is not usable in combination with --all or --available (-a)');
return; return 0;
} }
// init repos // init repos
@ -332,7 +332,11 @@ EOT
} }
/** /**
* prints package meta data * Prints package metadata.
*
* @param CompletePackageInterface $package
* @param array $versions
* @param RepositoryInterface $installedRepo
*/ */
protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo) protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
{ {
@ -389,7 +393,11 @@ EOT
} }
/** /**
* prints all available versions of this package and highlights the installed one if any * Prints all available versions of this package and highlights the installed one if any.
*
* @param CompletePackageInterface $package
* @param array $versions
* @param RepositoryInterface $installedRepo
*/ */
protected function printVersions(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo) protected function printVersions(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
{ {

View File

@ -80,7 +80,8 @@ class Config
private $useEnvironment; private $useEnvironment;
/** /**
* @param bool $useEnvironment Use COMPOSER_ environment variables to replace config settings * @param bool $useEnvironment Use COMPOSER_ environment variables to replace config settings
* @param string $baseDir Optional base directory of the config
*/ */
public function __construct($useEnvironment = true, $baseDir = null) public function __construct($useEnvironment = true, $baseDir = null)
{ {

View File

@ -45,6 +45,9 @@ class Request
* Mark an existing package as being installed and having to remain installed * Mark an existing package as being installed and having to remain installed
* *
* These jobs will not be tempered with by the solver * These jobs will not be tempered with by the solver
*
* @param string $packageName
* @param ConstraintInterface|null $constraint
*/ */
public function fix($packageName, ConstraintInterface $constraint = null) public function fix($packageName, ConstraintInterface $constraint = null)
{ {

View File

@ -69,7 +69,7 @@ class HgDownloader extends VcsDownloader
public function getLocalChanges(PackageInterface $package, $path) public function getLocalChanges(PackageInterface $package, $path)
{ {
if (!is_dir($path.'/.hg')) { if (!is_dir($path.'/.hg')) {
return; return null;
} }
$this->process->execute('hg st', $output, realpath($path)); $this->process->execute('hg st', $output, realpath($path));

View File

@ -73,7 +73,7 @@ class SvnDownloader extends VcsDownloader
public function getLocalChanges(PackageInterface $package, $path) public function getLocalChanges(PackageInterface $package, $path)
{ {
if (!$this->hasMetadataRepository($path)) { if (!$this->hasMetadataRepository($path)) {
return; return null;
} }
$this->process->execute('svn status --ignore-externals', $output, $path); $this->process->execute('svn status --ignore-externals', $output, $path);

View File

@ -137,11 +137,9 @@ class EventDispatcher
* Triggers the listeners of an event. * Triggers the listeners of an event.
* *
* @param Event $event The event object to pass to the event handlers/listeners. * @param Event $event The event object to pass to the event handlers/listeners.
* @param string $additionalArgs
* @throws \RuntimeException
* @throws \Exception
* @return int return code of the executed script if any, for php scripts a false return * @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0 * value is changed to 1, anything else to 0
* @throws \RuntimeException|\Exception
*/ */
protected function doDispatch(Event $event) protected function doDispatch(Event $event)
{ {

View File

@ -25,6 +25,7 @@ use Composer\Util\Platform;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem; use Composer\Util\RemoteFilesystem;
use Composer\Util\Silencer; use Composer\Util\Silencer;
use Seld\JsonLint\DuplicateKeyException;
use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Composer\EventDispatcher\EventDispatcher; use Composer\EventDispatcher\EventDispatcher;
use Composer\Autoload\AutoloadGenerator; use Composer\Autoload\AutoloadGenerator;
@ -270,7 +271,7 @@ class Factory
$jsonParser = new JsonParser; $jsonParser = new JsonParser;
try { try {
$jsonParser->parse(file_get_contents($localConfig), JsonParser::DETECT_KEY_CONFLICTS); $jsonParser->parse(file_get_contents($localConfig), JsonParser::DETECT_KEY_CONFLICTS);
} catch (\Seld\JsonLint\DuplicateKeyException $e) { } catch (DuplicateKeyException $e) {
$details = $e->getDetails(); $details = $e->getDetails();
$io->writeError('<warning>Key '.$details['key'].' is a duplicate in '.$localConfig.' at line '.$details['line'].'</warning>'); $io->writeError('<warning>Key '.$details['key'].' is a duplicate in '.$localConfig.' at line '.$details['line'].'</warning>');
} }

View File

@ -23,15 +23,12 @@ use Symfony\Component\Console\Helper\HelperSet;
class BufferIO extends ConsoleIO class BufferIO extends ConsoleIO
{ {
/** /**
* @param string $input * @param string $input
* @param int $verbosity * @param int $verbosity
* @param OutputFormatterInterface $formatter * @param OutputFormatterInterface|null $formatter
*/ */
public function __construct( public function __construct($input = '', $verbosity = StreamOutput::VERBOSITY_NORMAL, OutputFormatterInterface $formatter = null)
$input = '', {
$verbosity = StreamOutput::VERBOSITY_NORMAL,
OutputFormatterInterface $formatter = null
) {
$input = new StringInput($input); $input = new StringInput($input);
$input->setInteractive(false); $input->setInteractive(false);

View File

@ -27,12 +27,20 @@ use Symfony\Component\Console\Question\Question;
*/ */
class ConsoleIO extends BaseIO class ConsoleIO extends BaseIO
{ {
/** @var InputInterface */
protected $input; protected $input;
/** @var OutputInterface */
protected $output; protected $output;
/** @var HelperSet */
protected $helperSet; protected $helperSet;
/** @var string */
protected $lastMessage; protected $lastMessage;
/** @var string */
protected $lastMessageErr; protected $lastMessageErr;
/** @var float */
private $startTime; private $startTime;
/** @var array<int, int> */
private $verbosityMap; private $verbosityMap;
/** /**
@ -56,6 +64,9 @@ class ConsoleIO extends BaseIO
); );
} }
/**
* @param float $startTime
*/
public function enableDebugging($startTime) public function enableDebugging($startTime)
{ {
$this->startTime = $startTime; $this->startTime = $startTime;
@ -274,6 +285,9 @@ class ConsoleIO extends BaseIO
return $default; return $default;
} }
/**
* @return OutputInterface
*/
private function getErrorOutput() private function getErrorOutput()
{ {
if ($this->output instanceof ConsoleOutputInterface) { if ($this->output instanceof ConsoleOutputInterface) {

View File

@ -15,9 +15,7 @@ namespace Composer\Installer;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Silencer;
/** /**
* Utility to handle installation of package "bin"/binaries for PEAR packages * Utility to handle installation of package "bin"/binaries for PEAR packages
@ -30,10 +28,12 @@ class PearBinaryInstaller extends BinaryInstaller
private $vendorDir; private $vendorDir;
/** /**
* @param IOInterface $io * @param IOInterface $io
* @param string $binDir * @param string $binDir
* @param string $binCompat * @param string $vendorDir
* @param Filesystem $filesystem * @param string $binCompat
* @param Filesystem $filesystem
* @param PearInstaller $installer
*/ */
public function __construct(IOInterface $io, $binDir, $vendorDir, $binCompat, Filesystem $filesystem, PearInstaller $installer) public function __construct(IOInterface $io, $binDir, $vendorDir, $binCompat, Filesystem $filesystem, PearInstaller $installer)
{ {

View File

@ -18,7 +18,6 @@ use Composer\Downloader\PearPackageExtractor;
use Composer\Repository\InstalledRepositoryInterface; use Composer\Repository\InstalledRepositoryInterface;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Util\Platform; use Composer\Util\Platform;
use Composer\Util\ProcessExecutor;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
/** /**

View File

@ -29,7 +29,7 @@ class SuggestedPackagesReporter
protected $suggestedPackages = array(); protected $suggestedPackages = array();
/** /**
* @var Composer\IO\IOInterface * @var IOInterface
*/ */
private $io; private $io;

View File

@ -43,6 +43,7 @@ class JsonFile
* *
* @param string $path path to a lockfile * @param string $path path to a lockfile
* @param RemoteFilesystem $rfs required for loading http/https json files * @param RemoteFilesystem $rfs required for loading http/https json files
* @param IOInterface $io
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function __construct($path, RemoteFilesystem $rfs = null, IOInterface $io = null) public function __construct($path, RemoteFilesystem $rfs = null, IOInterface $io = null)
@ -105,7 +106,7 @@ class JsonFile
* *
* @param array $hash writes hash into json file * @param array $hash writes hash into json file
* @param int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) * @param int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
* @throws \UnexpectedValueException * @throws \UnexpectedValueException|\Exception
*/ */
public function write(array $hash, $options = 448) public function write(array $hash, $options = 448)
{ {

View File

@ -83,7 +83,7 @@ abstract class BaseExcludeFilter
$line = trim($line); $line = trim($line);
if (!$line || 0 === strpos($line, '#')) { if (!$line || 0 === strpos($line, '#')) {
return; return null;
} }
return call_user_func($lineParser, $line); return call_user_func($lineParser, $line);

View File

@ -69,12 +69,9 @@ class GitExcludeFilter extends BaseExcludeFilter
{ {
$parts = preg_split('#\s+#', $line); $parts = preg_split('#\s+#', $line);
if (count($parts) != 2) { if (count($parts) == 2 && $parts[1] === 'export-ignore') {
return null;
}
if ($parts[1] === 'export-ignore') {
return $this->generatePattern($parts[0]); return $this->generatePattern($parts[0]);
} }
return null;
} }
} }

View File

@ -13,9 +13,9 @@
namespace Composer\Package\Loader; namespace Composer\Package\Loader;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Config; use Composer\Config;
use Composer\Package\RootPackageInterface;
use Composer\Repository\RepositoryFactory; use Composer\Repository\RepositoryFactory;
use Composer\Package\Version\VersionGuesser; use Composer\Package\Version\VersionGuesser;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
@ -59,7 +59,7 @@ class RootPackageLoader extends ArrayLoader
* @param array $config package data * @param array $config package data
* @param string $class FQCN to be instantiated * @param string $class FQCN to be instantiated
* @param string $cwd cwd of the root package to be used to guess the version if it is not provided * @param string $cwd cwd of the root package to be used to guess the version if it is not provided
* @return PackageInterface * @return RootPackageInterface
*/ */
public function load(array $config, $class = 'Composer\Package\RootPackage', $cwd = null) public function load(array $config, $class = 'Composer\Package\RootPackage', $cwd = null)
{ {

View File

@ -56,6 +56,7 @@ class ArrayRepository extends BaseRepository
} }
} }
} }
return null;
} }
/** /**

View File

@ -272,6 +272,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
* @param Pool $pool * @param Pool $pool
* @param string $name package name * @param string $name package name
* @param bool $bypassFilters If set to true, this bypasses the stability filtering, and forces a recompute without cache * @param bool $bypassFilters If set to true, this bypasses the stability filtering, and forces a recompute without cache
* @return array|mixed
*/ */
public function whatProvides(Pool $pool, $name, $bypassFilters = false) public function whatProvides(Pool $pool, $name, $bypassFilters = false)
{ {

View File

@ -53,7 +53,6 @@ class ChannelReader extends BaseChannelReader
$xml = $this->requestXml($url, "/channel.xml"); $xml = $this->requestXml($url, "/channel.xml");
$channelName = (string) $xml->name; $channelName = (string) $xml->name;
$channelSummary = (string) $xml->summary;
$channelAlias = (string) $xml->suggestedalias; $channelAlias = (string) $xml->suggestedalias;
$supportedVersions = array_keys($this->readerMap); $supportedVersions = array_keys($this->readerMap);

View File

@ -25,7 +25,11 @@ use Composer\Json\JsonFile;
class RepositoryFactory class RepositoryFactory
{ {
/** /**
* @return array * @param IOInterface $io
* @param Config $config
* @param string $repository
* @param bool $allowFilesystem
* @return array|mixed
*/ */
public static function configFromString(IOInterface $io, Config $config, $repository, $allowFilesystem = false) public static function configFromString(IOInterface $io, Config $config, $repository, $allowFilesystem = false)
{ {
@ -52,6 +56,10 @@ class RepositoryFactory
} }
/** /**
* @param IOInterface $io
* @param Config $config
* @param string $repository
* @param bool $allowFilesystem
* @return RepositoryInterface * @return RepositoryInterface
*/ */
public static function fromString(IOInterface $io, Config $config, $repository, $allowFilesystem = false) public static function fromString(IOInterface $io, Config $config, $repository, $allowFilesystem = false)
@ -62,9 +70,12 @@ class RepositoryFactory
} }
/** /**
* @param IOInterface $io
* @param Config $config
* @param array $repoConfig
* @return RepositoryInterface * @return RepositoryInterface
*/ */
public static function createRepo($io, $config, array $repoConfig) public static function createRepo(IOInterface $io, Config $config, array $repoConfig)
{ {
$rm = static::manager($io, $config, null, Factory::createRemoteFilesystem($io, $config)); $rm = static::manager($io, $config, null, Factory::createRemoteFilesystem($io, $config));
$repos = static::createRepos($rm, array($repoConfig)); $repos = static::createRepos($rm, array($repoConfig));
@ -73,6 +84,9 @@ class RepositoryFactory
} }
/** /**
* @param IOInterface|null $io
* @param Config|null $config
* @param RepositoryManager|null $rm
* @return RepositoryInterface[] * @return RepositoryInterface[]
*/ */
public static function defaultRepos(IOInterface $io = null, Config $config = null, RepositoryManager $rm = null) public static function defaultRepos(IOInterface $io = null, Config $config = null, RepositoryManager $rm = null)

View File

@ -58,6 +58,7 @@ class RepositoryManager
return $package; return $package;
} }
} }
return null;
} }
/** /**

View File

@ -17,7 +17,6 @@ use Composer\Json\JsonFile;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Downloader\TransportException;
/** /**
* @author Per Bernhardt <plb@webfactory.de> * @author Per Bernhardt <plb@webfactory.de>

View File

@ -66,9 +66,9 @@ class ErrorHandler
} }
/** /**
* Register error handler * Register error handler.
* *
* @static * @param IOInterface|null $io
*/ */
public static function register(IOInterface $io = null) public static function register(IOInterface $io = null)
{ {

View File

@ -14,7 +14,6 @@ namespace Composer\Util;
use Composer\Config; use Composer\Config;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Downloader\TransportException;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>

View File

@ -70,6 +70,7 @@ class GitLab
/** /**
* Authorizes a GitLab domain interactively via OAuth. * Authorizes a GitLab domain interactively via OAuth.
* *
* @param string $scheme Scheme used in the origin URL
* @param string $originUrl The host this GitLab instance is located at * @param string $originUrl The host this GitLab instance is located at
* @param string $message The reason this authorization is required * @param string $message The reason this authorization is required
* *

View File

@ -13,7 +13,6 @@
namespace Composer\Util; namespace Composer\Util;
use Composer\Config; use Composer\Config;
use Composer\Downloader\TransportException;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
/** /**

View File

@ -70,7 +70,7 @@ final class TlsHelper
} }
if (!isset($info['subject']['commonName'])) { if (!isset($info['subject']['commonName'])) {
return; return null;
} }
$commonName = strtolower($info['subject']['commonName']); $commonName = strtolower($info['subject']['commonName']);
@ -82,6 +82,7 @@ final class TlsHelper
if (0 === strpos($name, 'DNS:')) { if (0 === strpos($name, 'DNS:')) {
return strtolower(ltrim(substr($name, 4))); return strtolower(ltrim(substr($name, 4)));
} }
return null;
}, $subjectAltNames)); }, $subjectAltNames));
$subjectAltNames = array_values($subjectAltNames); $subjectAltNames = array_values($subjectAltNames);
} }