1
0
Fork 0

Final type additions

pull/10561/head
Jordi Boggiano 2022-02-23 12:54:07 +01:00
parent 14fcfc3ae1
commit 89ce53250e
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
27 changed files with 82 additions and 116 deletions

View File

@ -1095,11 +1095,6 @@ parameters:
count: 1 count: 1
path: ../src/Composer/Command/ShowCommand.php path: ../src/Composer/Command/ShowCommand.php
-
message: "#^Only booleans are allowed in &&, Composer\\\\Package\\\\PackageInterface\\|false\\|null given on the right side\\.$#"
count: 1
path: ../src/Composer/Command/ShowCommand.php
- -
message: "#^Only booleans are allowed in &&, Composer\\\\Package\\\\PackageInterface\\|null given on the left side\\.$#" message: "#^Only booleans are allowed in &&, Composer\\\\Package\\\\PackageInterface\\|null given on the left side\\.$#"
count: 1 count: 1
@ -3530,11 +3525,6 @@ parameters:
count: 1 count: 1
path: ../src/Composer/Package/Loader/ArrayLoader.php path: ../src/Composer/Package/Loader/ArrayLoader.php
-
message: "#^Method Composer\\\\Package\\\\Loader\\\\ArrayLoader\\:\\:createObject\\(\\) should return Composer\\\\Package\\\\CompletePackage but returns PackageClass of Composer\\\\Package\\\\CompletePackageInterface\\.$#"
count: 1
path: ../src/Composer/Package/Loader/ArrayLoader.php
- -
message: "#^Only booleans are allowed in &&, string\\|false given on the left side\\.$#" message: "#^Only booleans are allowed in &&, string\\|false given on the left side\\.$#"
count: 1 count: 1
@ -3616,12 +3606,12 @@ parameters:
path: ../src/Composer/Package/Loader/RootPackageLoader.php path: ../src/Composer/Package/Loader/RootPackageLoader.php
- -
message: "#^Parameter \\#2 \\$class \\(class\\-string\\<PackageClass of Composer\\\\Package\\\\RootPackage\\>\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\<Composer\\\\Package\\\\CompletePackageInterface\\>\\) of method Composer\\\\Package\\\\Loader\\\\ArrayLoader\\:\\:load\\(\\)$#" message: "#^Parameter \\#2 \\$class \\(class\\-string\\<Composer\\\\Package\\\\RootPackage\\>\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\<Composer\\\\Package\\\\CompletePackage\\>\\) of method Composer\\\\Package\\\\Loader\\\\ArrayLoader\\:\\:load\\(\\)$#"
count: 1 count: 1
path: ../src/Composer/Package/Loader/RootPackageLoader.php path: ../src/Composer/Package/Loader/RootPackageLoader.php
- -
message: "#^Parameter \\#2 \\$class \\(class\\-string\\<PackageClass of Composer\\\\Package\\\\RootPackage\\>\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\<Composer\\\\Package\\\\CompletePackageInterface\\>\\) of method Composer\\\\Package\\\\Loader\\\\LoaderInterface\\:\\:load\\(\\)$#" message: "#^Parameter \\#2 \\$class \\(class\\-string\\<Composer\\\\Package\\\\RootPackage\\>\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\<Composer\\\\Package\\\\CompletePackage\\>\\) of method Composer\\\\Package\\\\Loader\\\\LoaderInterface\\:\\:load\\(\\)$#"
count: 1 count: 1
path: ../src/Composer/Package/Loader/RootPackageLoader.php path: ../src/Composer/Package/Loader/RootPackageLoader.php
@ -4595,11 +4585,6 @@ parameters:
count: 10 count: 10
path: ../src/Composer/Repository/Vcs/GitBitbucketDriver.php path: ../src/Composer/Repository/Vcs/GitBitbucketDriver.php
-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 1
path: ../src/Composer/Repository/Vcs/GitBitbucketDriver.php
- -
message: "#^Property Composer\\\\Repository\\\\Vcs\\\\GitBitbucketDriver\\:\\:\\$branches \\(array\\<string, string\\>\\) does not accept array\\<int\\|string, mixed\\>\\.$#" message: "#^Property Composer\\\\Repository\\\\Vcs\\\\GitBitbucketDriver\\:\\:\\$branches \\(array\\<string, string\\>\\) does not accept array\\<int\\|string, mixed\\>\\.$#"
count: 1 count: 1
@ -4720,11 +4705,6 @@ parameters:
count: 1 count: 1
path: ../src/Composer/Repository/Vcs/GitHubDriver.php path: ../src/Composer/Repository/Vcs/GitHubDriver.php
-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 1
path: ../src/Composer/Repository/Vcs/GitHubDriver.php
- -
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#" message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 2 count: 2
@ -4797,7 +4777,7 @@ parameters:
- -
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 2 count: 1
path: ../src/Composer/Repository/Vcs/GitLabDriver.php path: ../src/Composer/Repository/Vcs/GitLabDriver.php
- -
@ -5020,11 +5000,6 @@ parameters:
count: 1 count: 1
path: ../src/Composer/Repository/VcsRepository.php path: ../src/Composer/Repository/VcsRepository.php
-
message: "#^Only booleans are allowed in a negated boolean, array given\\.$#"
count: 2
path: ../src/Composer/Repository/VcsRepository.php
- -
message: "#^Only booleans are allowed in a negated boolean, array\\<Composer\\\\Package\\\\BasePackage\\> given\\.$#" message: "#^Only booleans are allowed in a negated boolean, array\\<Composer\\\\Package\\\\BasePackage\\> given\\.$#"
count: 1 count: 1

View File

@ -1364,12 +1364,7 @@ INITIALIZER;
} }
} }
/** function composerRequire(string $fileIdentifier, string $file): void
* @param string $fileIdentifier
* @param string $file
* @return void
*/
function composerRequire(string $fileIdentifier, string $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -459,7 +459,7 @@ EOT
* @param string $author * @param string $author
* @return array{name: string, email: string|null} * @return array{name: string, email: string|null}
*/ */
private function parseAuthorString(string $author) private function parseAuthorString(string $author): array
{ {
if (Preg::isMatch('/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'"()]+)(?:\s+<(?P<email>.+?)>)?$/u', $author, $match)) { if (Preg::isMatch('/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'"()]+)(?:\s+<(?P<email>.+?)>)?$/u', $author, $match)) {
$hasEmail = isset($match['email']) && '' !== $match['email']; $hasEmail = isset($match['email']) && '' !== $match['email'];

View File

@ -294,7 +294,7 @@ EOT
if ( if (
$input->getOption('outdated') $input->getOption('outdated')
&& $input->getOption('strict') && $input->getOption('strict')
&& $latestPackage && null !== $latestPackage
&& $latestPackage->getFullPrettyVersion() !== $package->getFullPrettyVersion() && $latestPackage->getFullPrettyVersion() !== $package->getFullPrettyVersion()
&& (!$latestPackage instanceof CompletePackageInterface || !$latestPackage->isAbandoned()) && (!$latestPackage instanceof CompletePackageInterface || !$latestPackage->isAbandoned())
) { ) {
@ -415,7 +415,7 @@ EOT
foreach ($packages[$type] as $package) { foreach ($packages[$type] as $package) {
if (is_object($package)) { if (is_object($package)) {
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly, $platformReqFilter); $latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly, $platformReqFilter);
if ($latestPackage === false) { if ($latestPackage === null) {
continue; continue;
} }
@ -628,7 +628,7 @@ EOT
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return array{CompletePackageInterface|null, array<string, string>} * @return array{CompletePackageInterface|null, array<string, string>}
*/ */
protected function getPackage(InstalledRepository $installedRepo, RepositoryInterface $repos, string $name, $version = null) protected function getPackage(InstalledRepository $installedRepo, RepositoryInterface $repos, string $name, $version = null): array
{ {
$name = strtolower($name); $name = strtolower($name);
$constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version; $constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version;
@ -1287,10 +1287,8 @@ EOT
/** /**
* Given a package, this finds the latest package matching it * Given a package, this finds the latest package matching it
*
* @return PackageInterface|false
*/ */
private function findLatestPackage(PackageInterface $package, Composer $composer, PlatformRepository $platformRepo, bool $minorOnly, PlatformRequirementFilterInterface $platformReqFilter) private function findLatestPackage(PackageInterface $package, Composer $composer, PlatformRepository $platformRepo, bool $minorOnly, PlatformRequirementFilterInterface $platformReqFilter): ?PackageInterface
{ {
// find the latest version allowed in this repo set // find the latest version allowed in this repo set
$name = $package->getName(); $name = $package->getName();
@ -1320,7 +1318,7 @@ EOT
$candidate = $candidate->getAliasOf(); $candidate = $candidate->getAliasOf();
} }
return $candidate; return $candidate !== false ? $candidate : null;
} }
/** /**

View File

@ -288,7 +288,7 @@ class Decisions implements \Iterator, \Countable
return $str; return $str;
} }
public function __toString() public function __toString(): string
{ {
return $this->toString(); return $this->toString();
} }

View File

@ -268,7 +268,7 @@ class Pool implements \Countable
return $this->unacceptableFixedOrLockedPackages; return $this->unacceptableFixedOrLockedPackages;
} }
public function __toString() public function __toString(): string
{ {
$str = "Pool:\n"; $str = "Pool:\n";

View File

@ -78,7 +78,7 @@ abstract class Rule
*/ */
abstract public function getHash(); abstract public function getHash();
abstract public function __toString(); abstract public function __toString(): string;
/** /**
* @param Rule $rule * @param Rule $rule

View File

@ -195,7 +195,7 @@ class RuleSet implements \IteratorAggregate, \Countable
return $string; return $string;
} }
public function __toString() public function __toString(): string
{ {
return $this->getPrettyString(); return $this->getPrettyString();
} }

View File

@ -81,7 +81,7 @@ class EventDispatcher
* @param bool $runScripts * @param bool $runScripts
* @return $this * @return $this
*/ */
public function setRunScripts(bool $runScripts = true) public function setRunScripts(bool $runScripts = true): self
{ {
$this->runScripts = (bool) $runScripts; $this->runScripts = (bool) $runScripts;

View File

@ -21,6 +21,8 @@ use Composer\Semver\VersionParser;
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
* *
* To require its presence, you can require `composer-runtime-api ^2.0` * To require its presence, you can require `composer-runtime-api ^2.0`
*
* @final
*/ */
class InstalledVersions class InstalledVersions
{ {

View File

@ -1030,7 +1030,7 @@ class Installer
* @param Composer $composer * @param Composer $composer
* @return Installer * @return Installer
*/ */
public static function create(IOInterface $io, Composer $composer): Installer public static function create(IOInterface $io, Composer $composer): self
{ {
return new static( return new static(
$io, $io,
@ -1049,7 +1049,7 @@ class Installer
* @param RepositoryInterface $additionalFixedRepository * @param RepositoryInterface $additionalFixedRepository
* @return $this * @return $this
*/ */
public function setAdditionalFixedRepository(RepositoryInterface $additionalFixedRepository) public function setAdditionalFixedRepository(RepositoryInterface $additionalFixedRepository): self
{ {
$this->additionalFixedRepository = $additionalFixedRepository; $this->additionalFixedRepository = $additionalFixedRepository;
@ -1062,7 +1062,7 @@ class Installer
* @param bool $dryRun * @param bool $dryRun
* @return Installer * @return Installer
*/ */
public function setDryRun(bool $dryRun = true): Installer public function setDryRun(bool $dryRun = true): self
{ {
$this->dryRun = (bool) $dryRun; $this->dryRun = (bool) $dryRun;
@ -1085,7 +1085,7 @@ class Installer
* @param bool $preferSource * @param bool $preferSource
* @return Installer * @return Installer
*/ */
public function setPreferSource(bool $preferSource = true): Installer public function setPreferSource(bool $preferSource = true): self
{ {
$this->preferSource = (bool) $preferSource; $this->preferSource = (bool) $preferSource;
@ -1098,7 +1098,7 @@ class Installer
* @param bool $preferDist * @param bool $preferDist
* @return Installer * @return Installer
*/ */
public function setPreferDist(bool $preferDist = true): Installer public function setPreferDist(bool $preferDist = true): self
{ {
$this->preferDist = (bool) $preferDist; $this->preferDist = (bool) $preferDist;
@ -1111,7 +1111,7 @@ class Installer
* @param bool $optimizeAutoloader * @param bool $optimizeAutoloader
* @return Installer * @return Installer
*/ */
public function setOptimizeAutoloader(bool $optimizeAutoloader): Installer public function setOptimizeAutoloader(bool $optimizeAutoloader): self
{ {
$this->optimizeAutoloader = (bool) $optimizeAutoloader; $this->optimizeAutoloader = (bool) $optimizeAutoloader;
if (!$this->optimizeAutoloader) { if (!$this->optimizeAutoloader) {
@ -1130,7 +1130,7 @@ class Installer
* @param bool $classMapAuthoritative * @param bool $classMapAuthoritative
* @return Installer * @return Installer
*/ */
public function setClassMapAuthoritative(bool $classMapAuthoritative): Installer public function setClassMapAuthoritative(bool $classMapAuthoritative): self
{ {
$this->classMapAuthoritative = (bool) $classMapAuthoritative; $this->classMapAuthoritative = (bool) $classMapAuthoritative;
if ($this->classMapAuthoritative) { if ($this->classMapAuthoritative) {
@ -1148,7 +1148,7 @@ class Installer
* @param string|null $apcuAutoloaderPrefix * @param string|null $apcuAutoloaderPrefix
* @return Installer * @return Installer
*/ */
public function setApcuAutoloader(bool $apcuAutoloader, ?string $apcuAutoloaderPrefix = null): Installer public function setApcuAutoloader(bool $apcuAutoloader, ?string $apcuAutoloaderPrefix = null): self
{ {
$this->apcuAutoloader = $apcuAutoloader; $this->apcuAutoloader = $apcuAutoloader;
$this->apcuAutoloaderPrefix = $apcuAutoloaderPrefix; $this->apcuAutoloaderPrefix = $apcuAutoloaderPrefix;
@ -1162,7 +1162,7 @@ class Installer
* @param bool $update * @param bool $update
* @return Installer * @return Installer
*/ */
public function setUpdate(bool $update): Installer public function setUpdate(bool $update): self
{ {
$this->update = (bool) $update; $this->update = (bool) $update;
@ -1175,7 +1175,7 @@ class Installer
* @param bool $install * @param bool $install
* @return Installer * @return Installer
*/ */
public function setInstall(bool $install): Installer public function setInstall(bool $install): self
{ {
$this->install = (bool) $install; $this->install = (bool) $install;
@ -1188,7 +1188,7 @@ class Installer
* @param bool $devMode * @param bool $devMode
* @return Installer * @return Installer
*/ */
public function setDevMode(bool $devMode = true): Installer public function setDevMode(bool $devMode = true): self
{ {
$this->devMode = (bool) $devMode; $this->devMode = (bool) $devMode;
@ -1203,7 +1203,7 @@ class Installer
* @param bool $dumpAutoloader * @param bool $dumpAutoloader
* @return Installer * @return Installer
*/ */
public function setDumpAutoloader(bool $dumpAutoloader = true): Installer public function setDumpAutoloader(bool $dumpAutoloader = true): self
{ {
$this->dumpAutoloader = (bool) $dumpAutoloader; $this->dumpAutoloader = (bool) $dumpAutoloader;
@ -1219,7 +1219,7 @@ class Installer
* @return Installer * @return Installer
* @deprecated Use setRunScripts(false) on the EventDispatcher instance being injected instead * @deprecated Use setRunScripts(false) on the EventDispatcher instance being injected instead
*/ */
public function setRunScripts(bool $runScripts = true): Installer public function setRunScripts(bool $runScripts = true): self
{ {
$this->runScripts = (bool) $runScripts; $this->runScripts = (bool) $runScripts;
@ -1232,7 +1232,7 @@ class Installer
* @param Config $config * @param Config $config
* @return Installer * @return Installer
*/ */
public function setConfig(Config $config): Installer public function setConfig(Config $config): self
{ {
$this->config = $config; $this->config = $config;
@ -1245,7 +1245,7 @@ class Installer
* @param bool $verbose * @param bool $verbose
* @return Installer * @return Installer
*/ */
public function setVerbose(bool $verbose = true): Installer public function setVerbose(bool $verbose = true): self
{ {
$this->verbose = (bool) $verbose; $this->verbose = (bool) $verbose;
@ -1275,7 +1275,7 @@ class Installer
* *
* @deprecated use setPlatformRequirementFilter instead * @deprecated use setPlatformRequirementFilter instead
*/ */
public function setIgnorePlatformRequirements($ignorePlatformReqs): Installer public function setIgnorePlatformRequirements($ignorePlatformReqs): self
{ {
trigger_error('Installer::setIgnorePlatformRequirements is deprecated since Composer 2.2, use setPlatformRequirementFilter instead.', E_USER_DEPRECATED); trigger_error('Installer::setIgnorePlatformRequirements is deprecated since Composer 2.2, use setPlatformRequirementFilter instead.', E_USER_DEPRECATED);
@ -1286,7 +1286,7 @@ class Installer
* @param PlatformRequirementFilterInterface $platformRequirementFilter * @param PlatformRequirementFilterInterface $platformRequirementFilter
* @return Installer * @return Installer
*/ */
public function setPlatformRequirementFilter(PlatformRequirementFilterInterface $platformRequirementFilter): Installer public function setPlatformRequirementFilter(PlatformRequirementFilterInterface $platformRequirementFilter): self
{ {
$this->platformRequirementFilter = $platformRequirementFilter; $this->platformRequirementFilter = $platformRequirementFilter;
@ -1299,7 +1299,7 @@ class Installer
* @param bool $updateMirrors * @param bool $updateMirrors
* @return Installer * @return Installer
*/ */
public function setUpdateMirrors(bool $updateMirrors): Installer public function setUpdateMirrors(bool $updateMirrors): self
{ {
$this->updateMirrors = $updateMirrors; $this->updateMirrors = $updateMirrors;
@ -1314,7 +1314,7 @@ class Installer
* *
* @return Installer * @return Installer
*/ */
public function setUpdateAllowList(array $packages): Installer public function setUpdateAllowList(array $packages): self
{ {
$this->updateAllowList = array_flip(array_map('strtolower', $packages)); $this->updateAllowList = array_flip(array_map('strtolower', $packages));
@ -1330,7 +1330,7 @@ class Installer
* @param int $updateAllowTransitiveDependencies One of the UPDATE_ constants on the Request class * @param int $updateAllowTransitiveDependencies One of the UPDATE_ constants on the Request class
* @return Installer * @return Installer
*/ */
public function setUpdateAllowTransitiveDependencies(int $updateAllowTransitiveDependencies): Installer public function setUpdateAllowTransitiveDependencies(int $updateAllowTransitiveDependencies): self
{ {
if (!in_array($updateAllowTransitiveDependencies, array(Request::UPDATE_ONLY_LISTED, Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS_NO_ROOT_REQUIRE, Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS), true)) { if (!in_array($updateAllowTransitiveDependencies, array(Request::UPDATE_ONLY_LISTED, Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS_NO_ROOT_REQUIRE, Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS), true)) {
throw new \RuntimeException("Invalid value for updateAllowTransitiveDependencies supplied"); throw new \RuntimeException("Invalid value for updateAllowTransitiveDependencies supplied");
@ -1347,7 +1347,7 @@ class Installer
* @param bool $preferStable * @param bool $preferStable
* @return Installer * @return Installer
*/ */
public function setPreferStable(bool $preferStable = true): Installer public function setPreferStable(bool $preferStable = true): self
{ {
$this->preferStable = (bool) $preferStable; $this->preferStable = (bool) $preferStable;
@ -1360,7 +1360,7 @@ class Installer
* @param bool $preferLowest * @param bool $preferLowest
* @return Installer * @return Installer
*/ */
public function setPreferLowest(bool $preferLowest = true): Installer public function setPreferLowest(bool $preferLowest = true): self
{ {
$this->preferLowest = (bool) $preferLowest; $this->preferLowest = (bool) $preferLowest;
@ -1375,7 +1375,7 @@ class Installer
* @param bool $writeLock * @param bool $writeLock
* @return Installer * @return Installer
*/ */
public function setWriteLock(bool $writeLock = true): Installer public function setWriteLock(bool $writeLock = true): self
{ {
$this->writeLock = (bool) $writeLock; $this->writeLock = (bool) $writeLock;
@ -1390,7 +1390,7 @@ class Installer
* @param bool $executeOperations * @param bool $executeOperations
* @return Installer * @return Installer
*/ */
public function setExecuteOperations(bool $executeOperations = true): Installer public function setExecuteOperations(bool $executeOperations = true): self
{ {
$this->executeOperations = (bool) $executeOperations; $this->executeOperations = (bool) $executeOperations;
@ -1406,7 +1406,7 @@ class Installer
* *
* @return Installer * @return Installer
*/ */
public function disablePlugins(): Installer public function disablePlugins(): self
{ {
$this->installationManager->disablePlugins(); $this->installationManager->disablePlugins();
@ -1417,7 +1417,7 @@ class Installer
* @param SuggestedPackagesReporter $suggestedPackagesReporter * @param SuggestedPackagesReporter $suggestedPackagesReporter
* @return Installer * @return Installer
*/ */
public function setSuggestedPackagesReporter(SuggestedPackagesReporter $suggestedPackagesReporter): Installer public function setSuggestedPackagesReporter(SuggestedPackagesReporter $suggestedPackagesReporter): self
{ {
$this->suggestedPackagesReporter = $suggestedPackagesReporter; $this->suggestedPackagesReporter = $suggestedPackagesReporter;

View File

@ -68,7 +68,7 @@ class ArchiveManager
* *
* @return $this * @return $this
*/ */
public function setOverwriteFiles(bool $overwriteFiles) public function setOverwriteFiles(bool $overwriteFiles): self
{ {
$this->overwriteFiles = $overwriteFiles; $this->overwriteFiles = $overwriteFiles;

View File

@ -49,7 +49,7 @@ class ArrayLoader implements LoaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function load(array $config, $class = 'Composer\Package\CompletePackage') public function load(array $config, string $class = 'Composer\Package\CompletePackage'): BasePackage
{ {
if ($class !== 'Composer\Package\CompletePackage' && $class !== 'Composer\Package\RootPackage') { if ($class !== 'Composer\Package\CompletePackage' && $class !== 'Composer\Package\RootPackage') {
trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', E_USER_DEPRECATED); trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', E_USER_DEPRECATED);
@ -81,7 +81,7 @@ class ArrayLoader implements LoaderInterface
* *
* @return list<CompletePackage|CompleteAliasPackage> * @return list<CompletePackage|CompleteAliasPackage>
*/ */
public function loadPackages(array $versions) public function loadPackages(array $versions): array
{ {
$packages = array(); $packages = array();
$linkCache = array(); $linkCache = array();
@ -99,7 +99,7 @@ class ArrayLoader implements LoaderInterface
} }
/** /**
* @template PackageClass of CompletePackageInterface * @template PackageClass of CompletePackage
* *
* @param mixed[] $config package data * @param mixed[] $config package data
* @param string $class FQCN to be instantiated * @param string $class FQCN to be instantiated
@ -108,7 +108,7 @@ class ArrayLoader implements LoaderInterface
* *
* @phpstan-param class-string<PackageClass> $class * @phpstan-param class-string<PackageClass> $class
*/ */
private function createObject(array $config, string $class) private function createObject(array $config, string $class): CompletePackage
{ {
if (!isset($config['name'])) { if (!isset($config['name'])) {
throw new \UnexpectedValueException('Unknown package has no name defined ('.json_encode($config).').'); throw new \UnexpectedValueException('Unknown package has no name defined ('.json_encode($config).').');
@ -141,7 +141,7 @@ class ArrayLoader implements LoaderInterface
* *
* @return RootPackage|RootAliasPackage|CompletePackage|CompleteAliasPackage * @return RootPackage|RootAliasPackage|CompletePackage|CompleteAliasPackage
*/ */
private function configureObject(PackageInterface $package, array $config): PackageInterface private function configureObject(PackageInterface $package, array $config): BasePackage
{ {
if (!$package instanceof CompletePackage) { if (!$package instanceof CompletePackage) {
throw new \LogicException('ArrayLoader expects instances of the Composer\Package\CompletePackage class to function correctly'); throw new \LogicException('ArrayLoader expects instances of the Composer\Package\CompletePackage class to function correctly');

View File

@ -13,8 +13,11 @@
namespace Composer\Package\Loader; namespace Composer\Package\Loader;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\BasePackage;
use Composer\Package\CompletePackage; use Composer\Package\CompletePackage;
use Composer\Package\CompleteAliasPackage; use Composer\Package\CompleteAliasPackage;
use Composer\Package\RootPackage;
use Composer\Package\RootAliasPackage;
/** /**
* @author Konstantin Kudryashiv <ever.zet@gmail.com> * @author Konstantin Kudryashiv <ever.zet@gmail.com>
@ -31,9 +34,9 @@ class JsonLoader
/** /**
* @param string|JsonFile $json A filename, json string or JsonFile instance to load the package from * @param string|JsonFile $json A filename, json string or JsonFile instance to load the package from
* @return CompletePackage|CompleteAliasPackage * @return CompletePackage|CompleteAliasPackage|RootPackage|RootAliasPackage
*/ */
public function load($json) public function load($json): BasePackage
{ {
if ($json instanceof JsonFile) { if ($json instanceof JsonFile) {
$config = $json->read(); $config = $json->read();

View File

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

View File

@ -61,15 +61,13 @@ class RootPackageLoader extends ArrayLoader
/** /**
* @inheritDoc * @inheritDoc
* *
* @template PackageClass of RootPackage
*
* @param string|null $cwd * @param string|null $cwd
* *
* @return RootPackage|RootAliasPackage * @return RootPackage|RootAliasPackage
* *
* @phpstan-param class-string<PackageClass> $class * @phpstan-param class-string<RootPackage> $class
*/ */
public function load(array $config, $class = 'Composer\Package\RootPackage', ?string $cwd = null) public function load(array $config, string $class = 'Composer\Package\RootPackage', ?string $cwd = null): BasePackage
{ {
if ($class !== 'Composer\Package\RootPackage') { if ($class !== 'Composer\Package\RootPackage') {
trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', E_USER_DEPRECATED); trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', E_USER_DEPRECATED);

View File

@ -59,7 +59,7 @@ class ValidatingArrayLoader implements LoaderInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function load(array $config, $class = 'Composer\Package\CompletePackage') public function load(array $config, string $class = 'Composer\Package\CompletePackage'): BasePackage
{ {
$this->errors = array(); $this->errors = array();
$this->warnings = array(); $this->warnings = array();

View File

@ -97,7 +97,7 @@ class ArrayRepository implements RepositoryInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function findPackage($name, $constraint) public function findPackage(string $name, $constraint)
{ {
$name = strtolower($name); $name = strtolower($name);
@ -121,7 +121,7 @@ class ArrayRepository implements RepositoryInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function findPackages($name, $constraint = null) public function findPackages(string $name, $constraint = null)
{ {
// normalize name // normalize name
$name = strtolower($name); $name = strtolower($name);
@ -237,7 +237,7 @@ class ArrayRepository implements RepositoryInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getProviders($packageName) public function getProviders(string $packageName)
{ {
$result = array(); $result = array();

View File

@ -187,7 +187,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function findPackage($name, $constraint) public function findPackage(string $name, $constraint)
{ {
// this call initializes loadRootServerFile which is needed for the rest below to work // this call initializes loadRootServerFile which is needed for the rest below to work
$hasProviders = $this->hasProviders(); $hasProviders = $this->hasProviders();
@ -227,7 +227,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function findPackages($name, $constraint = null) public function findPackages(string $name, $constraint = null)
{ {
// this call initializes loadRootServerFile which is needed for the rest below to work // this call initializes loadRootServerFile which is needed for the rest below to work
$hasProviders = $this->hasProviders(); $hasProviders = $this->hasProviders();
@ -598,7 +598,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return parent::search($query, $mode); return parent::search($query, $mode);
} }
public function getProviders($packageName) public function getProviders(string $packageName)
{ {
$this->loadRootServerFile(); $this->loadRootServerFile();
$result = array(); $result = array();

View File

@ -116,7 +116,7 @@ class FilesystemRepository extends WritableArrayRepository
/** /**
* Writes writable repository. * Writes writable repository.
*/ */
public function write($devMode, InstallationManager $installationManager) public function write(bool $devMode, InstallationManager $installationManager)
{ {
$data = array('packages' => array(), 'dev' => $devMode, 'dev-package-names' => array()); $data = array('packages' => array(), 'dev' => $devMode, 'dev-package-names' => array());
$dumper = new ArrayDumper(); $dumper = new ArrayDumper();

View File

@ -436,7 +436,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
* *
* @return array{name: string|null, dist: array{type: string, url: string, reference: string, shasum: string}|null, source: array{type: string, url: string, reference: string}} * @return array{name: string|null, dist: array{type: string, url: string, reference: string, shasum: string}|null, source: array{type: string, url: string, reference: string}}
*/ */
protected function preProcess(VcsDriverInterface $driver, array $data, string $identifier) protected function preProcess(VcsDriverInterface $driver, array $data, string $identifier): array
{ {
// keep the name of the main identifier for all packages // keep the name of the main identifier for all packages
// this ensures that a package can be renamed in one place and that all old tags // this ensures that a package can be renamed in one place and that all old tags

View File

@ -57,7 +57,7 @@ class WritableArrayRepository extends ArrayRepository implements WritableReposit
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function write($devMode, InstallationManager $installationManager) public function write(bool $devMode, InstallationManager $installationManager)
{ {
$this->devMode = $devMode; $this->devMode = $devMode;
} }

View File

@ -40,7 +40,7 @@ class Event extends BaseEvent
private $devMode; private $devMode;
/** /**
* @var BaseEvent * @var BaseEvent|null
*/ */
private $originatingEvent; private $originatingEvent;
@ -97,7 +97,7 @@ class Event extends BaseEvent
* *
* @return ?BaseEvent * @return ?BaseEvent
*/ */
public function getOriginatingEvent() public function getOriginatingEvent(): ?BaseEvent
{ {
return $this->originatingEvent; return $this->originatingEvent;
} }
@ -108,7 +108,7 @@ class Event extends BaseEvent
* @param BaseEvent $event * @param BaseEvent $event
* @return $this * @return $this
*/ */
public function setOriginatingEvent(BaseEvent $event) public function setOriginatingEvent(BaseEvent $event): self
{ {
$this->originatingEvent = $this->calculateOriginatingEvent($event); $this->originatingEvent = $this->calculateOriginatingEvent($event);

View File

@ -422,7 +422,7 @@ class Git
/** /**
* @return non-empty-string * @return non-empty-string
*/ */
public static function getGitHubDomainsRegex(Config $config) public static function getGitHubDomainsRegex(Config $config): string
{ {
return '(' . implode('|', array_map('preg_quote', $config->get('github-domains'))) . ')'; return '(' . implode('|', array_map('preg_quote', $config->get('github-domains'))) . ')';
} }
@ -430,7 +430,7 @@ class Git
/** /**
* @return non-empty-string * @return non-empty-string
*/ */
public static function getGitLabDomainsRegex(Config $config) public static function getGitLabDomainsRegex(Config $config): string
{ {
return '(' . implode('|', array_map('preg_quote', $config->get('gitlab-domains'))) . ')'; return '(' . implode('|', array_map('preg_quote', $config->get('gitlab-domains'))) . ')';
} }

View File

@ -151,7 +151,7 @@ class Perforce
/** /**
* @return non-empty-string * @return non-empty-string
*/ */
public function generateUniquePerforceClientName() public function generateUniquePerforceClientName(): string
{ {
return gethostname() . "_" . time(); return gethostname() . "_" . time();
} }
@ -281,7 +281,7 @@ class Perforce
/** /**
* @return non-empty-string * @return non-empty-string
*/ */
public function getP4ClientSpec() public function getP4ClientSpec(): string
{ {
return $this->path . '/' . $this->getClient() . '.p4.spec'; return $this->path . '/' . $this->getClient() . '.p4.spec';
} }
@ -330,7 +330,7 @@ class Perforce
* @param string $name * @param string $name
* @return ?string * @return ?string
*/ */
protected function getP4variable(string $name) protected function getP4variable(string $name): ?string
{ {
if ($this->windowsFlag) { if ($this->windowsFlag) {
$command = 'p4 set'; $command = 'p4 set';
@ -385,7 +385,7 @@ class Perforce
* *
* @return non-empty-string * @return non-empty-string
*/ */
public function generateP4Command(string $command, bool $useClient = true) public function generateP4Command(string $command, bool $useClient = true): string
{ {
$p4Command = 'p4 '; $p4Command = 'p4 ';
$p4Command .= '-u ' . $this->getUser() . ' '; $p4Command .= '-u ' . $this->getUser() . ' ';
@ -614,7 +614,7 @@ class Perforce
/** /**
* @return array{master: string} * @return array{master: string}
*/ */
public function getBranches() public function getBranches(): array
{ {
$possibleBranches = array(); $possibleBranches = array();
if (!$this->isStream()) { if (!$this->isStream()) {

View File

@ -10,11 +10,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/** function includeIfExists(string $file): ?\Composer\Autoload\ClassLoader
* @param string $file
* @return ?\Composer\Autoload\ClassLoader
*/
function includeIfExists(string $file)
{ {
return file_exists($file) ? include $file : null; return file_exists($file) ? include $file : null;
} }

View File

@ -113,7 +113,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
} }
/** /**
* @template PackageClass of PackageInterface * @template PackageClass of CompletePackage|CompleteAliasPackage
* *
* @param string $class FQCN to be instantiated * @param string $class FQCN to be instantiated
* @param string $name * @param string $name
@ -124,7 +124,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
* @phpstan-param class-string<PackageClass> $class * @phpstan-param class-string<PackageClass> $class
* @phpstan-return PackageClass * @phpstan-return PackageClass
*/ */
protected function getPackage(string $name = 'dummy/pkg', string $version = '1.0.0', string $class = 'Composer\Package\CompletePackage') protected function getPackage(string $name = 'dummy/pkg', string $version = '1.0.0', string $class = 'Composer\Package\CompletePackage'): BasePackage
{ {
$normVersion = self::getVersionParser()->normalize($version); $normVersion = self::getVersionParser()->normalize($version);