1
0
Fork 0

Add types to root namespace (#10213)

pull/10215/head
Martin Herndl 2021-10-26 12:40:52 +02:00 committed by GitHub
parent f267b01852
commit 3645d3042c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 156 additions and 58 deletions

View File

@ -61,6 +61,8 @@ class Cache
/**
* @param bool $readOnly
*
* @return void
*/
public function setReadOnly($readOnly)
{
@ -76,6 +78,8 @@ class Cache
}
/**
* @param string $path
*
* @return bool
*/
public static function isUsable($path)
@ -112,6 +116,8 @@ class Cache
}
/**
* @param string $file
*
* @return string|false
*/
public function read($file)
@ -129,6 +135,9 @@ class Cache
}
/**
* @param string $file
* @param string $contents
*
* @return bool
*/
public function write($file, $contents)
@ -169,6 +178,10 @@ class Cache
/**
* Copy a file into the cache
*
* @param string $file
* @param string $source
*
* @return bool
*/
public function copyFrom($file, $source)
@ -191,6 +204,10 @@ class Cache
/**
* Copy a file out of the cache
*
* @param string $file
* @param string $target
*
* @return bool
*/
public function copyTo($file, $target)
@ -237,6 +254,8 @@ class Cache
}
/**
* @param string $file
*
* @return bool
*/
public function remove($file)
@ -266,6 +285,9 @@ class Cache
}
/**
* @param int $ttl
* @param int $maxSize
*
* @return bool
*/
public function gc($ttl, $maxSize)
@ -299,6 +321,8 @@ class Cache
}
/**
* @param string $file
*
* @return string|false
*/
public function sha1($file)
@ -314,6 +338,8 @@ class Cache
}
/**
* @param string $file
*
* @return string|false
*/
public function sha256($file)

View File

@ -37,7 +37,10 @@ class Compiler
/**
* Compiles composer into a single phar file
*
* @param string $pharFile The full path to the file to create
* @param string $pharFile The full path to the file to create
*
* @return void
*
* @throws \RuntimeException
*/
public function compile($pharFile = 'composer.phar')
@ -214,7 +217,12 @@ class Compiler
return strtr($relativePath, '\\', '/');
}
private function addFile($phar, $file, $strip = true)
/**
* @param bool $strip
*
* @return void
*/
private function addFile(\Phar $phar, \SplFileInfo $file, $strip = true)
{
$path = $this->getRelativeFilePath($file);
$content = file_get_contents($file);
@ -239,7 +247,10 @@ class Compiler
$phar->addFromString($path, $content);
}
private function addComposerBin($phar)
/**
* @return void
*/
private function addComposerBin(\Phar $phar)
{
$content = file_get_contents(__DIR__.'/../../bin/composer');
$content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);

View File

@ -141,7 +141,6 @@ class Composer
private $archiveManager;
/**
* @param RootPackageInterface $package
* @return void
*/
public function setPackage(RootPackageInterface $package)
@ -158,7 +157,7 @@ class Composer
}
/**
* @param Config $config
* @return void
*/
public function setConfig(Config $config)
{
@ -174,7 +173,7 @@ class Composer
}
/**
* @param Locker $locker
* @return void
*/
public function setLocker(Locker $locker)
{
@ -190,7 +189,7 @@ class Composer
}
/**
* @param Loop $loop
* @return void
*/
public function setLoop(Loop $loop)
{
@ -206,7 +205,7 @@ class Composer
}
/**
* @param RepositoryManager $manager
* @return void
*/
public function setRepositoryManager(RepositoryManager $manager)
{
@ -222,7 +221,7 @@ class Composer
}
/**
* @param DownloadManager $manager
* @return void
*/
public function setDownloadManager(DownloadManager $manager)
{
@ -238,7 +237,7 @@ class Composer
}
/**
* @param ArchiveManager $manager
* @return void
*/
public function setArchiveManager(ArchiveManager $manager)
{
@ -254,7 +253,7 @@ class Composer
}
/**
* @param InstallationManager $manager
* @return void
*/
public function setInstallationManager(InstallationManager $manager)
{
@ -270,7 +269,7 @@ class Composer
}
/**
* @param PluginManager $manager
* @return void
*/
public function setPluginManager(PluginManager $manager)
{
@ -286,7 +285,7 @@ class Composer
}
/**
* @param EventDispatcher $eventDispatcher
* @return void
*/
public function setEventDispatcher(EventDispatcher $eventDispatcher)
{
@ -302,7 +301,7 @@ class Composer
}
/**
* @param AutoloadGenerator $autoloadGenerator
* @return void
*/
public function setAutoloadGenerator(AutoloadGenerator $autoloadGenerator)
{

View File

@ -114,6 +114,9 @@ class Config
$this->baseDir = $baseDir;
}
/**
* @return void
*/
public function setConfigSource(ConfigSourceInterface $source)
{
$this->configSource = $source;
@ -127,6 +130,9 @@ class Config
return $this->configSource;
}
/**
* @return void
*/
public function setAuthConfigSource(ConfigSourceInterface $source)
{
$this->authConfigSource = $source;
@ -143,7 +149,9 @@ class Config
/**
* Merges new config values with the existing ones (overriding)
*
* @param array $config
* @param array<string, mixed> $config
*
* @return void
*/
public function merge($config)
{
@ -184,13 +192,13 @@ class Config
foreach ($newRepos as $name => $repository) {
// disable a repository by name
if (false === $repository) {
$this->disableRepoByName($name);
$this->disableRepoByName((string) $name);
continue;
}
// disable a repository with an anonymous {"name": false} repo
if (is_array($repository) && 1 === count($repository) && false === current($repository)) {
$this->disableRepoByName(key($repository));
$this->disableRepoByName((string) key($repository));
continue;
}
@ -215,7 +223,7 @@ class Config
}
/**
* @return array
* @return array<int|string, mixed>
*/
public function getRepositories()
{
@ -228,6 +236,7 @@ class Config
* @param string $key
* @param int $flags Options (see class constants)
* @throws \RuntimeException
*
* @return mixed
*/
public function get($key, $flags = 0)
@ -380,6 +389,8 @@ class Config
}
/**
* @param int $flags
*
* @return array<string, mixed[]>
*/
public function all($flags = 0)
@ -421,6 +432,7 @@ class Config
*
* @param string|int|null $value a config string that can contain {$refs-to-other-config}
* @param int $flags Options (see class constants)
*
* @return string|int|null
*/
private function process($value, $flags)
@ -471,6 +483,11 @@ class Config
return false;
}
/**
* @param string $name
*
* @return void
*/
private function disableRepoByName($name)
{
if (isset($this->repositories[$name])) {
@ -485,6 +502,8 @@ class Config
*
* @param string $url
* @param IOInterface $io
*
* @return void
*/
public function prohibitUrlByConfig($url, IOInterface $io = null)
{
@ -527,6 +546,8 @@ class Config
* "vendor/bin/long-running-script --watch"
* ]
* }
*
* @return void
*/
public static function disableProcessTimeout()
{

View File

@ -88,7 +88,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
if ($this->cache && $this->cache->gcIsNecessary()) {
$this->io->writeError('Running cache garbage collection', true, IOInterface::VERY_VERBOSE);
$this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
$this->cache->gc((int) $config->get('cache-files-ttl'), (int) $config->get('cache-files-maxsize'));
}
}

View File

@ -171,12 +171,13 @@ class Factory
}
/**
* @param IOInterface|null $io
* @param string|null $cwd
*
* @return Config
*/
public static function createConfig(IOInterface $io = null, $cwd = null)
{
$cwd = $cwd ?: getcwd();
$cwd = $cwd ?: (string) getcwd();
$config = new Config(true, $cwd);
@ -250,6 +251,8 @@ class Factory
}
/**
* @param string $composerFile
*
* @return string
*/
public static function getLockFile($composerFile)
@ -286,18 +289,19 @@ class Factory
/**
* Creates a Composer instance
*
* @param IOInterface $io IO instance
* @param array|string|null $localConfig either a configuration array or a filename to read from, if null it will
* read from the default filename
* @param bool $disablePlugins Whether plugins should not be loaded
* @param bool $fullLoad Whether to initialize everything or only main project stuff (used when loading the global composer)
* @param IOInterface $io IO instance
* @param array<string, mixed>|string|null $localConfig either a configuration array or a filename to read from, if null it will
* read from the default filename
* @param bool $disablePlugins Whether plugins should not be loaded
* @param string|null $cwd
* @param bool $fullLoad Whether to initialize everything or only main project stuff (used when loading the global composer)
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
* @return Composer
*/
public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false, $cwd = null, $fullLoad = true)
{
$cwd = $cwd ?: getcwd();
$cwd = $cwd ?: (string) getcwd();
// load Composer configuration
if (null === $localConfig) {
@ -465,6 +469,8 @@ class Factory
/**
* @param Repository\RepositoryManager $rm
* @param string $vendorDir
*
* @return void
*/
protected function addLocalRepository(IOInterface $io, RepositoryManager $rm, $vendorDir, RootPackageInterface $rootPackage, ProcessExecutor $process = null)
{
@ -477,7 +483,9 @@ class Factory
}
/**
* @param Config $config
* @param bool $disablePlugins
* @param bool $fullLoad
*
* @return Composer|null
*/
protected function createGlobalComposer(IOInterface $io, Config $config, $disablePlugins, $fullLoad = false)
@ -578,9 +586,7 @@ class Factory
}
/**
* @param Installer\InstallationManager $im
* @param Composer $composer
* @param IO\IOInterface $io
* @return void
*/
protected function createDefaultInstallers(Installer\InstallationManager $im, Composer $composer, IOInterface $io, ProcessExecutor $process = null)
{
@ -594,7 +600,9 @@ class Factory
/**
* @param InstalledRepositoryInterface $repo repository to purge packages from
* @param Installer\InstallationManager $im manager to check whether packages are still installed
* @param Installer\InstallationManager $im manager to check whether packages are still installed
*
* @return void
*/
protected function purgePackages(InstalledRepositoryInterface $repo, Installer\InstallationManager $im)
{
@ -632,7 +640,7 @@ class Factory
*
* @param IOInterface $io IO instance
* @param Config $config Config instance
* @param array $options Array of options passed directly to HttpDownloader constructor
* @param mixed[] $options Array of options passed directly to HttpDownloader constructor
* @return HttpDownloader
*/
public static function createHttpDownloader(IOInterface $io, Config $config, $options = array())

View File

@ -372,6 +372,11 @@ class Installer
return 0;
}
/**
* @param bool $doInstall
*
* @return int
*/
protected function doUpdate(InstalledRepositoryInterface $localRepo, $doInstall)
{
$platformRepo = $this->createPlatformRepo(true);
@ -573,6 +578,13 @@ class Installer
/**
* Run the solver a second time on top of the existing update result with only the current result set in the pool
* and see what packages would get removed if we only had the non-dev packages in the solver request
*
* @param array<int, array<string, string>> $aliases
*
* @return int
*
* @phpstan-param list<array{package: string, version: string, alias: string, alias_normalized: string}> $aliases
* @phpstan-return self::ERROR_*
*/
protected function extractDevPackages(LockTransaction $lockTransaction, PlatformRepository $platformRepo, array $aliases, PolicyInterface $policy, LockArrayRepository $lockedRepository = null)
{
@ -740,6 +752,11 @@ class Installer
return 0;
}
/**
* @param bool $forUpdate
*
* @return PlatformRepository
*/
protected function createPlatformRepo($forUpdate)
{
if ($forUpdate) {
@ -752,11 +769,13 @@ class Installer
}
/**
* @param bool $forUpdate
* @param PlatformRepository $platformRepo
* @param array $rootAliases
* @param RepositoryInterface|null $lockedRepository
* @param bool $forUpdate
* @param array<int, array<string, string>> $rootAliases
* @param RepositoryInterface|null $lockedRepository
*
* @return RepositorySet
*
* @phpstan-param list<array{package: string, version: string, alias: string, alias_normalized: string}> $rootAliases
*/
private function createRepositorySet($forUpdate, PlatformRepository $platformRepo, array $rootAliases = array(), $lockedRepository = null)
{
@ -822,6 +841,8 @@ class Installer
}
/**
* @param bool $forUpdate
*
* @return DefaultPolicy
*/
private function createPolicy($forUpdate)
@ -879,6 +900,12 @@ class Installer
return $request;
}
/**
* @param LockArrayRepository|null $lockedRepository
* @param bool $includeDevRequires
*
* @return void
*/
private function requirePackagesForUpdate(Request $request, LockArrayRepository $lockedRepository = null, $includeDevRequires = true)
{
// if we're updating mirrors we want to keep exactly the same versions installed which are in the lock file, but we want current remote metadata
@ -907,8 +934,11 @@ class Installer
}
/**
* @param bool $forUpdate
* @return array
* @param bool $forUpdate
*
* @return array<int, array<string, string>>
*
* @phpstan-return list<array{package: string, version: string, alias: string, alias_normalized: string}>
*/
private function getRootAliases($forUpdate)
{
@ -922,8 +952,9 @@ class Installer
}
/**
* @param array $links
* @return array
* @param Link[] $links
*
* @return array<string, string>
*/
private function extractPlatformRequirements(array $links)
{
@ -942,7 +973,7 @@ class Installer
*
* This is to prevent any accidental modification of the existing repos on disk
*
* @param RepositoryManager $rm
* @return void
*/
private function mockLocalRepositories(RepositoryManager $rm)
{
@ -1208,7 +1239,8 @@ class Installer
* If this is set to false, no platform requirements are ignored
* If this is set to string[], those packages will be ignored
*
* @param bool|array $ignorePlatformReqs
* @param bool|string[] $ignorePlatformReqs
*
* @return Installer
*/
public function setIgnorePlatformRequirements($ignorePlatformReqs)
@ -1241,7 +1273,8 @@ class Installer
* restrict the update operation to a few packages, all other packages
* that are already installed will be kept at their current version
*
* @param array $packages
* @param string[] $packages
*
* @return Installer
*/
public function setUpdateAllowList(array $packages)

View File

@ -308,7 +308,7 @@ class Locker
/**
* @return string[][]
*
* @phpstan-return list<array<string, string>>
* @phpstan-return list<array{package: string, version: string, alias: string, alias_normalized: string}>
*/
public function getAliases()
{
@ -350,7 +350,7 @@ class Locker
*
* @return bool
*
* @phpstan-param list<array<string, string>> $aliases
* @phpstan-param list<array{package: string, version: string, alias: string, alias_normalized: string}> $aliases
*/
public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags, $preferStable, $preferLowest, array $platformOverrides, $write = true)
{

View File

@ -1132,8 +1132,8 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
if (isset($data['includes'])) {
foreach ($data['includes'] as $include => $metadata) {
if (isset($metadata['sha1']) && $this->cache->sha1($include) === $metadata['sha1']) {
$includedData = json_decode($this->cache->read($include), true);
if (isset($metadata['sha1']) && $this->cache->sha1((string) $include) === $metadata['sha1']) {
$includedData = json_decode($this->cache->read((string) $include), true);
} else {
$includedData = $this->fetchFile($include);
}
@ -1215,7 +1215,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
}
$response = $this->httpDownloader->get($filename, $options);
$json = $response->getBody();
$json = (string) $response->getBody();
if ($sha256 && $sha256 !== hash('sha256', $json)) {
// undo downgrade before trying again if http seems to be hijacked or modifying content somehow
if ($this->allowSslDowngrade) {
@ -1247,7 +1247,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$lastModifiedDate = $response->getHeader('last-modified');
if ($lastModifiedDate) {
$data['last-modified'] = $lastModifiedDate;
$json = json_encode($data);
$json = JsonFile::encode($data, 0);
}
}
$this->cache->write($cacheKey, $json);
@ -1329,7 +1329,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
}
$options['http']['header'][] = 'If-Modified-Since: '.$lastModifiedTime;
$response = $this->httpDownloader->get($filename, $options);
$json = $response->getBody();
$json = (string) $response->getBody();
if ($json === '' && $response->getStatusCode() === 304) {
return true;
}
@ -1346,7 +1346,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$response->collect();
if ($lastModifiedDate) {
$data['last-modified'] = $lastModifiedDate;
$json = json_encode($data);
$json = JsonFile::encode($data, 0);
}
if (!$this->cache->isReadOnly()) {
$this->cache->write($cacheKey, $json);
@ -1431,7 +1431,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return array('packages' => array());
}
$json = $response->getBody();
$json = (string) $response->getBody();
if ($json === '' && $response->getStatusCode() === 304) {
$repo->freshMetadataUrls[$filename] = true;

View File

@ -50,7 +50,7 @@ class FossilDriver extends VcsDriver
if (Filesystem::isLocalPath($this->url) && is_dir($this->url)) {
$this->checkoutDir = $this->url;
} else {
if (!Cache::isUsable($this->config->get('cache-repo-dir')) || !Cache::isUsable($this->config->get('cache-vcs-dir'))) {
if (!Cache::isUsable((string) $this->config->get('cache-repo-dir')) || !Cache::isUsable((string) $this->config->get('cache-vcs-dir'))) {
throw new \RuntimeException('FossilDriver requires a usable cache directory, and it looks like you set it to be disabled');
}

View File

@ -47,7 +47,7 @@ class GitDriver extends VcsDriver
$this->repoDir = $this->url;
$cacheUrl = realpath($this->url);
} else {
if (!Cache::isUsable($this->config->get('cache-vcs-dir'))) {
if (!Cache::isUsable((string) $this->config->get('cache-vcs-dir'))) {
throw new \RuntimeException('GitDriver requires a usable cache directory, and it looks like you set it to be disabled');
}

View File

@ -41,7 +41,7 @@ class HgDriver extends VcsDriver
if (Filesystem::isLocalPath($this->url)) {
$this->repoDir = $this->url;
} else {
if (!Cache::isUsable($this->config->get('cache-vcs-dir'))) {
if (!Cache::isUsable((string) $this->config->get('cache-vcs-dir'))) {
throw new \RuntimeException('HgDriver requires a usable cache directory, and it looks like you set it to be disabled');
}

View File

@ -60,7 +60,7 @@ class PerforceDriver extends VcsDriver
return;
}
if (!Cache::isUsable($this->config->get('cache-vcs-dir'))) {
if (!Cache::isUsable((string) $this->config->get('cache-vcs-dir'))) {
throw new \RuntimeException('PerforceDriver requires a usable cache directory, and it looks like you set it to be disabled');
}

View File

@ -96,7 +96,7 @@ abstract class VcsDriver implements VcsDriverInterface
$composer = $this->getBaseComposerInformation($identifier);
if ($this->shouldCache($identifier)) {
$this->cache->write($identifier, json_encode($composer));
$this->cache->write($identifier, JsonFile::encode($composer, 0));
}
$this->infoCache[$identifier] = $composer;