1
0
Fork 0

Type annotations

pull/10169/head
Jordi Boggiano 2021-10-16 11:13:29 +02:00
parent 6d5f6eb090
commit 9599eb613b
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
13 changed files with 145 additions and 17 deletions

View File

@ -54,6 +54,9 @@ class PhpFileCleaner
$this->maxMatches = $maxMatches; $this->maxMatches = $maxMatches;
} }
/**
* @return string
*/
public function clean() public function clean()
{ {
$clean = ''; $clean = '';
@ -212,11 +215,17 @@ class PhpFileCleaner
} }
} }
/**
* @return bool
*/
private function peek($char) private function peek($char)
{ {
return $this->index + 1 < $this->len && $this->contents[$this->index + 1] === $char; return $this->index + 1 < $this->len && $this->contents[$this->index + 1] === $char;
} }
/**
* @return bool
*/
private function match($regex, array &$match = null) private function match($regex, array &$match = null)
{ {
if (\preg_match($regex, $this->contents, $match, 0, $this->index)) { if (\preg_match($regex, $this->contents, $match, 0, $this->index)) {

View File

@ -75,11 +75,17 @@ class Cache
return $this->readOnly; return $this->readOnly;
} }
/**
* @return bool
*/
public static function isUsable($path) public static function isUsable($path)
{ {
return !preg_match('{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}', $path); return !preg_match('{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}', $path);
} }
/**
* @return bool
*/
public function isEnabled() public function isEnabled()
{ {
if ($this->enabled === null) { if ($this->enabled === null) {
@ -97,11 +103,17 @@ class Cache
return $this->enabled; return $this->enabled;
} }
/**
* @return string
*/
public function getRoot() public function getRoot()
{ {
return $this->root; return $this->root;
} }
/**
* @return string|false
*/
public function read($file) public function read($file)
{ {
if ($this->isEnabled()) { if ($this->isEnabled()) {
@ -116,6 +128,9 @@ class Cache
return false; return false;
} }
/**
* @return bool
*/
public function write($file, $contents) public function write($file, $contents)
{ {
if ($this->isEnabled() && !$this->readOnly) { if ($this->isEnabled() && !$this->readOnly) {
@ -154,6 +169,7 @@ class Cache
/** /**
* Copy a file into the cache * Copy a file into the cache
* @return bool
*/ */
public function copyFrom($file, $source) public function copyFrom($file, $source)
{ {
@ -175,6 +191,7 @@ class Cache
/** /**
* Copy a file out of the cache * Copy a file out of the cache
* @return bool
*/ */
public function copyTo($file, $target) public function copyTo($file, $target)
{ {
@ -198,6 +215,9 @@ class Cache
return false; return false;
} }
/**
* @return bool
*/
public function gcIsNecessary() public function gcIsNecessary()
{ {
if (self::$cacheCollected) { if (self::$cacheCollected) {
@ -216,6 +236,9 @@ class Cache
return !mt_rand(0, 50); return !mt_rand(0, 50);
} }
/**
* @return bool
*/
public function remove($file) public function remove($file)
{ {
if ($this->isEnabled()) { if ($this->isEnabled()) {
@ -228,6 +251,9 @@ class Cache
return false; return false;
} }
/**
* @return bool
*/
public function clear() public function clear()
{ {
if ($this->isEnabled()) { if ($this->isEnabled()) {
@ -239,6 +265,9 @@ class Cache
return false; return false;
} }
/**
* @return bool
*/
public function gc($ttl, $maxSize) public function gc($ttl, $maxSize)
{ {
if ($this->isEnabled()) { if ($this->isEnabled()) {
@ -269,6 +298,9 @@ class Cache
return false; return false;
} }
/**
* @return string|false
*/
public function sha1($file) public function sha1($file)
{ {
if ($this->isEnabled()) { if ($this->isEnabled()) {
@ -281,6 +313,9 @@ class Cache
return false; return false;
} }
/**
* @return string|false
*/
public function sha256($file) public function sha256($file)
{ {
if ($this->isEnabled()) { if ($this->isEnabled()) {
@ -293,6 +328,9 @@ class Cache
return false; return false;
} }
/**
* @return Finder
*/
protected function getFinder() protected function getFinder()
{ {
return Finder::create()->in($this->root)->files(); return Finder::create()->in($this->root)->files();

View File

@ -16,6 +16,7 @@ use Composer\Factory;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Config; use Composer\Config;
use Composer\Composer; use Composer\Composer;
use Composer\Package\BasePackage;
use Composer\Package\CompletePackageInterface; use Composer\Package\CompletePackageInterface;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\RepositoryFactory; use Composer\Repository\RepositoryFactory;
@ -108,6 +109,9 @@ EOT
return $returnCode; return $returnCode;
} }
/**
* @return int
*/
protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.', $fileName = null, $ignoreFilters = false, Composer $composer = null) protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.', $fileName = null, $ignoreFilters = false, Composer $composer = null)
{ {
if ($composer) { if ($composer) {
@ -142,7 +146,7 @@ EOT
} }
/** /**
* @return CompletePackageInterface|false * @return BasePackage&CompletePackageInterface|false
*/ */
protected function selectPackage(IOInterface $io, $packageName, $version = null) protected function selectPackage(IOInterface $io, $packageName, $version = null)
{ {

View File

@ -58,9 +58,6 @@ class ConfigCommand extends BaseCommand
*/ */
protected $authConfigSource; protected $authConfigSource;
/**
* {@inheritDoc}
*/
protected function configure() protected function configure()
{ {
$this $this
@ -148,9 +145,6 @@ EOT
; ;
} }
/**
* {@inheritDoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output) protected function initialize(InputInterface $input, OutputInterface $output)
{ {
parent::initialize($input, $output); parent::initialize($input, $output);
@ -204,9 +198,6 @@ EOT
} }
} }
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
// Open file in editor // Open file in editor

View File

@ -159,6 +159,9 @@ EOT
); );
} }
/**
* @return int
*/
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, $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(); $oldCwd = getcwd();
@ -304,6 +307,9 @@ EOT
return 0; return 0;
} }
/**
* @return bool
*/
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) 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)
{ {
if (!$secureHttp) { if (!$secureHttp) {

View File

@ -65,9 +65,6 @@ EOT
; ;
} }
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$composer = $this->getComposer(false); $composer = $this->getComposer(false);
@ -195,6 +192,9 @@ EOT
return $this->exitCode; return $this->exitCode;
} }
/**
* @return string|true
*/
private function checkComposerSchema() private function checkComposerSchema()
{ {
$validator = new ConfigValidator($this->getIO()); $validator = new ConfigValidator($this->getIO());
@ -219,6 +219,9 @@ EOT
return true; return true;
} }
/**
* @return string|true
*/
private function checkGit() private function checkGit()
{ {
if (!function_exists('proc_open')) { if (!function_exists('proc_open')) {
@ -233,6 +236,9 @@ EOT
return true; return true;
} }
/**
* @return string|string[]|true
*/
private function checkHttp($proto, Config $config) private function checkHttp($proto, Config $config)
{ {
$result = $this->checkConnectivity(); $result = $this->checkConnectivity();
@ -268,6 +274,9 @@ EOT
return true; return true;
} }
/**
* @return string|true|\Exception
*/
private function checkHttpProxy() private function checkHttpProxy()
{ {
$result = $this->checkConnectivity(); $result = $this->checkConnectivity();
@ -293,6 +302,9 @@ EOT
return true; return true;
} }
/**
* @return string|true|\Exception
*/
private function checkGithubOauth($domain, $token) private function checkGithubOauth($domain, $token)
{ {
$result = $this->checkConnectivity(); $result = $this->checkConnectivity();
@ -322,7 +334,7 @@ EOT
* @param string $domain * @param string $domain
* @param string $token * @param string $token
* @throws TransportException * @throws TransportException
* @return array|string * @return mixed|string
*/ */
private function getGithubRateLimit($domain, $token = null) private function getGithubRateLimit($domain, $token = null)
{ {
@ -341,6 +353,9 @@ EOT
return $data['resources']['core']; return $data['resources']['core'];
} }
/**
* @return string|true
*/
private function checkDiskSpace($config) private function checkDiskSpace($config)
{ {
$minSpaceFree = 1024 * 1024; $minSpaceFree = 1024 * 1024;
@ -353,6 +368,9 @@ EOT
return true; return true;
} }
/**
* @return string[]|true
*/
private function checkPubKeys($config) private function checkPubKeys($config)
{ {
$home = $config->get('home'); $home = $config->get('home');
@ -382,6 +400,9 @@ EOT
return $errors ?: true; return $errors ?: true;
} }
/**
* @return string|\Exception|true
*/
private function checkVersion($config) private function checkVersion($config)
{ {
$result = $this->checkConnectivity(); $result = $this->checkConnectivity();
@ -403,6 +424,9 @@ EOT
return true; return true;
} }
/**
* @return string
*/
private function getCurlVersion() private function getCurlVersion()
{ {
if (extension_loaded('curl')) { if (extension_loaded('curl')) {
@ -469,6 +493,9 @@ EOT
} }
} }
/**
* @return string|true
*/
private function checkPlatform() private function checkPlatform()
{ {
$output = ''; $output = '';
@ -699,7 +726,7 @@ EOT
/** /**
* Check if allow_url_fopen is ON * Check if allow_url_fopen is ON
* *
* @return true|string * @return string|true
*/ */
private function checkConnectivity() private function checkConnectivity()
{ {

View File

@ -97,6 +97,9 @@ EOT
return $return; return $return;
} }
/**
* @return bool
*/
private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly) private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly)
{ {
$support = $package->getSupport(); $support = $package->getSupport();
@ -122,6 +125,7 @@ EOT
* opens a url in your system default browser * opens a url in your system default browser
* *
* @param string $url * @param string $url
* @return void
*/ */
private function openBrowser($url) private function openBrowser($url)
{ {
@ -129,7 +133,8 @@ EOT
$process = new ProcessExecutor($this->getIO()); $process = new ProcessExecutor($this->getIO());
if (Platform::isWindows()) { if (Platform::isWindows()) {
return $process->execute('start "web" explorer ' . $url, $output); $process->execute('start "web" explorer ' . $url, $output);
return;
} }
$linux = $process->execute('which xdg-open', $output); $linux = $process->execute('which xdg-open', $output);

View File

@ -461,7 +461,7 @@ EOT
/** /**
* @private * @private
* @param string $author * @param string $author
* @return array * @return array{name: string, email: string}
*/ */
public function parseAuthorString($author) public function parseAuthorString($author)
{ {
@ -485,6 +485,9 @@ EOT
return $this->getRepos()->search($name); return $this->getRepos()->search($name);
} }
/**
* @return CompositeRepository
*/
protected function getRepos() protected function getRepos()
{ {
if (!$this->repos) { if (!$this->repos) {
@ -663,6 +666,9 @@ EOT
return $requires; return $requires;
} }
/**
* @return array<int, array{name: string, email: string}>
*/
protected function formatAuthors($author) protected function formatAuthors($author)
{ {
return array($this->parseAuthorString($author)); return array($this->parseAuthorString($author));
@ -775,6 +781,9 @@ EOT
file_put_contents($ignoreFile, $contents . $vendor. "\n"); file_put_contents($ignoreFile, $contents . $vendor. "\n");
} }
/**
* @return bool
*/
protected function isValidEmail($email) protected function isValidEmail($email)
{ {
// assume it's valid if we can't validate it // assume it's valid if we can't validate it
@ -790,6 +799,9 @@ EOT
return false !== filter_var($email, FILTER_VALIDATE_EMAIL); return false !== filter_var($email, FILTER_VALIDATE_EMAIL);
} }
/**
* @return RepositorySet
*/
private function getRepositorySet(InputInterface $input, $minimumStability = null) private function getRepositorySet(InputInterface $input, $minimumStability = null)
{ {
$key = $minimumStability ?: 'default'; $key = $minimumStability ?: 'default';
@ -802,6 +814,9 @@ EOT
return $this->repositorySets[$key]; return $this->repositorySets[$key];
} }
/**
* @return string
*/
private function getMinimumStability(InputInterface $input) private function getMinimumStability(InputInterface $input)
{ {
if ($input->hasOption('stability')) { if ($input->hasOption('stability')) {
@ -936,6 +951,9 @@ EOT
); );
} }
/**
* @return string
*/
private function getPlatformExceptionDetails(PackageInterface $candidate, PlatformRepository $platformRepo = null) private function getPlatformExceptionDetails(PackageInterface $candidate, PlatformRepository $platformRepo = null)
{ {
$details = array(); $details = array();
@ -993,6 +1011,9 @@ EOT
return array_keys(array_slice($similarPackages, 0, 5)); return array_keys(array_slice($similarPackages, 0, 5));
} }
/**
* @return void
*/
private function updateDependencies($output) private function updateDependencies($output)
{ {
try { try {
@ -1004,6 +1025,9 @@ EOT
} }
} }
/**
* @return void
*/
private function runDumpAutoloadCommand($output) private function runDumpAutoloadCommand($output)
{ {
try { try {
@ -1015,6 +1039,9 @@ EOT
} }
} }
/**
* @return bool
*/
private function hasDependencies($options) private function hasDependencies($options)
{ {
$requires = (array) $options['require']; $requires = (array) $options['require'];

View File

@ -417,6 +417,9 @@ EOT
return $status; return $status;
} }
/**
* @return bool
*/
private function updateFileCleanly($json, array $new, $requireKey, $removeKey, $sortPackages) private function updateFileCleanly($json, array $new, $requireKey, $removeKey, $sortPackages)
{ {
$contents = file_get_contents($json->getPath()); $contents = file_get_contents($json->getPath());

View File

@ -109,6 +109,9 @@ EOT
return $composer->getEventDispatcher()->dispatchScript($script, $devMode, $args); return $composer->getEventDispatcher()->dispatchScript($script, $devMode, $args);
} }
/**
* @return int
*/
protected function listScripts(OutputInterface $output) protected function listScripts(OutputInterface $output)
{ {
$scripts = $this->getComposer()->getPackage()->getScripts(); $scripts = $this->getComposer()->getPackage()->getScripts();

View File

@ -369,6 +369,9 @@ TAGSPUBKEY
$io->write('Public keys stored in '.$config->get('home')); $io->write('Public keys stored in '.$config->get('home'));
} }
/**
* @return int
*/
protected function rollback(OutputInterface $output, $rollbackDir, $localFilename) protected function rollback(OutputInterface $output, $rollbackDir, $localFilename)
{ {
$rollbackVersion = $this->getLastBackupVersion($rollbackDir); $rollbackVersion = $this->getLastBackupVersion($rollbackDir);
@ -464,6 +467,9 @@ TAGSPUBKEY
} }
} }
/**
* @return string|false
*/
protected function getLastBackupVersion($rollbackDir) protected function getLastBackupVersion($rollbackDir)
{ {
$finder = $this->getOldInstallationFinder($rollbackDir); $finder = $this->getOldInstallationFinder($rollbackDir);
@ -477,6 +483,9 @@ TAGSPUBKEY
return false; return false;
} }
/**
* @return Finder
*/
protected function getOldInstallationFinder($rollbackDir) protected function getOldInstallationFinder($rollbackDir)
{ {
return Finder::create() return Finder::create()

View File

@ -304,6 +304,9 @@ EOT
throw new \RuntimeException('Installation aborted.'); throw new \RuntimeException('Installation aborted.');
} }
/**
* @return Link
*/
private function appendConstraintToLink(Link $link, $constraint) private function appendConstraintToLink(Link $link, $constraint)
{ {
$parser = new VersionParser; $parser = new VersionParser;

View File

@ -1737,6 +1737,9 @@ EOF;
} }
} }
/**
* @return array<string, mixed[]>
*/
public function platformCheckProvider() public function platformCheckProvider()
{ {
$versionParser = new VersionParser(); $versionParser = new VersionParser();