1
0
Fork 0

Fix type issues (#7996)

* Fix type issues found by Psalm
pull/7906/head^2
Matthew Brown 2019-02-19 09:35:48 -05:00 committed by Jordi Boggiano
parent ab945a6ec1
commit 65903aacfd
34 changed files with 59 additions and 66 deletions

View File

@ -27,6 +27,8 @@ use Symfony\Component\Console\Command\Command;
/** /**
* Base class for Composer commands * Base class for Composer commands
* *
* @method Application getApplication()
*
* @author Ryan Weaver <ryan@knplabs.com> * @author Ryan Weaver <ryan@knplabs.com>
* @author Konstantin Kudryashov <ever.zet@gmail.com> * @author Konstantin Kudryashov <ever.zet@gmail.com>
*/ */
@ -46,7 +48,7 @@ abstract class BaseCommand extends Command
* @param bool $required * @param bool $required
* @param bool|null $disablePlugins * @param bool|null $disablePlugins
* @throws \RuntimeException * @throws \RuntimeException
* @return Composer * @return Composer|null
*/ */
public function getComposer($required = true, $disablePlugins = 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'))) { 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')); $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); return array($preferSource, $preferDist);

View File

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

View File

@ -602,20 +602,6 @@ EOT
$text .= "Install either of them or recompile php without --disable-iconv"; $text .= "Install either of them or recompile php without --disable-iconv";
break; 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': case 'php':
$text = PHP_EOL."Your PHP ({$current}) is too old, you must upgrade to PHP 5.3.2 or higher."; $text = PHP_EOL."Your PHP ({$current}) is too old, you must upgrade to PHP 5.3.2 or higher.";
break; break;
@ -713,7 +699,7 @@ EOT
/** /**
* Check if allow_url_fopen is ON * Check if allow_url_fopen is ON
* *
* @return bool|string * @return true|string
*/ */
private function checkConnectivity() private function checkConnectivity()
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -176,12 +176,12 @@ class PoolBuilder
if (!isset($this->loadedNames[$require])) { if (!isset($this->loadedNames[$require])) {
$loadNames[$require] = null; $loadNames[$require] = null;
} }
if ($link->getConstraint()) { if ($linkConstraint = $link->getConstraint()) {
if (!array_key_exists($require, $this->nameConstraints)) { 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]) { } elseif ($this->nameConstraints[$require]) {
// TODO addConstraint function? // 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 { } else {
$this->nameConstraints[$require] = null; $this->nameConstraints[$require] = null;

View File

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

View File

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

View File

@ -294,9 +294,7 @@ class DownloadManager
// if downloader type changed, or update failed and user asks for reinstall, // 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 // 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); $this->install($target, $targetDir);
} }

View File

@ -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)); $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)) { 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)); $command = sprintf('git reset --hard %s --', ProcessExecutor::escape($reference));
if (0 === $this->process->execute($command, $output, $path)) { if (0 === $this->process->execute($command, $output, $path)) {
return; return null;
} }
} }
} }
$command = sprintf($template, ProcessExecutor::escape($gitRef)); $command = sprintf($template, ProcessExecutor::escape($gitRef));
if (0 === $this->process->execute($command, $output, $path)) { if (0 === $this->process->execute($command, $output, $path)) {
return; return null;
} }
// reference was not found (prints "fatal: reference is not a tree: $ref") // reference was not found (prints "fatal: reference is not a tree: $ref")

View File

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

View File

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

View File

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

View File

@ -108,7 +108,7 @@ interface IOInterface extends LoggerInterface
* @param string $default The default answer if none is given by the user * @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 * @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); public function ask($question, $default = null);
@ -146,7 +146,7 @@ interface IOInterface extends LoggerInterface
* *
* @param string $question The question to ask * @param string $question The question to ask
* *
* @return string The answer * @return string|null The answer
*/ */
public function askAndHideAnswer($question); public function askAndHideAnswer($question);
@ -161,7 +161,7 @@ interface IOInterface extends LoggerInterface
* @param bool $multiselect Select more than one value separated by comma * @param bool $multiselect Select more than one value separated by comma
* *
* @throws \InvalidArgumentException * @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); public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false);

View File

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

View File

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

View File

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

View File

@ -239,7 +239,7 @@ abstract class BasePackage implements PackageInterface
* Build a regexp from a package name, expanding * globs as required * Build a regexp from a package name, expanding * globs as required
* *
* @param string $whiteListedPattern * @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 * @return string
*/ */
public static function packageNameToRegexp($whiteListedPattern, $wrap = '{^%s$}i') public static function packageNameToRegexp($whiteListedPattern, $wrap = '{^%s$}i')

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -38,7 +38,7 @@ interface VcsDriverInterface
* *
* @param string $file * @param string $file
* @param string $identifier * @param string $identifier
* @return string * @return string|null
*/ */
public function getFileContent($file, $identifier); public function getFileContent($file, $identifier);
@ -46,7 +46,7 @@ interface VcsDriverInterface
* Get the changedate for $identifier. * Get the changedate for $identifier.
* *
* @param string $identifier * @param string $identifier
* @return \DateTime * @return \DateTime|null
*/ */
public function getChangeDate($identifier); public function getChangeDate($identifier);
@ -73,7 +73,7 @@ interface VcsDriverInterface
/** /**
* @param string $identifier Any identifier to a specific branch/tag/commit * @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); public function getDist($identifier);

View File

@ -73,7 +73,7 @@ class AuthHelper
* @param string|null $reason a message/description explaining why this was called * @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 $warning an authentication warning returned by the server as {"warning": ".."}, if present
* @param string[] $headers * @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 * 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()) public function promptAuthIfNeeded($url, $origin, $statusCode, $reason = null, $warning = null, $headers = array())

View File

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

View File

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

View File

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

View File

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

View File

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