1
0
Fork 0

Lots of typing improvements

pull/10152/head
Jordi Boggiano 2021-10-12 22:47:23 +02:00
parent 1e3f7cfcba
commit d1c8a4d1b4
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
46 changed files with 361 additions and 106 deletions

View File

@ -33,7 +33,7 @@ class ClassMapGenerator
/**
* Generate a class map file
*
* @param \Traversable|array<string> $dirs Directories or a single path to search in
* @param \Traversable<string>|array<string> $dirs Directories or a single path to search in
* @param string $file The name of the class map file
*/
public static function dump($dirs, $file)
@ -58,6 +58,8 @@ class ClassMapGenerator
*
* @throws \RuntimeException When the path is neither an existing file nor directory
* @return array A class map array
*
* @phpstan-param \Traversable<\SplFileInfo>|string|array<string> $path
*/
public static function createMap($path, $excluded = null, IOInterface $io = null, $namespace = null, $autoloadType = null, &$scannedFiles = array())
{

View File

@ -24,12 +24,19 @@ use Symfony\Component\Finder\Finder;
*/
class Cache
{
/** @var bool|null */
private static $cacheCollected = null;
/** @var IOInterface */
private $io;
/** @var string */
private $root;
/** @var bool */
private $enabled = true;
/** @var string */
private $allowlist;
/** @var Filesystem */
private $filesystem;
/** @var bool */
private $readOnly;
/**

View File

@ -203,7 +203,7 @@ class BaseDependencyCommand extends BaseCommand
/**
* @var PackageInterface $package
* @var Link $link
* @var array|bool $children
* @var mixed[]|bool $children
*/
list($package, $link, $children) = $result;

View File

@ -27,8 +27,11 @@ use Seld\PharUtils\Linter;
*/
class Compiler
{
/** @var string */
private $version;
/** @var string */
private $branchAliasVersion = '';
/** @var \DateTime */
private $versionDate;
/**
@ -313,7 +316,7 @@ EOF;
// add warning once the phar is older than 60 days
if (preg_match('{^[a-f0-9]+$}', $this->version)) {
$warningTime = $this->versionDate->format('U') + 60 * 86400;
$warningTime = ((int) $this->versionDate->format('U')) + 60 * 86400;
$stub .= "define('COMPOSER_DEV_WARNING_TIME', $warningTime);\n";
}

View File

@ -25,6 +25,7 @@ class Config
{
const RELATIVE_PATHS = 1;
/** @var array<string, mixed> */
public static $defaultConfig = array(
'process-timeout' => 300,
'use-include-path' => false,
@ -77,6 +78,7 @@ class Config
// bearer
);
/** @var array<string, mixed> */
public static $defaultRepositories = array(
'packagist.org' => array(
'type' => 'composer',
@ -84,14 +86,19 @@ class Config
),
);
/** @var array<string, mixed> */
private $config;
/** @var ?string */
private $baseDir;
/** @var array<int|string, mixed> */
private $repositories;
/** @var ConfigSourceInterface */
private $configSource;
/** @var ConfigSourceInterface */
private $authConfigSource;
/** @var bool */
private $useEnvironment;
/** @var array<string, true> */
private $warnedHosts = array();
/**

View File

@ -23,8 +23,11 @@ interface ConfigSourceInterface
/**
* Add a repository
*
* @param string $name Name
* @param array|false $config Configuration
* @param string $name Name
* @param mixed[]|false $config Configuration
* @param bool $append Whether the repo should be appended (true) or prepended (false)
*
* @return void
*/
public function addRepository($name, $config, $append = true);
@ -32,14 +35,18 @@ interface ConfigSourceInterface
* Remove a repository
*
* @param string $name
*
* @return void
*/
public function removeRepository($name);
/**
* Add a config setting
*
* @param string $name Name
* @param string|array $value Value
* @param string $name Name
* @param mixed $value Value
*
* @return void
*/
public function addConfigSetting($name, $value);
@ -47,6 +54,8 @@ interface ConfigSourceInterface
* Remove a config setting
*
* @param string $name
*
* @return void
*/
public function removeConfigSetting($name);
@ -55,6 +64,8 @@ interface ConfigSourceInterface
*
* @param string $name Name
* @param string $value Value
*
* @return void
*/
public function addProperty($name, $value);
@ -62,6 +73,8 @@ interface ConfigSourceInterface
* Remove a property
*
* @param string $name
*
* @return void
*/
public function removeProperty($name);
@ -71,6 +84,8 @@ interface ConfigSourceInterface
* @param string $type Type (require, require-dev, provide, suggest, replace, conflict)
* @param string $name Name
* @param string $value Value
*
* @return void
*/
public function addLink($type, $name, $value);
@ -79,6 +94,8 @@ interface ConfigSourceInterface
*
* @param string $type Type (require, require-dev, provide, suggest, replace, conflict)
* @param string $name Name
*
* @return void
*/
public function removeLink($type, $name);

View File

@ -13,13 +13,25 @@
namespace Composer\DependencyResolver;
use Composer\Package\PackageInterface;
use Composer\Semver\Constraint\Constraint;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
interface PolicyInterface
{
/**
* @param string $operator
* @return bool
*
* @phpstan-param Constraint::STR_OP_* $operator
*/
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator);
/**
* @param int[] $literals
* @param ?string $requiredPackage
* @return int[]
*/
public function selectPreferredPackages(Pool $pool, array $literals, $requiredPackage = null);
}

View File

@ -33,6 +33,7 @@ interface DownloaderInterface
/**
* This should do any network-related tasks to prepare for an upcoming install/update
*
* @param string $path download path
* @return PromiseInterface|null
*/
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null);

View File

@ -42,7 +42,7 @@ interface EventSubscriberInterface
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
* @return array<string, string|array{0: string, 1?: int}|array<array{0: string, 1?: int}>> The event names to listen to
*/
public static function getSubscribedEvents();
}

View File

@ -66,56 +66,68 @@ interface IOInterface extends LoggerInterface
/**
* Writes a message to the output.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
* @param string|string[] $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
*
* @return void
*/
public function write($messages, $newline = true, $verbosity = self::NORMAL);
/**
* Writes a message to the error output.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
* @param string|string[] $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
*
* @return void
*/
public function writeError($messages, $newline = true, $verbosity = self::NORMAL);
/**
* Writes a message to the output, without formatting it.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
* @param string|string[] $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
*
* @return void
*/
public function writeRaw($messages, $newline = true, $verbosity = self::NORMAL);
/**
* Writes a message to the error output, without formatting it.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
* @param string|string[] $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
*
* @return void
*/
public function writeErrorRaw($messages, $newline = true, $verbosity = self::NORMAL);
/**
* Overwrites a previous message to the output.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $size The size of line
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
* @param string|string[] $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $size The size of line
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
*
* @return void
*/
public function overwrite($messages, $newline = true, $size = null, $verbosity = self::NORMAL);
/**
* Overwrites a previous message to the error output.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $size The size of line
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
* @param string|string[] $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline or not
* @param int $size The size of line
* @param int $verbosity Verbosity level from the VERBOSITY_* constants
*
* @return void
*/
public function overwriteError($messages, $newline = true, $size = null, $verbosity = self::NORMAL);
@ -172,21 +184,21 @@ interface IOInterface extends LoggerInterface
* Asks the user to select a value.
*
* @param string $question The question to ask
* @param array $choices List of choices to pick from
* @param string[] $choices List of choices to pick from
* @param bool|string $default The default answer if the user enters nothing
* @param bool|int $attempts Max number of times to ask before giving up (false by default, which means infinite)
* @param string $errorMessage Message which will be shown if invalid value from choice list would be picked
* @param bool $multiselect Select more than one value separated by comma
*
* @throws \InvalidArgumentException
* @return int|string|array|bool The selected value or values (the key of the choices array)
* @return int|string|string[]|bool The selected value or values (the key of the choices array)
*/
public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false);
/**
* Get all authentication information entered.
*
* @return array The map of authentication data
* @return array<string, array{username: string, password: string}> The map of authentication data
*/
public function getAuthentications();
@ -204,16 +216,18 @@ interface IOInterface extends LoggerInterface
*
* @param string $repositoryName The unique name of repository
*
* @return array The 'username' and 'password'
* @return array{username: string|null, password: string|null}
*/
public function getAuthentication($repositoryName);
/**
* Set the authentication information for the repository.
*
* @param string $repositoryName The unique name of repository
* @param string $username The username
* @param string $password The password
* @param string $repositoryName The unique name of repository
* @param string $username The username
* @param ?string $password The password
*
* @return void
*/
public function setAuthentication($repositoryName, $username, $password = null);
@ -221,6 +235,8 @@ interface IOInterface extends LoggerInterface
* Loads authentications from a config instance
*
* @param Config $config
*
* @return void
*/
public function loadConfiguration(Config $config);
}

View File

@ -24,8 +24,21 @@ use Composer\Semver\VersionParser;
*/
class InstalledVersions
{
/**
* @var mixed[]|null
* @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
*/
private static $installed;
/**
* @var bool|null
*/
private static $canGetVendors;
/**
* @var array[]
* @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
*/
private static $installedByVendor = array();
/**

View File

@ -117,23 +117,41 @@ class Installer
*/
protected $autoloadGenerator;
/** @var bool */
protected $preferSource = false;
/** @var bool */
protected $preferDist = false;
/** @var bool */
protected $optimizeAutoloader = false;
/** @var bool */
protected $classMapAuthoritative = false;
/** @var bool */
protected $apcuAutoloader = false;
protected $apcuAutoloaderPrefix;
/** @var string|null */
protected $apcuAutoloaderPrefix = null;
/** @var bool */
protected $devMode = false;
/** @var bool */
protected $dryRun = false;
/** @var bool */
protected $verbose = false;
/** @var bool */
protected $update = false;
/** @var bool */
protected $install = true;
/** @var bool */
protected $dumpAutoloader = true;
/** @var bool */
protected $runScripts = true;
/** @var bool|string[] */
protected $ignorePlatformReqs = false;
/** @var bool */
protected $preferStable = false;
/** @var bool */
protected $preferLowest = false;
/** @var bool */
protected $writeLock;
/** @var bool */
protected $executeOperations = true;
/** @var bool */
@ -141,9 +159,10 @@ class Installer
/**
* Array of package names/globs flagged for update
*
* @var array|null
* @var string[]|null
*/
protected $updateAllowList = null;
/** @var Request::UPDATE_* */
protected $updateAllowTransitiveDependencies = Request::UPDATE_ONLY_LISTED;
/**

View File

@ -25,6 +25,8 @@ interface BinaryPresenceInterface
* Make sure binaries are installed for a given package.
*
* @param PackageInterface $package package instance
*
* @return void
*/
public function ensureBinariesPresence(PackageInterface $package);
}

View File

@ -20,11 +20,17 @@ use Composer\Package\Version\VersionParser;
*/
class AliasPackage extends BasePackage
{
/** @var string */
protected $version;
/** @var string */
protected $prettyVersion;
/** @var bool */
protected $dev;
/** @var bool */
protected $rootPackageAlias = false;
/** @var string */
protected $stability;
/** @var bool */
protected $hasSelfVersionRequires = false;
/** @var BasePackage */

View File

@ -17,6 +17,7 @@ use PharData;
class ArchivableFilesFilter extends FilterIterator
{
/** @var string[] */
private $dirs = array();
/**

View File

@ -22,10 +22,11 @@ interface ArchiverInterface
/**
* Create an archive from the sources.
*
* @param string $sources The sources directory
* @param string $target The target file
* @param string $format The format used for archive
* @param array $excludes A list of patterns for files to exclude
* @param string $sources The sources directory
* @param string $target The target file
* @param string $format The format used for archive
* @param string[] $excludes A list of patterns for files to exclude
* @param bool $ignoreFilters Whether to ignore filters when looking for files
*
* @return string The path to the written archive file
*/

View File

@ -25,7 +25,7 @@ abstract class BaseExcludeFilter
protected $sourcePath;
/**
* @var array
* @var array<array{0: string, 1: bool, 2: bool}> array of [$pattern, $negate, $stripLeadingSlash] arrays
*/
protected $excludePatterns;

View File

@ -19,6 +19,7 @@ namespace Composer\Package\Archiver;
*/
class PharArchiver implements ArchiverInterface
{
/** @var array<string, int> */
protected static $formats = array(
'zip' => \Phar::ZIP,
'tar' => \Phar::TAR,
@ -26,6 +27,7 @@ class PharArchiver implements ArchiverInterface
'tar.bz2' => \Phar::TAR,
);
/** @var array<string, int> */
protected static $compressFormats = array(
'tar.gz' => \Phar::GZ,
'tar.bz2' => \Phar::BZ2,

View File

@ -20,8 +20,9 @@ use Composer\Util\Filesystem;
*/
class ZipArchiver implements ArchiverInterface
{
/** @var array<string, bool> */
protected static $formats = array(
'zip' => 1,
'zip' => true,
);
/**

View File

@ -40,6 +40,7 @@ abstract class BasePackage implements PackageInterface
const STABILITY_ALPHA = 15;
const STABILITY_DEV = 20;
/** @var array<string, self::STABILITY_*> */
public static $stabilities = array(
'stable' => self::STABILITY_STABLE,
'RC' => self::STABILITY_RC,

View File

@ -19,8 +19,11 @@ namespace Composer\Package\Comparer;
*/
class Comparer
{
/** @var string Source directory */
private $source;
/** @var string Target directory */
private $update;
/** @var array{changed?: string[], removed?: string[], added?: string[]} */
private $changed;
public function setSource($source)

View File

@ -19,17 +19,29 @@ namespace Composer\Package;
*/
class CompletePackage extends Package implements CompletePackageInterface
{
/** @var mixed[] */
protected $repositories = array();
/** @var string[] */
protected $license = array();
/** @var string[] */
protected $keywords = array();
/** @var array<array{name?: string, homepage?: string, email?: string, role?: string}> */
protected $authors = array();
protected $description;
protected $homepage;
/** @var ?string */
protected $description = null;
/** @var ?string */
protected $homepage = null;
/** @var array<string, string[]> Map of script name to array of handlers */
protected $scripts = array();
/** @var array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} */
protected $support = array();
/** @var array<array{url?: string, type?: string}> */
protected $funding = array();
/** @var bool|string */
protected $abandoned = false;
protected $archiveName;
/** @var ?string */
protected $archiveName = null;
/** @var string[] */
protected $archiveExcludes = array();
/**

View File

@ -22,7 +22,7 @@ interface CompletePackageInterface extends PackageInterface
/**
* Returns the scripts of this package
*
* @return array<string, string[]> array('script name' => array('listeners'))
* @return array<string, string[]> Map of script name to array of handlers
*/
public function getScripts();
@ -35,14 +35,14 @@ interface CompletePackageInterface extends PackageInterface
/**
* Returns an array of repositories
*
* @return array<array{type: string, url?: string}> Repositories
* @return mixed[] Repositories
*/
public function getRepositories();
/**
* Set the repositories
*
* @param array<array{type: string, url?: string}> $repositories
* @param mixed[] $repositories
* @return void
*/
public function setRepositories(array $repositories);
@ -80,7 +80,7 @@ interface CompletePackageInterface extends PackageInterface
/**
* Returns the package description
*
* @return string
* @return ?string
*/
public function getDescription();
@ -95,7 +95,7 @@ interface CompletePackageInterface extends PackageInterface
/**
* Returns the package homepage
*
* @return string
* @return ?string
*/
public function getHomepage();
@ -127,14 +127,14 @@ interface CompletePackageInterface extends PackageInterface
/**
* Returns the support information
*
* @return array<string, string>
* @return array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string}
*/
public function getSupport();
/**
* Set the support information
*
* @param array<string, string> $support
* @param array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} $support
* @return void
*/
public function setSupport(array $support);
@ -144,14 +144,14 @@ interface CompletePackageInterface extends PackageInterface
*
* Each item will contain type and url keys
*
* @return array<array{type: string, url: string}>
* @return array<array{type?: string, url?: string}>
*/
public function getFunding();
/**
* Set the funding
*
* @param array<array{type: string, url: string}> $funding
* @param array<array{type?: string, url?: string}> $funding
* @return void
*/
public function setFunding(array $funding);
@ -179,7 +179,7 @@ interface CompletePackageInterface extends PackageInterface
/**
* Returns default base filename for archive
*
* @return array
* @return ?string
*/
public function getArchiveName();
@ -194,7 +194,7 @@ interface CompletePackageInterface extends PackageInterface
/**
* Returns a list of patterns to exclude from package archives
*
* @return array
* @return string[]
*/
public function getArchiveExcludes();

View File

@ -31,7 +31,9 @@ use Composer\Package\Version\VersionParser;
*/
class ArrayLoader implements LoaderInterface
{
/** @var VersionParser */
protected $versionParser;
/** @var bool */
protected $loadOptions;
public function __construct(VersionParser $parser = null, $loadOptions = false)

View File

@ -17,8 +17,11 @@ namespace Composer\Package\Loader;
*/
class InvalidPackageException extends \Exception
{
/** @var string[] */
private $errors;
/** @var string[] */
private $warnings;
/** @var mixed[] package config */
private $data;
public function __construct(array $errors, array $warnings, array $data)

View File

@ -21,6 +21,7 @@ use Composer\Package\CompleteAliasPackage;
*/
class JsonLoader
{
/** @var LoaderInterface */
private $loader;
public function __construct(LoaderInterface $loader)

View File

@ -12,6 +12,12 @@
namespace Composer\Package\Loader;
use Composer\Package\CompletePackageInterface;
use Composer\Package\CompletePackage;
use Composer\Package\CompleteAliasPackage;
use Composer\Package\RootAliasPackage;
use Composer\Package\RootPackage;
/**
* Defines a loader that takes an array to create package instances
*
@ -22,9 +28,14 @@ interface LoaderInterface
/**
* Converts a package from an array to a real instance
*
* @param array $package Package config
* @param string $class Package class to use
* @return \Composer\Package\PackageInterface
* @template PackageClass of CompletePackageInterface
*
* @param mixed[] $config package data
* @param string $class FQCN to be instantiated
*
* @return CompletePackage|CompleteAliasPackage|RootPackage|RootAliasPackage
*
* @phpstan-param class-string<PackageClass> $class
*/
public function load(array $package, $class = 'Composer\Package\CompletePackage');
public function load(array $config, $class = 'Composer\Package\CompletePackage');
}

View File

@ -59,10 +59,11 @@ class RootPackageLoader extends ArrayLoader
/**
* @template PackageClass of RootPackage
* @param array $config package data
* @param class-string<PackageClass> $class FQCN to be instantiated
*
* @param string $cwd cwd of the root package to be used to guess the version if it is not provided
* @return RootPackage|RootAliasPackage
*
* @phpstan-param class-string<PackageClass> $class
*/
public function load(array $config, $class = 'Composer\Package\RootPackage', $cwd = null)
{
@ -183,6 +184,9 @@ class RootPackageLoader extends ArrayLoader
return $package;
}
/**
* @return array<array{package: string, version: string, alias: string, alias_normalized: string}>
*/
private function extractAliases(array $requires, array $aliases)
{
foreach ($requires as $reqName => $reqVersion) {
@ -203,6 +207,7 @@ class RootPackageLoader extends ArrayLoader
/**
* @internal
* @return array<string, BasePackage::STABILITY_*>
*/
public static function extractStabilityFlags(array $requires, $minimumStability, array $stabilityFlags)
{
@ -259,6 +264,7 @@ class RootPackageLoader extends ArrayLoader
/**
* @internal
* @return array<string, string>
*/
public static function extractReferences(array $requires, array $references)
{

View File

@ -27,12 +27,19 @@ class ValidatingArrayLoader implements LoaderInterface
const CHECK_UNBOUND_CONSTRAINTS = 1;
const CHECK_STRICT_CONSTRAINTS = 2;
/** @var LoaderInterface */
private $loader;
/** @var VersionParser */
private $versionParser;
/** @var string[] */
private $errors;
/** @var string[] */
private $warnings;
/** @var mixed[] */
private $config;
/** @var bool */
private $strictName;
/** @var int One or more of self::CHECK_* constants */
private $flags;
public function __construct(LoaderInterface $loader, $strictName = true, VersionParser $parser = null, $flags = 0)
@ -388,7 +395,7 @@ class ValidatingArrayLoader implements LoaderInterface
}
$package = $this->loader->load($this->config, $class);
$this->config = null;
$this->config = array();
return $package;
}

View File

@ -46,8 +46,10 @@ class Locker
private $dumper;
/** @var ProcessExecutor */
private $process;
private $lockDataCache;
private $virtualFileWritten;
/** @var mixed[]|null */
private $lockDataCache = null;
/** @var bool */
private $virtualFileWritten = false;
/**
* Initializes packages locker.

View File

@ -34,7 +34,7 @@ class Package extends BasePackage
protected $sourceUrl;
/** @var ?string */
protected $sourceReference;
/** @var ?array */
/** @var ?array<int, array{url: string, preferred: bool}> */
protected $sourceMirrors;
/** @var ?string */
protected $distType;
@ -44,7 +44,7 @@ class Package extends BasePackage
protected $distReference;
/** @var ?string */
protected $distSha1Checksum;
/** @var ?array */
/** @var ?array<int, array{url: string, preferred: bool}> */
protected $distMirrors;
/** @var string */
protected $version;

View File

@ -55,6 +55,8 @@ interface PackageInterface
* Allows the solver to set an id for this package to refer to it.
*
* @param int $id
*
* @return void
*/
public function setId($id);
@ -98,6 +100,8 @@ interface PackageInterface
*
* @param string $type source/dist
* @phpstan-param 'source'|'dist'|null $type
*
* @return void
*/
public function setInstallationSource($type);
@ -140,12 +144,12 @@ interface PackageInterface
/**
* Returns the source mirrors of this package
*
* @return ?array
* @return ?array<int, array{url: string, preferred: bool}>
*/
public function getSourceMirrors();
/**
* @param ?array $mirrors
* @param ?array<int, array{url: string, preferred: bool}> $mirrors
* @return void
*/
public function setSourceMirrors($mirrors);
@ -188,12 +192,12 @@ interface PackageInterface
/**
* Returns the dist mirrors of this package
*
* @return ?array
* @return ?array<int, array{url: string, preferred: bool}>
*/
public function getDistMirrors();
/**
* @param ?array $mirrors
* @param ?array<int, array{url: string, preferred: bool}> $mirrors
* @return void
*/
public function setDistMirrors($mirrors);
@ -326,6 +330,8 @@ interface PackageInterface
* Stores a reference to the repository that owns the package
*
* @param RepositoryInterface $repository
*
* @return void
*/
public function setRepository(RepositoryInterface $repository);
@ -386,6 +392,8 @@ interface PackageInterface
/**
* Configures the list of options to download package dist files
*
* @param mixed[] $options
*
* @return void
*/
public function setTransportOptions(array $options);

View File

@ -21,11 +21,17 @@ class RootPackage extends CompletePackage implements RootPackageInterface
{
const DEFAULT_PRETTY_VERSION = '1.0.0+no-version-set';
/** @var string */
protected $minimumStability = 'stable';
/** @var bool */
protected $preferStable = false;
/** @var array<string, BasePackage::STABILITY_*> Map of package name to stability constant */
protected $stabilityFlags = array();
/** @var mixed[] */
protected $config = array();
/** @var array<string, string> Map of package name to reference/commit hash */
protected $references = array();
/** @var array<array{package: string, version: string, alias: string, alias_normalized: string}> */
protected $aliases = array();
/**

View File

@ -22,7 +22,7 @@ interface RootPackageInterface extends CompletePackageInterface
/**
* Returns a set of package names and their aliases
*
* @return array
* @return array<array{package: string, version: string, alias: string, alias_normalized: string}>
*/
public function getAliases();
@ -38,7 +38,7 @@ interface RootPackageInterface extends CompletePackageInterface
*
* array('foo/bar' => 'dev')
*
* @return array
* @return array<string, BasePackage::STABILITY_*>
*/
public function getStabilityFlags();
@ -47,7 +47,7 @@ interface RootPackageInterface extends CompletePackageInterface
*
* array('foo/bar' => 'abcd1234')
*
* @return array
* @return array<string, string>
*/
public function getReferences();
@ -61,7 +61,7 @@ interface RootPackageInterface extends CompletePackageInterface
/**
* Returns the root package's configuration
*
* @return array
* @return mixed[]
*/
public function getConfig();
@ -69,6 +69,8 @@ interface RootPackageInterface extends CompletePackageInterface
* Set the required packages
*
* @param Link[] $requires A set of package links
*
* @return void
*/
public function setRequires(array $requires);
@ -76,6 +78,8 @@ interface RootPackageInterface extends CompletePackageInterface
* Set the recommended packages
*
* @param Link[] $devRequires A set of package links
*
* @return void
*/
public function setDevRequires(array $devRequires);
@ -83,6 +87,8 @@ interface RootPackageInterface extends CompletePackageInterface
* Set the conflicting packages
*
* @param Link[] $conflicts A set of package links
*
* @return void
*/
public function setConflicts(array $conflicts);
@ -90,6 +96,8 @@ interface RootPackageInterface extends CompletePackageInterface
* Set the provided virtual packages
*
* @param Link[] $provides A set of package links
*
* @return void
*/
public function setProvides(array $provides);
@ -97,34 +105,44 @@ interface RootPackageInterface extends CompletePackageInterface
* Set the packages this one replaces
*
* @param Link[] $replaces A set of package links
*
* @return void
*/
public function setReplaces(array $replaces);
/**
* Set the repositories
*
* @param array $repositories
* @param mixed[] $repositories
*
* @return void
*/
public function setRepositories(array $repositories);
/**
* Set the autoload mapping
*
* @param array $autoload Mapping of autoloading rules
* @param array{psr-0?: array<string, string|string[]>, psr-4?: array<string, string|string[]>, classmap?: list<string>, files?: list<string>} $autoload Mapping of autoloading rules
*
* @return void
*/
public function setAutoload(array $autoload);
/**
* Set the dev autoload mapping
*
* @param array $devAutoload Mapping of dev autoloading rules
* @param array{psr-0?: array<string, string|string[]>, psr-4?: array<string, string|string[]>, classmap?: list<string>, files?: list<string>} $devAutoload Mapping of dev autoloading rules
*
* @return void
*/
public function setDevAutoload(array $devAutoload);
/**
* Set the stabilityFlags
*
* @param array $stabilityFlags
* @param array<string, BasePackage::STABILITY_*> $stabilityFlags
*
* @return void
*/
public function setStabilityFlags(array $stabilityFlags);
@ -132,6 +150,8 @@ interface RootPackageInterface extends CompletePackageInterface
* Set the minimumStability
*
* @param string $minimumStability
*
* @return void
*/
public function setMinimumStability($minimumStability);
@ -139,39 +159,51 @@ interface RootPackageInterface extends CompletePackageInterface
* Set the preferStable
*
* @param bool $preferStable
*
* @return void
*/
public function setPreferStable($preferStable);
/**
* Set the config
*
* @param array $config
* @param mixed[] $config
*
* @return void
*/
public function setConfig(array $config);
/**
* Set the references
*
* @param array $references
* @param array<string, string> $references
*
* @return void
*/
public function setReferences(array $references);
/**
* Set the aliases
*
* @param array $aliases
* @param array<array{package: string, version: string, alias: string, alias_normalized: string}> $aliases
*
* @return void
*/
public function setAliases(array $aliases);
/**
* Set the suggested packages
*
* @param array $suggests A set of package names/comments
* @param array<string, string> $suggests A set of package names/comments
*
* @return void
*/
public function setSuggests(array $suggests);
/**
* @param array $extra
* @param mixed[] $extra
*
* @return void
*/
public function setExtra(array $extra);
}

View File

@ -15,11 +15,13 @@ namespace Composer\Package\Version;
use Composer\Repository\PlatformRepository;
use Composer\Semver\VersionParser as SemverVersionParser;
use Composer\Semver\Semver;
use Composer\Semver\Constraint\ConstraintInterface;
class VersionParser extends SemverVersionParser
{
const DEFAULT_BRANCH_ALIAS = '9999999-dev';
/** @var array<string, ConstraintInterface> Constraint parsing cache */
private static $constraints = array();
/**

View File

@ -21,6 +21,7 @@ use Composer\Package\Dumper\ArrayDumper;
use Composer\Repository\RepositorySet;
use Composer\Repository\PlatformRepository;
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\Constraint\ConstraintInterface;
/**
* Selects the best possible version for a package
@ -30,10 +31,13 @@ use Composer\Semver\Constraint\Constraint;
*/
class VersionSelector
{
/** @var RepositorySet */
private $repositorySet;
/** @var array<string, ConstraintInterface[]> */
private $platformConstraints = array();
/** @var VersionParser */
private $parser;
/**

View File

@ -39,6 +39,8 @@ interface PluginInterface
*
* @param Composer $composer
* @param IOInterface $io
*
* @return void
*/
public function activate(Composer $composer, IOInterface $io);
@ -51,6 +53,8 @@ interface PluginInterface
*
* @param Composer $composer
* @param IOInterface $io
*
* @return void
*/
public function deactivate(Composer $composer, IOInterface $io);
@ -61,6 +65,8 @@ interface PluginInterface
*
* @param Composer $composer
* @param IOInterface $io
*
* @return void
*/
public function uninstall(Composer $composer, IOInterface $io);
}

View File

@ -91,9 +91,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
private $allowSslDowngrade = false;
/** @var ?EventDispatcher */
private $eventDispatcher;
/** @var ?array<string, array{url: string, preferred: bool}> */
/** @var ?array<string, array<int, array{url: string, preferred: bool}>> */
private $sourceMirrors;
/** @var ?array<string, array{url: string, preferred: bool}> */
/** @var ?array<int, array{url: string, preferred: bool}> */
private $distMirrors;
/** @var bool */
private $degradedMode = false;

View File

@ -19,5 +19,8 @@ namespace Composer\Repository;
*/
interface ConfigurableRepositoryInterface
{
/**
* @return mixed[]
*/
public function getRepoConfig();
}

View File

@ -47,8 +47,6 @@ class PerforceDriver extends VcsDriver
$this->perforce->writeP4ClientSpec();
$this->perforce->connectClient();
return true;
}
private function initPerforce($repoConfig)

View File

@ -22,14 +22,16 @@ interface VcsDriverInterface
{
/**
* Initializes the driver (git clone, svn checkout, fetch info etc)
*
* @return void
*/
public function initialize();
/**
* Return the composer.json file information
*
* @param string $identifier Any identifier to a specific branch/tag/commit
* @return array containing all infos from the composer.json file
* @param string $identifier Any identifier to a specific branch/tag/commit
* @return mixed[] containing all infos from the composer.json file
*/
public function getComposerInformation($identifier);
@ -60,26 +62,28 @@ interface VcsDriverInterface
/**
* Return list of branches in the repository
*
* @return array Branch names as keys, identifiers as values
* @return array<string, string> Branch names as keys, identifiers as values
*/
public function getBranches();
/**
* Return list of tags in the repository
*
* @return array Tag names as keys, identifiers as values
* @return array<string, string> Tag names as keys, identifiers as values
*/
public function getTags();
/**
* @param string $identifier Any identifier to a specific branch/tag/commit
* @return array|null With type, url reference and shasum keys.
* @param string $identifier Any identifier to a specific branch/tag/commit
*
* @return array{type: string, url: string, reference: string, shasum: string}|null
*/
public function getDist($identifier);
/**
* @param string $identifier Any identifier to a specific branch/tag/commit
* @return array With type, url and reference keys.
* @param string $identifier Any identifier to a specific branch/tag/commit
*
* @return array{type: string, url: string, reference: string}
*/
public function getSource($identifier);
@ -101,6 +105,8 @@ interface VcsDriverInterface
/**
* Performs any cleanup necessary as the driver is not longer needed
*
* @return void
*/
public function cleanup();

View File

@ -15,9 +15,9 @@ namespace Composer\Repository;
interface VersionCacheInterface
{
/**
* @param string $version
* @param string $identifier
* @return array|null|false Package version data if found, false to indicate the identifier is known but has no package, null for an unknown identifier
* @param string $version
* @param string $identifier
* @return mixed[]|null|false Package version data if found, false to indicate the identifier is known but has no package, null for an unknown identifier
*/
public function getVersionPackage($version, $identifier);
}

View File

@ -26,6 +26,7 @@ interface WritableRepositoryInterface extends RepositoryInterface
* Writes repository (f.e. to the disc).
*
* @param bool $devMode Whether dev requirements were included or not in this installation
* @return void
*/
public function write($devMode, InstallationManager $installationManager);
@ -33,6 +34,7 @@ interface WritableRepositoryInterface extends RepositoryInterface
* Adds package to the repository.
*
* @param PackageInterface $package package instance
* @return void
*/
public function addPackage(PackageInterface $package);
@ -40,6 +42,7 @@ interface WritableRepositoryInterface extends RepositoryInterface
* Removes package from the repository.
*
* @param PackageInterface $package package instance
* @return void
*/
public function removePackage(PackageInterface $package);
@ -52,11 +55,14 @@ interface WritableRepositoryInterface extends RepositoryInterface
/**
* Forces a reload of all packages.
*
* @return void
*/
public function reload();
/**
* @param string[] $devPackageNames
* @return void
*/
public function setDevPackageNames(array $devPackageNames);

View File

@ -120,8 +120,11 @@ class AuthHelper
$message = "\n".'Could not fetch '.$url.', enter your ' . $origin . ' credentials ' .($statusCode === 401 ? 'to access private repos' : 'to go over the API rate limit');
$gitLabUtil = new GitLab($this->io, $this->config, null);
if ($this->io->hasAuthentication($origin) && ($auth = $this->io->getAuthentication($origin)) && in_array($auth['password'], array('gitlab-ci-token', 'private-token', 'oauth2'), true)) {
throw new TransportException("Invalid credentials for '" . $url . "', aborting.", $statusCode);
if ($this->io->hasAuthentication($origin)) {
$auth = $this->io->getAuthentication($origin);
if (in_array($auth['password'], array('gitlab-ci-token', 'private-token', 'oauth2'), true)) {
throw new TransportException("Invalid credentials for '" . $url . "', aborting.", $statusCode);
}
}
if (!$gitLabUtil->authorizeOAuth($origin)

View File

@ -22,13 +22,20 @@ use Composer\Util\Url;
*/
class ProxyManager
{
private $error;
/** @var ?string */
private $error = null;
/** @var array{http: ?string, https: ?string} */
private $fullProxy;
/** @var array{http: ?string, https: ?string} */
private $safeProxy;
/** @var array{http: array{options: mixed[]|null}, https: array{options: mixed[]|null}} */
private $streams;
/** @var bool */
private $hasProxy;
private $info;
private $lastProxy;
/** @var ?string */
private $info = null;
/** @var ?string */
private $lastProxy = null;
/** @var ?NoProxyPattern */
private $noProxyHandler = null;
@ -154,7 +161,7 @@ class ProxyManager
* Sets initial data
*
* @param string $url Proxy url
* @param string $scheme Environment variable scheme
* @param 'http'|'https' $scheme Environment variable scheme
*/
private function setData($url, $scheme)
{

View File

@ -20,23 +20,39 @@ use Symfony\Component\Process\Process;
*/
class Perforce
{
/** @var string */
protected $path;
/** @var ?string */
protected $p4Depot;
/** @var string */
protected $p4Client;
/** @var ?string */
protected $p4User;
/** @var ?string */
protected $p4Password;
/** @var int */
protected $p4Port;
/** @var string */
protected $p4Stream;
/** @var string */
protected $p4ClientSpec;
/** @var ?string */
protected $p4DepotType;
/** @var ?string */
protected $p4Branch;
/** @var ProcessExecutor */
protected $process;
/** @var string */
protected $uniquePerforceClientName;
/** @var bool */
protected $windowsFlag;
/** @var string */
protected $commandResult;
/** @var IOInterface */
protected $io;
/** @var Filesystem */
protected $filesystem;
public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, IOInterface $io)