From 3ccb54832b39ec148e00d162b0ed004a0db5c164 Mon Sep 17 00:00:00 2001 From: Samuel Felipe Date: Wed, 27 Oct 2021 09:18:16 -0300 Subject: [PATCH] PHPStan level 6 in src/Composer/Command (#10214) --- src/Composer/Command/AboutCommand.php | 3 + src/Composer/Command/ArchiveCommand.php | 14 +++ src/Composer/Command/BaseCommand.php | 29 ++++- .../Command/BaseDependencyCommand.php | 22 ++-- .../Command/CheckPlatformReqsCommand.php | 11 ++ src/Composer/Command/ClearCacheCommand.php | 6 + src/Composer/Command/ConfigCommand.php | 40 +++++- src/Composer/Command/CreateProjectCommand.php | 40 +++++- src/Composer/Command/DependsCommand.php | 4 +- src/Composer/Command/DiagnoseCommand.php | 19 ++- src/Composer/Command/DumpAutoloadCommand.php | 6 + src/Composer/Command/ExecCommand.php | 6 + src/Composer/Command/FundCommand.php | 10 ++ src/Composer/Command/GlobalCommand.php | 7 ++ src/Composer/Command/HomeCommand.php | 4 + src/Composer/Command/InitCommand.php | 49 +++++++- src/Composer/Command/InstallCommand.php | 3 + src/Composer/Command/LicensesCommand.php | 26 ++-- src/Composer/Command/OutdatedCommand.php | 3 + src/Composer/Command/ProhibitsCommand.php | 4 +- src/Composer/Command/ReinstallCommand.php | 3 + src/Composer/Command/RemoveCommand.php | 10 ++ src/Composer/Command/RequireCommand.php | 33 ++++- src/Composer/Command/RunScriptCommand.php | 3 + src/Composer/Command/ScriptAliasCommand.php | 10 ++ src/Composer/Command/SearchCommand.php | 3 + src/Composer/Command/SelfUpdateCommand.php | 25 +++- src/Composer/Command/ShowCommand.php | 117 +++++++++++------- src/Composer/Command/StatusCommand.php | 4 +- src/Composer/Command/SuggestsCommand.php | 3 + src/Composer/Command/UpdateCommand.php | 12 ++ src/Composer/Command/ValidateCommand.php | 19 ++- 32 files changed, 457 insertions(+), 91 deletions(-) diff --git a/src/Composer/Command/AboutCommand.php b/src/Composer/Command/AboutCommand.php index 931c20e55..38ac0f226 100644 --- a/src/Composer/Command/AboutCommand.php +++ b/src/Composer/Command/AboutCommand.php @@ -21,6 +21,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class AboutCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this diff --git a/src/Composer/Command/ArchiveCommand.php b/src/Composer/Command/ArchiveCommand.php index 57d99e3aa..c30c2364d 100644 --- a/src/Composer/Command/ArchiveCommand.php +++ b/src/Composer/Command/ArchiveCommand.php @@ -38,6 +38,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class ArchiveCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -110,7 +113,15 @@ EOT } /** + * @param string|null $packageName + * @param string|null $version + * @param string $format + * @param string $dest + * @param string|null $fileName + * @param bool $ignoreFilters + * * @return int + * @throws \Exception */ protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.', $fileName = null, $ignoreFilters = false, Composer $composer = null) { @@ -146,6 +157,9 @@ EOT } /** + * @param string $packageName + * @param string|null $version + * * @return (BasePackage&CompletePackageInterface)|false */ protected function selectPackage(IOInterface $io, $packageName, $version = null) diff --git a/src/Composer/Command/BaseCommand.php b/src/Composer/Command/BaseCommand.php index b473fbe80..022d7e77b 100644 --- a/src/Composer/Command/BaseCommand.php +++ b/src/Composer/Command/BaseCommand.php @@ -23,6 +23,7 @@ use Composer\Package\Version\VersionParser; use Composer\Plugin\PluginEvents; use Composer\Util\Platform; use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Command\Command; @@ -74,7 +75,7 @@ abstract class BaseCommand extends Command } /** - * @param Composer $composer + * @return void */ public function setComposer(Composer $composer) { @@ -83,6 +84,8 @@ abstract class BaseCommand extends Command /** * Removes the cached composer instance + * + * @return void */ public function resetComposer() { @@ -121,7 +124,7 @@ abstract class BaseCommand extends Command } /** - * @param IOInterface $io + * @return void */ public function setIO(IOInterface $io) { @@ -130,6 +133,8 @@ abstract class BaseCommand extends Command /** * {@inheritDoc} + * + * @return void */ protected function initialize(InputInterface $input, OutputInterface $output) { @@ -154,8 +159,6 @@ abstract class BaseCommand extends Command /** * Returns preferSource and preferDist values based on the configuration. * - * @param Config $config - * @param InputInterface $input * @param bool $keepVcsRequiresPreferSource * * @return bool[] An array composed of the preferSource and preferDist values @@ -209,6 +212,11 @@ abstract class BaseCommand extends Command return array($preferSource, $preferDist); } + /** + * @param array $requirements + * + * @return array + */ protected function formatRequirements(array $requirements) { $requires = array(); @@ -223,6 +231,11 @@ abstract class BaseCommand extends Command return $requires; } + /** + * @param array $requirements + * + * @return list + */ protected function normalizeRequirements(array $requirements) { $parser = new VersionParser(); @@ -230,6 +243,11 @@ abstract class BaseCommand extends Command return $parser->parseNameVersionPairs($requirements); } + /** + * @param array $table + * + * @return void + */ protected function renderTable(array $table, OutputInterface $output) { $renderer = new Table($output); @@ -246,6 +264,9 @@ abstract class BaseCommand extends Command $renderer->setRows($table)->render(); } + /** + * @return int + */ protected function getTerminalWidth() { if (class_exists('Symfony\Component\Console\Terminal')) { diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index b49a76b7d..ae91abae6 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -47,8 +47,6 @@ class BaseDependencyCommand extends BaseCommand /** * Execute the command. * - * @param InputInterface $input - * @param OutputInterface $output * @param bool $inverted Whether to invert matching process (why-not vs why behaviour) * @return int Exit code of the operation. */ @@ -134,8 +132,9 @@ class BaseDependencyCommand extends BaseCommand /** * Assembles and prints a bottom-up table of the dependencies. * - * @param OutputInterface $output - * @param array $results + * @param array[] $results + * + * @return void */ protected function printTable(OutputInterface $output, $results) { @@ -171,7 +170,7 @@ class BaseDependencyCommand extends BaseCommand /** * Init styles for tree * - * @param OutputInterface $output + * @return void */ protected function initStyles(OutputInterface $output) { @@ -192,9 +191,11 @@ class BaseDependencyCommand extends BaseCommand /** * Recursively prints a tree of the selected results. * - * @param array $results Results to be printed at this level. - * @param string $prefix Prefix of the current tree level. - * @param int $level Current level of recursion. + * @param array[] $results Results to be printed at this level. + * @param string $prefix Prefix of the current tree level. + * @param int $level Current level of recursion. + * + * @return void */ protected function printTree($results, $prefix = '', $level = 1) { @@ -222,6 +223,11 @@ class BaseDependencyCommand extends BaseCommand } } + /** + * @param string $line + * + * @return void + */ private function writeTreeLine($line) { $io = $this->getIO(); diff --git a/src/Composer/Command/CheckPlatformReqsCommand.php b/src/Composer/Command/CheckPlatformReqsCommand.php index 2f68a65cb..170e25f29 100644 --- a/src/Composer/Command/CheckPlatformReqsCommand.php +++ b/src/Composer/Command/CheckPlatformReqsCommand.php @@ -23,6 +23,9 @@ use Composer\Repository\InstalledRepository; class CheckPlatformReqsCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this->setName('check-platform-reqs') @@ -43,6 +46,9 @@ EOT ); } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(); @@ -166,6 +172,11 @@ EOT return $exitCode; } + /** + * @param array[] $results + * + * @return void + */ protected function printTable(OutputInterface $output, $results) { $rows = array(); diff --git a/src/Composer/Command/ClearCacheCommand.php b/src/Composer/Command/ClearCacheCommand.php index bdbdd80cf..51e02b789 100644 --- a/src/Composer/Command/ClearCacheCommand.php +++ b/src/Composer/Command/ClearCacheCommand.php @@ -22,6 +22,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class ClearCacheCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -39,6 +42,9 @@ EOT ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $config = Factory::createConfig(); diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index c96597dce..4f486cc83 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -58,6 +58,9 @@ class ConfigCommand extends BaseCommand */ protected $authConfigSource; + /** + * @return void + */ protected function configure() { $this @@ -145,6 +148,10 @@ EOT ; } + /** + * @return void + * @throws \Exception + */ protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); @@ -198,6 +205,10 @@ EOT } } + /** + * @return int + * @throws \Seld\JsonLint\ParsingException + */ protected function execute(InputInterface $input, OutputInterface $output) { // Open file in editor @@ -750,6 +761,14 @@ EOT throw new \InvalidArgumentException('Setting '.$settingKey.' does not exist or is not supported by this command'); } + /** + * @param string $key + * @param array{callable, callable} $callbacks Validator and normalizer callbacks + * @param array $values + * @param string $method + * + * @return void + */ protected function handleSingleValue($key, array $callbacks, array $values, $method) { list($validator, $normalizer) = $callbacks; @@ -774,9 +793,17 @@ EOT } } - return call_user_func(array($this->configSource, $method), $key, $normalizedValue); + call_user_func(array($this->configSource, $method), $key, $normalizedValue); } + /** + * @param string $key + * @param array{callable, callable} $callbacks Validator and normalizer callbacks + * @param array $values + * @param string $method + * + * @return void + */ protected function handleMultiValue($key, array $callbacks, array $values, $method) { list($validator, $normalizer) = $callbacks; @@ -787,16 +814,17 @@ EOT )); } - return call_user_func(array($this->configSource, $method), $key, $normalizer($values)); + call_user_func(array($this->configSource, $method), $key, $normalizer($values)); } /** * Display the contents of the file in a pretty formatted way * - * @param array $contents - * @param array $rawContents - * @param OutputInterface $output - * @param string|null $k + * @param array $contents + * @param array $rawContents + * @param string|null $k + * + * @return void */ protected function listConfiguration(array $contents, array $rawContents, OutputInterface $output, $k = null) { diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index e47945466..da01080f6 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -56,6 +56,9 @@ class CreateProjectCommand extends BaseCommand */ protected $suggestedPackagesReporter; + /** + * @return void + */ protected function configure() { $this @@ -115,6 +118,9 @@ EOT ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $config = Factory::createConfig(); @@ -160,9 +166,26 @@ EOT } /** + * @param string|null $packageName + * @param string|null $directory + * @param string|null $packageVersion + * @param string $stability + * @param bool $preferSource + * @param bool $preferDist + * @param bool $installDevPackages + * @param string|array|null $repositories + * @param bool $disablePlugins + * @param bool $noScripts + * @param bool $noProgress + * @param bool $noInstall + * @param bool $ignorePlatformReqs + * @param bool $secureHttp + * @param bool $addRepository + * * @return int + * @throws \Exception */ - public function installProject(IOInterface $io, Config $config, InputInterface $input, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositories = null, $disablePlugins = false, $noScripts = false, $noProgress = false, $noInstall = false, $ignorePlatformReqs = false, $secureHttp = true, $addRepository = false) + public function installProject(IOInterface $io, Config $config, InputInterface $input, $packageName = null, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositories = null, $disablePlugins = false, $noScripts = false, $noProgress = false, $noInstall = false, $ignorePlatformReqs = false, $secureHttp = true, $addRepository = false) { $oldCwd = getcwd(); @@ -308,7 +331,22 @@ EOT } /** + * @param string $packageName + * @param string|null $directory + * @param string|null $packageVersion + * @param string|null $stability + * @param bool $preferSource + * @param bool $preferDist + * @param bool $installDevPackages + * @param array|null $repositories + * @param bool $disablePlugins + * @param bool $noScripts + * @param bool $noProgress + * @param bool $ignorePlatformReqs + * @param bool $secureHttp + * * @return bool + * @throws \Exception */ protected function installRootPackage(IOInterface $io, Config $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, array $repositories = null, $disablePlugins = false, $noScripts = false, $noProgress = false, $ignorePlatformReqs = false, $secureHttp = true) { diff --git a/src/Composer/Command/DependsCommand.php b/src/Composer/Command/DependsCommand.php index c1ebe7eab..9ea939946 100644 --- a/src/Composer/Command/DependsCommand.php +++ b/src/Composer/Command/DependsCommand.php @@ -24,6 +24,8 @@ class DependsCommand extends BaseDependencyCommand { /** * Configure command metadata. + * + * @return void */ protected function configure() { @@ -51,8 +53,6 @@ EOT /** * Execute the function. * - * @param InputInterface $input - * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index b788c5e0f..8e4e617cc 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -48,6 +48,9 @@ class DiagnoseCommand extends BaseCommand /** @var int */ protected $exitCode = 0; + /** + * @return void + */ protected function configure() { $this @@ -65,6 +68,9 @@ EOT ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(false); @@ -237,6 +243,8 @@ EOT } /** + * @param string $proto + * * @return string|string[]|true */ private function checkHttp($proto, Config $config) @@ -303,6 +311,9 @@ EOT } /** + * @param string $domain + * @param string $token + * * @return string|true|\Exception */ private function checkGithubOauth($domain, $token) @@ -356,7 +367,7 @@ EOT /** * @return string|true */ - private function checkDiskSpace($config) + private function checkDiskSpace(Config $config) { $minSpaceFree = 1024 * 1024; if ((($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree) @@ -371,7 +382,7 @@ EOT /** * @return string[]|true */ - private function checkPubKeys($config) + private function checkPubKeys(Config $config) { $home = $config->get('home'); $errors = array(); @@ -403,7 +414,7 @@ EOT /** * @return string|\Exception|true */ - private function checkVersion($config) + private function checkVersion(Config $config) { $result = $this->checkConnectivity(); if ($result !== true) { @@ -446,6 +457,8 @@ EOT /** * @param bool|string|string[]|\Exception $result + * + * @return void */ private function outputResult($result) { diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index c4b0b9926..20da6fb15 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -23,6 +23,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class DumpAutoloadCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -50,6 +53,9 @@ EOT ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(); diff --git a/src/Composer/Command/ExecCommand.php b/src/Composer/Command/ExecCommand.php index 167a2be0d..7cc2c3fae 100644 --- a/src/Composer/Command/ExecCommand.php +++ b/src/Composer/Command/ExecCommand.php @@ -22,6 +22,9 @@ use Symfony\Component\Console\Input\InputArgument; */ class ExecCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -46,6 +49,9 @@ EOT ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(); diff --git a/src/Composer/Command/FundCommand.php b/src/Composer/Command/FundCommand.php index edba9e806..00bbca4af 100644 --- a/src/Composer/Command/FundCommand.php +++ b/src/Composer/Command/FundCommand.php @@ -28,6 +28,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class FundCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this->setName('fund') @@ -38,6 +41,9 @@ class FundCommand extends BaseCommand ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(); @@ -125,6 +131,10 @@ class FundCommand extends BaseCommand return 0; } + /** + * @param array[] $fundings + * @return array[] + */ private function insertFundingData(array $fundings, CompletePackageInterface $package) { foreach ($package->getFunding() as $fundingOption) { diff --git a/src/Composer/Command/GlobalCommand.php b/src/Composer/Command/GlobalCommand.php index c78ea7109..b35393a90 100644 --- a/src/Composer/Command/GlobalCommand.php +++ b/src/Composer/Command/GlobalCommand.php @@ -25,6 +25,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class GlobalCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -57,6 +60,10 @@ EOT ; } + /** + * @return int|void + * @throws \Symfony\Component\Console\Exception\ExceptionInterface + */ public function run(InputInterface $input, OutputInterface $output) { if (!method_exists($input, '__toString')) { diff --git a/src/Composer/Command/HomeCommand.php b/src/Composer/Command/HomeCommand.php index 62c52e923..540f2bc4c 100644 --- a/src/Composer/Command/HomeCommand.php +++ b/src/Composer/Command/HomeCommand.php @@ -30,6 +30,8 @@ class HomeCommand extends BaseCommand { /** * {@inheritDoc} + * + * @return void */ protected function configure() { @@ -98,6 +100,8 @@ EOT } /** + * @param bool $showHomepage + * @param bool $showOnly * @return bool */ private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index e06b670b9..945571441 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -54,6 +54,8 @@ class InitCommand extends BaseCommand /** * {@inheritdoc} + * + * @return void */ protected function configure() { @@ -89,6 +91,9 @@ EOT /** * {@inheritdoc} + * + * @return int + * @throws \Seld\JsonLint\ParsingException */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -220,6 +225,8 @@ EOT /** * {@inheritdoc} + * + * @return void */ protected function interact(InputInterface $input, OutputInterface $output) { @@ -480,6 +487,10 @@ EOT ); } + /** + * @param string $name + * @return list + */ protected function findPackages($name) { return $this->getRepos()->search($name); @@ -500,6 +511,16 @@ EOT return $this->repos; } + /** + * @param array $requires + * @param PlatformRepository|null $platformRepo + * @param string $preferredStability + * @param bool $checkProvidedVersions + * @param bool $fixed + * + * @return array + * @throws \Exception + */ final protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array(), PlatformRepository $platformRepo = null, $preferredStability = 'stable', $checkProvidedVersions = true, $fixed = false) { if ($requires) { @@ -667,6 +688,8 @@ EOT } /** + * @param string $author + * * @return array */ protected function formatAuthors($author) @@ -702,6 +725,9 @@ EOT return join('\\', $namespace); } + /** + * @return array + */ protected function getGitConfig() { if (null !== $this->gitConfig) { @@ -767,6 +793,12 @@ EOT return false; } + /** + * @param string $ignoreFile + * @param string $vendor + * + * @return void + */ protected function addVendorIgnore($ignoreFile, $vendor = '/vendor/') { $contents = ""; @@ -782,6 +814,8 @@ EOT } /** + * @param string $email + * * @return bool */ protected function isValidEmail($email) @@ -800,6 +834,8 @@ EOT } /** + * @param string|null $minimumStability + * * @return RepositorySet */ private function getRepositorySet(InputInterface $input, $minimumStability = null) @@ -838,7 +874,6 @@ EOT * * This returns a version with the ~ operator prefixed when possible. * - * @param InputInterface $input * @param string $name * @param PlatformRepository|null $platformRepo * @param string $preferredStability @@ -846,7 +881,7 @@ EOT * @param string $minimumStability * @param bool $fixed * @throws \InvalidArgumentException - * @return array name version + * @return array{string, string} name version */ private function findBestVersionAndNameForPackage(InputInterface $input, $name, PlatformRepository $platformRepo = null, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null, $fixed = null) { @@ -987,6 +1022,11 @@ EOT return ':'.PHP_EOL.' - ' . implode(PHP_EOL.' - ', $details); } + /** + * @param string $package + * + * @return array + */ private function findSimilar($package) { try { @@ -1014,7 +1054,7 @@ EOT /** * @return void */ - private function updateDependencies($output) + private function updateDependencies(OutputInterface $output) { try { $updateCommand = $this->getApplication()->find('update'); @@ -1028,7 +1068,7 @@ EOT /** * @return void */ - private function runDumpAutoloadCommand($output) + private function runDumpAutoloadCommand(OutputInterface $output) { try { $command = $this->getApplication()->find('dump-autoload'); @@ -1040,6 +1080,7 @@ EOT } /** + * @param array> $options * @return bool */ private function hasDependencies($options) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index eda9c25cf..583fc33a1 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -29,6 +29,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class InstallCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index b4544cf50..3f19d366e 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -13,6 +13,8 @@ namespace Composer\Command; use Composer\Json\JsonFile; +use Composer\Package\BasePackage; +use Composer\Package\CompletePackageInterface; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; use Composer\Package\PackageInterface; @@ -28,6 +30,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; */ class LicensesCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -48,6 +53,9 @@ EOT ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(); @@ -91,7 +99,7 @@ EOT $table->addRow(array( $package->getPrettyName(), $package->getFullPrettyVersion(), - implode(', ', $package->getLicense()) ?: 'none', + implode(', ', $package instanceof CompletePackageInterface ? $package->getLicense() : array()) ?: 'none', )); } $table->render(); @@ -102,7 +110,7 @@ EOT foreach ($packages as $package) { $dependencies[$package->getPrettyName()] = array( 'version' => $package->getFullPrettyVersion(), - 'license' => $package->getLicense(), + 'license' => $package instanceof CompletePackageInterface ? $package->getLicense() : array(), ); } @@ -117,7 +125,7 @@ EOT case 'summary': $usedLicenses = array(); foreach ($packages as $package) { - $license = $package->getLicense(); + $license = $package instanceof CompletePackageInterface ? $package->getLicense() : array(); $licenseName = $license[0]; if (!isset($usedLicenses[$licenseName])) { $usedLicenses[$licenseName] = 0; @@ -149,10 +157,8 @@ EOT /** * Find package requires and child requires * - * @param RepositoryInterface $repo - * @param PackageInterface $package - * @param array $bucket - * @return array + * @param array $bucket + * @return array */ private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()) { @@ -178,9 +184,9 @@ EOT /** * Adds packages to the package list * - * @param array $packages the list of packages to add - * @param array $bucket the list to add packages to - * @return array + * @param PackageInterface[] $packages the list of packages to add + * @param array $bucket the list to add packages to + * @return array */ public function appendPackages(array $packages, array $bucket) { diff --git a/src/Composer/Command/OutdatedCommand.php b/src/Composer/Command/OutdatedCommand.php index ace1631d8..584a755b7 100644 --- a/src/Composer/Command/OutdatedCommand.php +++ b/src/Composer/Command/OutdatedCommand.php @@ -23,6 +23,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class OutdatedCommand extends ShowCommand { + /** + * @return void + */ protected function configure() { $this diff --git a/src/Composer/Command/ProhibitsCommand.php b/src/Composer/Command/ProhibitsCommand.php index 9931a881b..c51d320f5 100644 --- a/src/Composer/Command/ProhibitsCommand.php +++ b/src/Composer/Command/ProhibitsCommand.php @@ -24,6 +24,8 @@ class ProhibitsCommand extends BaseDependencyCommand { /** * Configure command metadata. + * + * @return void */ protected function configure() { @@ -52,8 +54,6 @@ EOT /** * Execute the function. * - * @param InputInterface $input - * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) diff --git a/src/Composer/Command/ReinstallCommand.php b/src/Composer/Command/ReinstallCommand.php index c92564658..94da95f1d 100644 --- a/src/Composer/Command/ReinstallCommand.php +++ b/src/Composer/Command/ReinstallCommand.php @@ -29,6 +29,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class ReinstallCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php index 3cd865126..926500c09 100644 --- a/src/Composer/Command/RemoveCommand.php +++ b/src/Composer/Command/RemoveCommand.php @@ -31,6 +31,9 @@ use Composer\Package\BasePackage; */ class RemoveCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -70,6 +73,9 @@ EOT ; } + /** + * @return void + */ protected function interact(InputInterface $input, OutputInterface $output) { if ($input->getOption('unused')) { @@ -117,6 +123,10 @@ EOT } } + /** + * @return int + * @throws \Seld\JsonLint\ParsingException + */ protected function execute(InputInterface $input, OutputInterface $output) { $packages = $input->getArgument('packages'); diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 9388af63d..c629af5db 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -56,6 +56,9 @@ class RequireCommand extends InitCommand /** @var bool */ private $dependencyResolutionCompleted = false; + /** + * @return void + */ protected function configure() { $this @@ -106,6 +109,10 @@ EOT ; } + /** + * @return int + * @throws \Seld\JsonLint\ParsingException + */ protected function execute(InputInterface $input, OutputInterface $output) { if (function_exists('pcntl_async_signals') && function_exists('pcntl_signal')) { @@ -280,6 +287,11 @@ EOT } } + /** + * @param array $newRequirements + * @param string $requireKey + * @return string[] + */ private function getInconsistentRequireKeys(array $newRequirements, $requireKey) { $requireKeys = $this->getPackagesByRequireKey(); @@ -296,6 +308,9 @@ EOT return $inconsistentRequirements; } + /** + * @return array + */ private function getPackagesByRequireKey() { $composerDefinition = $this->json->read(); @@ -318,12 +333,20 @@ EOT /** * @private + * @return void */ public function markSolverComplete() { $this->dependencyResolutionCompleted = true; } + /** + * @param array $requirements + * @param string $requireKey + * @param string $removeKey + * @return int + * @throws \Exception + */ private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, $requireKey, $removeKey) { // Update packages @@ -418,9 +441,13 @@ EOT } /** + * @param array $new + * @param string $requireKey + * @param string $removeKey + * @param bool $sortPackages * @return bool */ - private function updateFileCleanly($json, array $new, $requireKey, $removeKey, $sortPackages) + private function updateFileCleanly(JsonFile $json, array $new, $requireKey, $removeKey, $sortPackages) { $contents = file_get_contents($json->getPath()); @@ -447,6 +474,10 @@ EOT return; } + /** + * @param bool $hardExit + * @return void + */ public function revertComposerFile($hardExit = true) { $io = $this->getIO(); diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php index 052139f8b..6bb0f0a64 100644 --- a/src/Composer/Command/RunScriptCommand.php +++ b/src/Composer/Command/RunScriptCommand.php @@ -44,6 +44,9 @@ class RunScriptCommand extends BaseCommand ScriptEvents::POST_AUTOLOAD_DUMP, ); + /** + * @return void + */ protected function configure() { $this diff --git a/src/Composer/Command/ScriptAliasCommand.php b/src/Composer/Command/ScriptAliasCommand.php index 63f0f9e6a..1cf3e2ba9 100644 --- a/src/Composer/Command/ScriptAliasCommand.php +++ b/src/Composer/Command/ScriptAliasCommand.php @@ -27,6 +27,10 @@ class ScriptAliasCommand extends BaseCommand /** @var string */ private $description; + /** + * @param string $script + * @param string $description + */ public function __construct($script, $description) { $this->script = $script; @@ -35,6 +39,9 @@ class ScriptAliasCommand extends BaseCommand parent::__construct(); } + /** + * @return void + */ protected function configure() { $this @@ -57,6 +64,9 @@ EOT ; } + /** + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) { $composer = $this->getComposer(); diff --git a/src/Composer/Command/SearchCommand.php b/src/Composer/Command/SearchCommand.php index 8b51d530a..a4e63198b 100644 --- a/src/Composer/Command/SearchCommand.php +++ b/src/Composer/Command/SearchCommand.php @@ -29,6 +29,9 @@ use Composer\Plugin\PluginEvents; */ class SearchCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index bfa1bd481..b21f7bf83 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -38,6 +38,9 @@ class SelfUpdateCommand extends BaseCommand const HOMEPAGE = 'getcomposer.org'; const OLD_INSTALL_EXT = '-old.phar'; + /** + * @return void + */ protected function configure() { $this @@ -70,6 +73,10 @@ EOT ; } + /** + * @return int + * @throws FilesystemException + */ protected function execute(InputInterface $input, OutputInterface $output) { $config = Factory::createConfig(); @@ -105,7 +112,8 @@ EOT $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; if ($input->getOption('update-keys')) { - return $this->fetchKeys($io, $config); + $this->fetchKeys($io, $config); + return 0; } // ensure composer.phar location is accessible @@ -324,6 +332,10 @@ TAGSPUBKEY return 0; } + /** + * @return void + * @throws \Exception + */ protected function fetchKeys(IOInterface $io, Config $config) { if (!$io->isInteractive()) { @@ -370,7 +382,10 @@ TAGSPUBKEY } /** + * @param string $rollbackDir + * @param string $localFilename * @return int + * @throws FilesystemException */ protected function rollback(OutputInterface $output, $rollbackDir, $localFilename) { @@ -451,6 +466,12 @@ TAGSPUBKEY } } + /** + * @param string $rollbackDir + * @param string|null $except + * + * @return void + */ protected function cleanBackups($rollbackDir, $except = null) { $finder = $this->getOldInstallationFinder($rollbackDir); @@ -468,6 +489,7 @@ TAGSPUBKEY } /** + * @param string $rollbackDir * @return string|false */ protected function getLastBackupVersion($rollbackDir) @@ -484,6 +506,7 @@ TAGSPUBKEY } /** + * @param string $rollbackDir * @return Finder */ protected function getOldInstallationFinder($rollbackDir) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 1640d0562..ac75b202d 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -59,6 +59,9 @@ class ShowCommand extends BaseCommand /** @var ?RepositorySet */ private $repositorySet; + /** + * @return void + */ protected function configure() { $this @@ -553,6 +556,9 @@ EOT return $exitCode; } + /** + * @return string[] + */ protected function getRootRequires() { $rootPackage = $this->getComposer()->getPackage(); @@ -563,6 +569,9 @@ EOT ); } + /** + * @return array|string|string[] + */ protected function getVersionStyle(PackageInterface $latestPackage, PackageInterface $package) { return $this->updateStatusToVersionStyle($this->getUpdateStatus($latestPackage, $package)); @@ -571,12 +580,10 @@ EOT /** * finds a package by name and version if provided * - * @param InstalledRepository $installedRepo - * @param RepositoryInterface $repos * @param string $name * @param ConstraintInterface|string $version * @throws \InvalidArgumentException - * @return array array(CompletePackageInterface, array of versions) + * @return array{CompletePackageInterface|null, array} */ protected function getPackage(InstalledRepository $installedRepo, RepositoryInterface $repos, $name, $version = null) { @@ -617,10 +624,10 @@ EOT /** * Prints package info. * - * @param CompletePackageInterface $package - * @param array $versions - * @param InstalledRepository $installedRepo + * @param array $versions * @param PackageInterface|null $latestPackage + * + * @return void */ protected function printPackageInfo(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null) { @@ -645,10 +652,10 @@ EOT /** * Prints package metadata. * - * @param CompletePackageInterface $package - * @param array $versions - * @param InstalledRepository $installedRepo + * @param array $versions * @param PackageInterface|null $latestPackage + * + * @return void */ protected function printMeta(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null) { @@ -713,9 +720,9 @@ EOT /** * Prints all available versions of this package and highlights the installed one if any. * - * @param CompletePackageInterface $package - * @param array $versions - * @param InstalledRepository $installedRepo + * @param array $versions + * + * @return void */ protected function printVersions(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo) { @@ -741,9 +748,10 @@ EOT /** * print link objects * - * @param CompletePackageInterface $package * @param string $linkType * @param string $title + * + * @return void */ protected function printLinks(CompletePackageInterface $package, $linkType, $title = null) { @@ -761,7 +769,7 @@ EOT /** * Prints the licenses of a package with metadata * - * @param CompletePackageInterface $package + * @return void */ protected function printLicenses(CompletePackageInterface $package) { @@ -791,10 +799,9 @@ EOT /** * Prints package info in JSON format. * - * @param CompletePackageInterface $package - * @param array $versions - * @param InstalledRepository $installedRepo - * @param PackageInterface|null $latestPackage + * @param array $versions + * + * @return void */ protected function printPackageInfoAsJson(CompletePackageInterface $package, array $versions, InstalledRepository $installedRepo, PackageInterface $latestPackage = null) { @@ -862,6 +869,11 @@ EOT $this->getIO()->write(JsonFile::encode($json)); } + /** + * @param array $json + * @param array $versions + * @return array + */ private function appendVersions($json, array $versions) { uasort($versions, 'version_compare'); @@ -871,6 +883,10 @@ EOT return $json; } + /** + * @param array $json + * @return array + */ private function appendLicenses($json, CompletePackageInterface $package) { if ($licenses = $package->getLicense()) { @@ -894,6 +910,10 @@ EOT return $json; } + /** + * @param array $json + * @return array + */ private function appendAutoload($json, CompletePackageInterface $package) { if ($package->getAutoload()) { @@ -923,6 +943,10 @@ EOT return $json; } + /** + * @param array $json + * @return array + */ private function appendLinks($json, CompletePackageInterface $package) { foreach (Link::$TYPES as $linkType) { @@ -932,6 +956,11 @@ EOT return $json; } + /** + * @param array $json + * @param string $linkType + * @return array + */ private function appendLink($json, CompletePackageInterface $package, $linkType) { $links = $package->{'get' . ucfirst($linkType)}(); @@ -950,7 +979,7 @@ EOT /** * Init styles for tree * - * @param OutputInterface $output + * @return void */ protected function initStyles(OutputInterface $output) { @@ -971,7 +1000,8 @@ EOT /** * Display the tree * - * @param array $arrayTree + * @param array> $arrayTree + * @return void */ protected function displayPackageTree(array $arrayTree) { @@ -1016,10 +1046,7 @@ EOT /** * Generate the package tree * - * @param PackageInterface $package - * @param InstalledRepository $installedRepo - * @param RepositoryInterface $remoteRepos - * @return array + * @return array>|string|null> */ protected function generatePackageTree( PackageInterface $package, @@ -1061,10 +1088,12 @@ EOT /** * Display a package tree * - * @param array|string $package - * @param array $packagesInTree - * @param string $previousTreeBar - * @param int $level + * @param array>|string|null>|string $package + * @param array $packagesInTree + * @param string $previousTreeBar + * @param int $level + * + * @return void */ protected function displayTree( $package, @@ -1114,12 +1143,9 @@ EOT /** * Display a package tree * - * @param string $name - * @param Link $link - * @param InstalledRepository $installedRepo - * @param RepositoryInterface $remoteRepos - * @param array $packagesInTree - * @return array + * @param string $name + * @param string[] $packagesInTree + * @return array>|string>> */ protected function addTree( $name, @@ -1161,6 +1187,10 @@ EOT return $children; } + /** + * @param string $updateStatus + * @return string + */ private function updateStatusToVersionStyle($updateStatus) { // 'up-to-date' is printed green @@ -1169,6 +1199,9 @@ EOT return str_replace(array('up-to-date', 'semver-safe-update', 'update-possible'), array('info', 'highlight', 'comment'), $updateStatus); } + /** + * @return string + */ private function getUpdateStatus(PackageInterface $latestPackage, PackageInterface $package) { if ($latestPackage->getFullPrettyVersion() === $package->getFullPrettyVersion()) { @@ -1188,6 +1221,11 @@ EOT return 'update-possible'; } + /** + * @param string $line + * + * @return void + */ private function writeTreeLine($line) { $io = $this->getIO(); @@ -1201,10 +1239,7 @@ EOT /** * Given a package, this finds the latest package matching it * - * @param PackageInterface $package - * @param Composer $composer - * @param PlatformRepository $platformRepo - * @param bool $minorOnly + * @param bool $minorOnly * * @return PackageInterface|false */ @@ -1257,10 +1292,8 @@ EOT /** * Find package requires and child requires * - * @param RepositoryInterface $repo - * @param PackageInterface $package - * @param array $bucket - * @return array + * @param array $bucket + * @return array */ private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array()) { diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index ede91ac13..cc4876fd0 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -37,6 +37,7 @@ class StatusCommand extends BaseCommand const EXIT_CODE_VERSION_CHANGES = 4; /** + * @return void * @throws \Symfony\Component\Console\Exception\InvalidArgumentException */ protected function configure() @@ -59,8 +60,6 @@ EOT } /** - * @param InputInterface $input - * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) @@ -82,7 +81,6 @@ EOT } /** - * @param InputInterface $input * @return int */ private function doExecute(InputInterface $input) diff --git a/src/Composer/Command/SuggestsCommand.php b/src/Composer/Command/SuggestsCommand.php index cb1f4e9a6..c6da9fc5d 100644 --- a/src/Composer/Command/SuggestsCommand.php +++ b/src/Composer/Command/SuggestsCommand.php @@ -23,6 +23,9 @@ use Symfony\Component\Console\Output\OutputInterface; class SuggestsCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 7c2a7dcee..84c99ffd7 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -36,6 +36,9 @@ use Symfony\Component\Console\Question\Question; */ class UpdateCommand extends BaseCommand { + /** + * @return void + */ protected function configure() { $this @@ -105,6 +108,10 @@ EOT ; } + /** + * @return int + * @throws \Exception + */ protected function execute(InputInterface $input, OutputInterface $output) { $io = $this->getIO(); @@ -241,6 +248,10 @@ EOT return $install->run(); } + /** + * @param array $packages + * @return array + */ private function getPackagesInteractively(IOInterface $io, InputInterface $input, OutputInterface $output, Composer $composer, array $packages) { if (!$input->isInteractive()) { @@ -305,6 +316,7 @@ EOT } /** + * @param string $constraint * @return Link */ private function appendConstraintToLink(Link $link, $constraint) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index fdb424423..e66cbf23b 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -13,6 +13,7 @@ namespace Composer\Command; use Composer\Factory; +use Composer\IO\IOInterface; use Composer\Package\Loader\ValidatingArrayLoader; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; @@ -35,6 +36,7 @@ class ValidateCommand extends BaseCommand { /** * configure + * @return void */ protected function configure() { @@ -65,9 +67,6 @@ EOT } /** - * @param InputInterface $input - * @param OutputInterface $output - * * @return int */ protected function execute(InputInterface $input, OutputInterface $output) @@ -161,7 +160,19 @@ EOT return max($eventCode, $exitCode); } - private function outputResult($io, $name, &$errors, &$warnings, $checkPublish = false, $publishErrors = array(), $checkLock = false, $lockErrors = array(), $printSchemaUrl = false) + /** + * @param string $name + * @param string[] $errors + * @param string[] $warnings + * @param bool $checkPublish + * @param string[] $publishErrors + * @param bool $checkLock + * @param string[] $lockErrors + * @param bool $printSchemaUrl + * + * @return void + */ + private function outputResult(IOInterface $io, $name, &$errors, &$warnings, $checkPublish = false, $publishErrors = array(), $checkLock = false, $lockErrors = array(), $printSchemaUrl = false) { $doPrintSchemaUrl = false;