Fix type issues (#7996)

* Fix type issues found by Psalm
main
Matthew Brown 5 years ago committed by Jordi Boggiano
parent ab945a6ec1
commit 65903aacfd

@ -27,6 +27,8 @@ use Symfony\Component\Console\Command\Command;
/**
* Base class for Composer commands
*
* @method Application getApplication()
*
* @author Ryan Weaver <ryan@knplabs.com>
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
@ -46,7 +48,7 @@ abstract class BaseCommand extends Command
* @param bool $required
* @param bool|null $disablePlugins
* @throws \RuntimeException
* @return Composer
* @return Composer|null
*/
public function getComposer($required = true, $disablePlugins = null)
{
@ -173,7 +175,7 @@ abstract class BaseCommand extends Command
if ($input->getOption('prefer-source') || $input->getOption('prefer-dist') || ($keepVcsRequiresPreferSource && $input->hasOption('keep-vcs') && $input->getOption('keep-vcs'))) {
$preferSource = $input->getOption('prefer-source') || ($keepVcsRequiresPreferSource && $input->hasOption('keep-vcs') && $input->getOption('keep-vcs'));
$preferDist = $input->getOption('prefer-dist');
$preferDist = (bool) $input->getOption('prefer-dist');
}
return array($preferSource, $preferDist);

@ -226,7 +226,7 @@ EOT
}
$settingKey = $input->getArgument('setting-key');
if (!$settingKey) {
if (!$settingKey || !is_string($settingKey)) {
return 0;
}

@ -602,20 +602,6 @@ EOT
$text .= "Install either of them or recompile php without --disable-iconv";
break;
case 'unicode':
$text = PHP_EOL."The detect_unicode setting must be disabled.".PHP_EOL;
$text .= "Add the following to the end of your `php.ini`:".PHP_EOL;
$text .= " detect_unicode = Off";
$displayIniMessage = true;
break;
case 'suhosin':
$text = PHP_EOL."The suhosin.executor.include.whitelist setting is incorrect.".PHP_EOL;
$text .= "Add the following to the end of your `php.ini` or suhosin.ini (Example path [for Debian]: /etc/php5/cli/conf.d/suhosin.ini):".PHP_EOL;
$text .= " suhosin.executor.include.whitelist = phar ".$current;
$displayIniMessage = true;
break;
case 'php':
$text = PHP_EOL."Your PHP ({$current}) is too old, you must upgrade to PHP 5.3.2 or higher.";
break;
@ -713,7 +699,7 @@ EOT
/**
* Check if allow_url_fopen is ON
*
* @return bool|string
* @return true|string
*/
private function checkConnectivity()
{

@ -823,10 +823,10 @@ EOT
/**
* Display a package tree
*
* @param PackageInterface|string $package
* @param array $packagesInTree
* @param string $previousTreeBar
* @param int $level
* @param array|string $package
* @param array $packagesInTree
* @param string $previousTreeBar
* @param int $level
*/
protected function displayTree(
$package,
@ -835,7 +835,7 @@ EOT
$level = 1
) {
$previousTreeBar = str_replace('├', '│', $previousTreeBar);
if (isset($package['requires'])) {
if (is_array($package) && isset($package['requires'])) {
$requires = $package['requires'];
$treeBar = $previousTreeBar . ' ├';
$i = 0;
@ -968,7 +968,7 @@ EOT
* @param string $phpVersion
* @param bool $minorOnly
*
* @return PackageInterface|null
* @return PackageInterface|false
*/
private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false)
{

@ -43,6 +43,9 @@ EOT
;
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$lock = $this->getComposer()->getLocker()->getLockData();
@ -117,7 +120,7 @@ EOT
$io->write(sprintf('<info>%s</info>', $suggestion));
}
return;
return null;
}
// Grouped by package

@ -39,7 +39,7 @@ interface ConfigSourceInterface
* Add a config setting
*
* @param string $name Name
* @param string $value Value
* @param string|array $value Value
*/
public function addConfigSetting($name, $value);

@ -259,7 +259,7 @@ class JsonConfigSource implements ConfigSourceInterface
*
* @param array $array
* @param mixed $value
* @return array
* @return int
*/
private function arrayUnshiftRef(&$array, &$value)
{

@ -284,7 +284,7 @@ class Application extends BaseApplication
return $result;
} catch (ScriptExecutionException $e) {
return $e->getCode();
return (int) $e->getCode();
} catch (\Exception $e) {
$this->hintCommonErrors($e);
restore_error_handler();

@ -23,10 +23,10 @@ class GenericRule extends Rule
protected $literals;
/**
* @param array $literals
* @param int $reason A RULE_* constant describing the reason for generating this rule
* @param Link|PackageInterface $reasonData
* @param array $job The job this rule was created from
* @param array $literals
* @param int|null $reason A RULE_* constant describing the reason for generating this rule
* @param Link|PackageInterface|int|null $reasonData
* @param array $job The job this rule was created from
*/
public function __construct(array $literals, $reason, $reasonData, $job = null)
{

@ -176,12 +176,12 @@ class PoolBuilder
if (!isset($this->loadedNames[$require])) {
$loadNames[$require] = null;
}
if ($link->getConstraint()) {
if ($linkConstraint = $link->getConstraint()) {
if (!array_key_exists($require, $this->nameConstraints)) {
$this->nameConstraints[$require] = new MultiConstraint(array($link->getConstraint()), false);
$this->nameConstraints[$require] = new MultiConstraint(array($linkConstraint), false);
} elseif ($this->nameConstraints[$require]) {
// TODO addConstraint function?
$this->nameConstraints[$require] = new MultiConstraint(array_merge(array($link->getConstraint()), $this->nameConstraints[$require]->getConstraints()), false);
$this->nameConstraints[$require] = new MultiConstraint(array_merge(array($linkConstraint), $this->nameConstraints[$require]->getConstraints()), false);
}
} else {
$this->nameConstraints[$require] = null;

@ -180,7 +180,7 @@ class Problem
* Store a reason descriptor but ignore duplicates
*
* @param string $id A canonical identifier for the reason
* @param string $reason The reason descriptor
* @param string|array $reason The reason descriptor
*/
protected function addReason($id, $reason)
{

@ -13,6 +13,7 @@
namespace Composer\DependencyResolver;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositorySet;
@ -44,7 +45,7 @@ class Solver
protected $watchGraph;
/** @var Decisions */
protected $decisions;
/** @var int[] */
/** @var PackageInterface[] */
protected $installedMap;
/** @var int */
@ -691,7 +692,7 @@ class Solver
/**
* @todo this makes $disableRules always false; determine the rationale and possibly remove dead code?
*/
$disableRules = array();
$disableRules = false;
$level = 1;
$systemLevel = $level + 1;

@ -294,9 +294,7 @@ class DownloadManager
// if downloader type changed, or update failed and user asks for reinstall,
// we wipe the dir and do a new install instead of updating it
if ($initialDownloader) {
$initialDownloader->remove($initial, $targetDir);
}
$initialDownloader->remove($initial, $targetDir);
$this->install($target, $targetDir);
}

@ -362,7 +362,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
) {
$command = sprintf('git checkout '.$force.'-B %s %s -- && git reset --hard %2$s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$reference));
if (0 === $this->process->execute($command, $output, $path)) {
return;
return null;
}
}
@ -380,14 +380,14 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
) {
$command = sprintf('git reset --hard %s --', ProcessExecutor::escape($reference));
if (0 === $this->process->execute($command, $output, $path)) {
return;
return null;
}
}
}
$command = sprintf($template, ProcessExecutor::escape($gitRef));
if (0 === $this->process->execute($command, $output, $path)) {
return;
return null;
}
// reference was not found (prints "fatal: reference is not a tree: $ref")

@ -88,7 +88,7 @@ class PerforceDownloader extends VcsDownloader
{
$this->io->writeError('Perforce driver does not check for local changes before overriding', true);
return;
return null;
}
/**

@ -199,6 +199,7 @@ class EventDispatcher
}
try {
/** @var InstallerEvent $event */
$return = $this->dispatch($scriptName, new Script\Event($scriptName, $event->getComposer(), $event->getIO(), $event->isDevMode(), $args, $flags));
} catch (ScriptExecutionException $e) {
$this->io->writeError(sprintf('<error>Script %s was called via %s</error>', $callable, $event->getName()), true, IOInterface::QUIET);
@ -499,7 +500,7 @@ class EventDispatcher
*
* @param Event $event
* @throws \RuntimeException
* @return number
* @return int
*/
protected function pushEvent(Event $event)
{

@ -413,7 +413,7 @@ class Factory
/**
* @param IOInterface $io IO instance
* @param bool $disablePlugins Whether plugins should not be loaded
* @return Composer
* @return Composer|null
*/
public static function createGlobal(IOInterface $io, $disablePlugins = false)
{

@ -108,7 +108,7 @@ interface IOInterface extends LoggerInterface
* @param string $default The default answer if none is given by the user
*
* @throws \RuntimeException If there is no data to read in the input stream
* @return string The user answer
* @return string|null The user answer
*/
public function ask($question, $default = null);
@ -146,7 +146,7 @@ interface IOInterface extends LoggerInterface
*
* @param string $question The question to ask
*
* @return string The answer
* @return string|null The answer
*/
public function askAndHideAnswer($question);
@ -161,7 +161,7 @@ interface IOInterface extends LoggerInterface
* @param bool $multiselect Select more than one value separated by comma
*
* @throws \InvalidArgumentException
* @return int|string|array The selected value or values (the key of the choices array)
* @return int|string|array|bool The selected value or values (the key of the choices array)
*/
public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false);

@ -959,7 +959,7 @@ class Installer
* @param RepositoryInterface $lockedRepository
* @param string $task
* @param array|null $operations
* @return array
* @return array|null
*/
private function processDevPackages($localRepo, Pool $pool, $policy, $repositories, $installedRepo, $lockedRepository, $task, array $operations = null)
{

@ -48,7 +48,7 @@ interface InstallerInterface
*
* @param PackageInterface $package package instance
* @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface
* @return PromiseInterface|null
*/
public function download(PackageInterface $package, PackageInterface $prevPackage = null);

@ -43,7 +43,7 @@ class LibraryInstaller implements InstallerInterface, BinaryPresenceInterface
*
* @param IOInterface $io
* @param Composer $composer
* @param string $type
* @param string|null $type
* @param Filesystem $filesystem
* @param BinaryInstaller $binaryInstaller
*/

@ -239,7 +239,7 @@ abstract class BasePackage implements PackageInterface
* Build a regexp from a package name, expanding * globs as required
*
* @param string $whiteListedPattern
* @param bool $wrap Wrap the cleaned string by the given string
* @param string $wrap Wrap the cleaned string by the given string
* @return string
*/
public static function packageNameToRegexp($whiteListedPattern, $wrap = '{^%s$}i')

@ -76,7 +76,7 @@ interface PackageInterface
/**
* Returns the package targetDir property
*
* @return string The package targetDir
* @return string|null The package targetDir
*/
public function getTargetDir();

@ -45,7 +45,7 @@ class VersionSelector
* @param string $targetPackageVersion
* @param string $targetPhpVersion
* @param string $preferredStability
* @return PackageInterface|bool
* @return PackageInterface|false
*/
public function findBestCandidate($packageName, $targetPackageVersion = null, $targetPhpVersion = null, $preferredStability = 'stable')
{

@ -47,7 +47,7 @@ abstract class BaseChannelReader
* @param string $origin server
* @param string $path relative path to content
* @throws \UnexpectedValueException
* @return \SimpleXMLElement
* @return string
*/
protected function requestContent($origin, $path)
{

@ -150,7 +150,7 @@ class ChannelRest10Reader extends BaseChannelReader
* @param string $baseUrl
* @param string $packageName
* @param string $version
* @return DependencyInfo[]
* @return DependencyInfo
*/
private function readPackageReleaseDependencies($baseUrl, $packageName, $version)
{

@ -97,7 +97,7 @@ class PearRepository extends ArrayRepository implements ConfigurableRepositoryIn
*
* @param ChannelInfo $channelInfo
* @param SemverVersionParser $versionParser
* @return CompletePackage
* @return CompletePackage[]
*/
private function buildComposerPackages(ChannelInfo $channelInfo, SemverVersionParser $versionParser)
{

@ -38,7 +38,7 @@ interface VcsDriverInterface
*
* @param string $file
* @param string $identifier
* @return string
* @return string|null
*/
public function getFileContent($file, $identifier);
@ -46,7 +46,7 @@ interface VcsDriverInterface
* Get the changedate for $identifier.
*
* @param string $identifier
* @return \DateTime
* @return \DateTime|null
*/
public function getChangeDate($identifier);
@ -73,7 +73,7 @@ interface VcsDriverInterface
/**
* @param string $identifier Any identifier to a specific branch/tag/commit
* @return array With type, url reference and shasum keys.
* @return array|null With type, url reference and shasum keys.
*/
public function getDist($identifier);

@ -73,7 +73,7 @@ class AuthHelper
* @param string|null $reason a message/description explaining why this was called
* @param string $warning an authentication warning returned by the server as {"warning": ".."}, if present
* @param string[] $headers
* @return array containing retry (bool) and storeAuth (string|bool) keys, if retry is true the request should be
* @return array|null containing retry (bool) and storeAuth (string|bool) keys, if retry is true the request should be
* retried, if storeAuth is true then on a successful retry the authentication should be persisted to auth.json
*/
public function promptAuthIfNeeded($url, $origin, $statusCode, $reason = null, $warning = null, $headers = array())

@ -292,6 +292,7 @@ class Filesystem
$this->ensureDirectoryExists($target);
$result = true;
/** @var RecursiveDirectoryIterator $ri */
foreach ($ri as $file) {
$targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
if ($file->isDir()) {

@ -117,7 +117,7 @@ class HttpDownloader
/**
* Merges new options
*
* @return array $options
* @return void
*/
public function setOptions(array $options)
{

@ -29,6 +29,7 @@ class Loop
public function wait(array $promises)
{
/** @var \Exception|null */
$uncaught = null;
\React\Promise\all($promises)->then(

@ -398,7 +398,7 @@ class RemoteFilesystem
// fail 4xx and 5xx responses and capture the response
if ($statusCode && $statusCode >= 400 && $statusCode <= 599) {
if (!$this->retry) {
if ($this->progress && !$this->retry && !$isRedirect) {
if ($this->progress && !$isRedirect) {
$this->io->overwriteError("Downloading (<error>failed</error>)", false);
}

@ -304,7 +304,7 @@ class Svn
$this->createAuthFromUrl();
}
return $this->hasAuth;
return (bool) $this->hasAuth;
}
/**

Loading…
Cancel
Save