1
0
Fork 0

PHPStan level 6 in src/Composer/Command (#10214)

pull/10227/head
Samuel Felipe 2021-10-27 09:18:16 -03:00 committed by GitHub
parent f667c7b8de
commit 3ccb54832b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 457 additions and 91 deletions

View File

@ -21,6 +21,9 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class AboutCommand extends BaseCommand
{
/**
* @return void
*/
protected function configure()
{
$this

View File

@ -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)

View File

@ -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<string, string> $requirements
*
* @return array<string, string>
*/
protected function formatRequirements(array $requirements)
{
$requires = array();
@ -223,6 +231,11 @@ abstract class BaseCommand extends Command
return $requires;
}
/**
* @param array<string> $requirements
*
* @return list<array{name: string, version?: string}>
*/
protected function normalizeRequirements(array $requirements)
{
$parser = new VersionParser();
@ -230,6 +243,11 @@ abstract class BaseCommand extends Command
return $parser->parseNameVersionPairs($requirements);
}
/**
* @param array<TableSeparator|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')) {

View File

@ -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 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();

View File

@ -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();

View File

@ -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();

View File

@ -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<string> $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<string> $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 array<array|bool|string> $contents
* @param array<array|string> $rawContents
* @param string|null $k
*
* @return void
*/
protected function listConfiguration(array $contents, array $rawContents, OutputInterface $output, $k = null)
{

View File

@ -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<string>|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<string>|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)
{

View File

@ -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)

View File

@ -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)
{

View File

@ -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();

View File

@ -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();

View File

@ -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) {

View File

@ -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')) {

View File

@ -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)

View File

@ -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<array{name: string, description: ?string}>
*/
protected function findPackages($name)
{
return $this->getRepos()->search($name);
@ -500,6 +511,16 @@ EOT
return $this->repos;
}
/**
* @param array<string> $requires
* @param PlatformRepository|null $platformRepo
* @param string $preferredStability
* @param bool $checkProvidedVersions
* @param bool $fixed
*
* @return array<string>
* @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<int, array{name: string, email: string}>
*/
protected function formatAuthors($author)
@ -702,6 +725,9 @@ EOT
return join('\\', $namespace);
}
/**
* @return array<string, string>
*/
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<string>
*/
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<string, string|array<string>> $options
* @return bool
*/
private function hasDependencies($options)

View File

@ -29,6 +29,9 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class InstallCommand extends BaseCommand
{
/**
* @return void
*/
protected function configure()
{
$this

View File

@ -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<string, PackageInterface> $bucket
* @return array<string, PackageInterface>
*/
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<string, PackageInterface> $bucket the list to add packages to
* @return array<string, PackageInterface>
*/
public function appendPackages(array $packages, array $bucket)
{

View File

@ -23,6 +23,9 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class OutdatedCommand extends ShowCommand
{
/**
* @return void
*/
protected function configure()
{
$this

View File

@ -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)

View File

@ -29,6 +29,9 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class ReinstallCommand extends BaseCommand
{
/**
* @return void
*/
protected function configure()
{
$this

View File

@ -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');

View File

@ -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<string, string> $newRequirements
* @param string $requireKey
* @return string[]
*/
private function getInconsistentRequireKeys(array $newRequirements, $requireKey)
{
$requireKeys = $this->getPackagesByRequireKey();
@ -296,6 +308,9 @@ EOT
return $inconsistentRequirements;
}
/**
* @return array<string, string>
*/
private function getPackagesByRequireKey()
{
$composerDefinition = $this->json->read();
@ -318,12 +333,20 @@ EOT
/**
* @private
* @return void
*/
public function markSolverComplete()
{
$this->dependencyResolutionCompleted = true;
}
/**
* @param array<string, string> $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<string, string> $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();

View File

@ -44,6 +44,9 @@ class RunScriptCommand extends BaseCommand
ScriptEvents::POST_AUTOLOAD_DUMP,
);
/**
* @return void
*/
protected function configure()
{
$this

View File

@ -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();

View File

@ -29,6 +29,9 @@ use Composer\Plugin\PluginEvents;
*/
class SearchCommand extends BaseCommand
{
/**
* @return void
*/
protected function configure()
{
$this

View File

@ -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)

View File

@ -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<string, string>}
*/
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<string, string> $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<string, string> $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<string, string> $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<string, string> $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<string, string|string[]|null> $json
* @param array<string, string> $versions
* @return array<string, string|string[]|null>
*/
private function appendVersions($json, array $versions)
{
uasort($versions, 'version_compare');
@ -871,6 +883,10 @@ EOT
return $json;
}
/**
* @param array<string, string|string[]|null> $json
* @return array<string, string|string[]|null>
*/
private function appendLicenses($json, CompletePackageInterface $package)
{
if ($licenses = $package->getLicense()) {
@ -894,6 +910,10 @@ EOT
return $json;
}
/**
* @param array<string, string|string[]|null> $json
* @return array<string, string|string[]|null>
*/
private function appendAutoload($json, CompletePackageInterface $package)
{
if ($package->getAutoload()) {
@ -923,6 +943,10 @@ EOT
return $json;
}
/**
* @param array<string, string|string[]|null> $json
* @return array<string, string|string[]|null>
*/
private function appendLinks($json, CompletePackageInterface $package)
{
foreach (Link::$TYPES as $linkType) {
@ -932,6 +956,11 @@ EOT
return $json;
}
/**
* @param array<string, string|string[]|null> $json
* @param string $linkType
* @return array<string, string|string[]|null>
*/
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<int, array<string, string|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, array<int, array<string, array|string>>|string|null>
*/
protected function generatePackageTree(
PackageInterface $package,
@ -1061,10 +1088,12 @@ EOT
/**
* Display a package tree
*
* @param array|string $package
* @param array $packagesInTree
* @param array<string, array<int, array<string, array|string>>|string|null>|string $package
* @param array<int, string|array> $packagesInTree
* @param string $previousTreeBar
* @param int $level
*
* @return void
*/
protected function displayTree(
$package,
@ -1115,11 +1144,8 @@ EOT
* Display a package tree
*
* @param string $name
* @param Link $link
* @param InstalledRepository $installedRepo
* @param RepositoryInterface $remoteRepos
* @param array $packagesInTree
* @return array
* @param string[] $packagesInTree
* @return array<int, array<string, array<int, array<string, string>>|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,9 +1239,6 @@ EOT
/**
* Given a package, this finds the latest package matching it
*
* @param PackageInterface $package
* @param Composer $composer
* @param PlatformRepository $platformRepo
* @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<PackageInterface> $bucket
* @return array<PackageInterface>
*/
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
{

View File

@ -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)

View File

@ -23,6 +23,9 @@ use Symfony\Component\Console\Output\OutputInterface;
class SuggestsCommand extends BaseCommand
{
/**
* @return void
*/
protected function configure()
{
$this

View File

@ -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<string> $packages
* @return array<string>
*/
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)

View File

@ -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;