diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 763f33219..8508c981f 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -1095,11 +1095,6 @@ parameters: count: 1 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\\.$#" count: 1 @@ -3530,11 +3525,6 @@ parameters: count: 1 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\\.$#" count: 1 @@ -3616,12 +3606,12 @@ parameters: path: ../src/Composer/Package/Loader/RootPackageLoader.php - - message: "#^Parameter \\#2 \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\ArrayLoader\\:\\:load\\(\\)$#" + message: "#^Parameter \\#2 \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\ArrayLoader\\:\\:load\\(\\)$#" count: 1 path: ../src/Composer/Package/Loader/RootPackageLoader.php - - message: "#^Parameter \\#2 \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\LoaderInterface\\:\\:load\\(\\)$#" + message: "#^Parameter \\#2 \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\RootPackageLoader\\:\\:load\\(\\) should be contravariant with parameter \\$class \\(class\\-string\\\\) of method Composer\\\\Package\\\\Loader\\\\LoaderInterface\\:\\:load\\(\\)$#" count: 1 path: ../src/Composer/Package/Loader/RootPackageLoader.php @@ -4595,11 +4585,6 @@ parameters: count: 10 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\\\\) does not accept array\\\\.$#" count: 1 @@ -4720,11 +4705,6 @@ parameters: count: 1 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\\.$#" count: 2 @@ -4797,7 +4777,7 @@ parameters: - message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" - count: 2 + count: 1 path: ../src/Composer/Repository/Vcs/GitLabDriver.php - @@ -5020,11 +5000,6 @@ parameters: count: 1 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\\ given\\.$#" count: 1 diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 825dc17bc..5485565e0 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -1364,12 +1364,7 @@ INITIALIZER; } } -/** - * @param string $fileIdentifier - * @param string $file - * @return void - */ -function composerRequire(string $fileIdentifier, string $file) +function composerRequire(string $fileIdentifier, string $file): void { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 4f3cebbd8..1d4dea29b 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -459,7 +459,7 @@ EOT * @param string $author * @return array{name: string, email: string|null} */ - private function parseAuthorString(string $author) + private function parseAuthorString(string $author): array { if (Preg::isMatch('/^(?P[- .,\p{L}\p{N}\p{Mn}\'’"()]+)(?:\s+<(?P.+?)>)?$/u', $author, $match)) { $hasEmail = isset($match['email']) && '' !== $match['email']; diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 775d858e9..8b11a8e33 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -294,7 +294,7 @@ EOT if ( $input->getOption('outdated') && $input->getOption('strict') - && $latestPackage + && null !== $latestPackage && $latestPackage->getFullPrettyVersion() !== $package->getFullPrettyVersion() && (!$latestPackage instanceof CompletePackageInterface || !$latestPackage->isAbandoned()) ) { @@ -415,7 +415,7 @@ EOT foreach ($packages[$type] as $package) { if (is_object($package)) { $latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly, $platformReqFilter); - if ($latestPackage === false) { + if ($latestPackage === null) { continue; } @@ -628,7 +628,7 @@ EOT * @throws \InvalidArgumentException * @return array{CompletePackageInterface|null, array} */ - 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); $constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version; @@ -1287,10 +1287,8 @@ EOT /** * 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 $name = $package->getName(); @@ -1320,7 +1318,7 @@ EOT $candidate = $candidate->getAliasOf(); } - return $candidate; + return $candidate !== false ? $candidate : null; } /** diff --git a/src/Composer/DependencyResolver/Decisions.php b/src/Composer/DependencyResolver/Decisions.php index 837488681..f9e349024 100644 --- a/src/Composer/DependencyResolver/Decisions.php +++ b/src/Composer/DependencyResolver/Decisions.php @@ -288,7 +288,7 @@ class Decisions implements \Iterator, \Countable return $str; } - public function __toString() + public function __toString(): string { return $this->toString(); } diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index 94c895c28..1abbc6382 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -268,7 +268,7 @@ class Pool implements \Countable return $this->unacceptableFixedOrLockedPackages; } - public function __toString() + public function __toString(): string { $str = "Pool:\n"; diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index c1cc491d2..bcf32fb03 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -78,7 +78,7 @@ abstract class Rule */ abstract public function getHash(); - abstract public function __toString(); + abstract public function __toString(): string; /** * @param Rule $rule diff --git a/src/Composer/DependencyResolver/RuleSet.php b/src/Composer/DependencyResolver/RuleSet.php index 9fe82e24e..d430b46a9 100644 --- a/src/Composer/DependencyResolver/RuleSet.php +++ b/src/Composer/DependencyResolver/RuleSet.php @@ -195,7 +195,7 @@ class RuleSet implements \IteratorAggregate, \Countable return $string; } - public function __toString() + public function __toString(): string { return $this->getPrettyString(); } diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index 941fc2520..d0cd437bd 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -81,7 +81,7 @@ class EventDispatcher * @param bool $runScripts * @return $this */ - public function setRunScripts(bool $runScripts = true) + public function setRunScripts(bool $runScripts = true): self { $this->runScripts = (bool) $runScripts; diff --git a/src/Composer/InstalledVersions.php b/src/Composer/InstalledVersions.php index d50e0c9fc..41bc143c1 100644 --- a/src/Composer/InstalledVersions.php +++ b/src/Composer/InstalledVersions.php @@ -21,6 +21,8 @@ use Composer\Semver\VersionParser; * See also https://getcomposer.org/doc/07-runtime.md#installed-versions * * To require its presence, you can require `composer-runtime-api ^2.0` + * + * @final */ class InstalledVersions { diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index fd3cb1417..d72525b33 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -1030,7 +1030,7 @@ class Installer * @param Composer $composer * @return Installer */ - public static function create(IOInterface $io, Composer $composer): Installer + public static function create(IOInterface $io, Composer $composer): self { return new static( $io, @@ -1049,7 +1049,7 @@ class Installer * @param RepositoryInterface $additionalFixedRepository * @return $this */ - public function setAdditionalFixedRepository(RepositoryInterface $additionalFixedRepository) + public function setAdditionalFixedRepository(RepositoryInterface $additionalFixedRepository): self { $this->additionalFixedRepository = $additionalFixedRepository; @@ -1062,7 +1062,7 @@ class Installer * @param bool $dryRun * @return Installer */ - public function setDryRun(bool $dryRun = true): Installer + public function setDryRun(bool $dryRun = true): self { $this->dryRun = (bool) $dryRun; @@ -1085,7 +1085,7 @@ class Installer * @param bool $preferSource * @return Installer */ - public function setPreferSource(bool $preferSource = true): Installer + public function setPreferSource(bool $preferSource = true): self { $this->preferSource = (bool) $preferSource; @@ -1098,7 +1098,7 @@ class Installer * @param bool $preferDist * @return Installer */ - public function setPreferDist(bool $preferDist = true): Installer + public function setPreferDist(bool $preferDist = true): self { $this->preferDist = (bool) $preferDist; @@ -1111,7 +1111,7 @@ class Installer * @param bool $optimizeAutoloader * @return Installer */ - public function setOptimizeAutoloader(bool $optimizeAutoloader): Installer + public function setOptimizeAutoloader(bool $optimizeAutoloader): self { $this->optimizeAutoloader = (bool) $optimizeAutoloader; if (!$this->optimizeAutoloader) { @@ -1130,7 +1130,7 @@ class Installer * @param bool $classMapAuthoritative * @return Installer */ - public function setClassMapAuthoritative(bool $classMapAuthoritative): Installer + public function setClassMapAuthoritative(bool $classMapAuthoritative): self { $this->classMapAuthoritative = (bool) $classMapAuthoritative; if ($this->classMapAuthoritative) { @@ -1148,7 +1148,7 @@ class Installer * @param string|null $apcuAutoloaderPrefix * @return Installer */ - public function setApcuAutoloader(bool $apcuAutoloader, ?string $apcuAutoloaderPrefix = null): Installer + public function setApcuAutoloader(bool $apcuAutoloader, ?string $apcuAutoloaderPrefix = null): self { $this->apcuAutoloader = $apcuAutoloader; $this->apcuAutoloaderPrefix = $apcuAutoloaderPrefix; @@ -1162,7 +1162,7 @@ class Installer * @param bool $update * @return Installer */ - public function setUpdate(bool $update): Installer + public function setUpdate(bool $update): self { $this->update = (bool) $update; @@ -1175,7 +1175,7 @@ class Installer * @param bool $install * @return Installer */ - public function setInstall(bool $install): Installer + public function setInstall(bool $install): self { $this->install = (bool) $install; @@ -1188,7 +1188,7 @@ class Installer * @param bool $devMode * @return Installer */ - public function setDevMode(bool $devMode = true): Installer + public function setDevMode(bool $devMode = true): self { $this->devMode = (bool) $devMode; @@ -1203,7 +1203,7 @@ class Installer * @param bool $dumpAutoloader * @return Installer */ - public function setDumpAutoloader(bool $dumpAutoloader = true): Installer + public function setDumpAutoloader(bool $dumpAutoloader = true): self { $this->dumpAutoloader = (bool) $dumpAutoloader; @@ -1219,7 +1219,7 @@ class Installer * @return Installer * @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; @@ -1232,7 +1232,7 @@ class Installer * @param Config $config * @return Installer */ - public function setConfig(Config $config): Installer + public function setConfig(Config $config): self { $this->config = $config; @@ -1245,7 +1245,7 @@ class Installer * @param bool $verbose * @return Installer */ - public function setVerbose(bool $verbose = true): Installer + public function setVerbose(bool $verbose = true): self { $this->verbose = (bool) $verbose; @@ -1275,7 +1275,7 @@ class Installer * * @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); @@ -1286,7 +1286,7 @@ class Installer * @param PlatformRequirementFilterInterface $platformRequirementFilter * @return Installer */ - public function setPlatformRequirementFilter(PlatformRequirementFilterInterface $platformRequirementFilter): Installer + public function setPlatformRequirementFilter(PlatformRequirementFilterInterface $platformRequirementFilter): self { $this->platformRequirementFilter = $platformRequirementFilter; @@ -1299,7 +1299,7 @@ class Installer * @param bool $updateMirrors * @return Installer */ - public function setUpdateMirrors(bool $updateMirrors): Installer + public function setUpdateMirrors(bool $updateMirrors): self { $this->updateMirrors = $updateMirrors; @@ -1314,7 +1314,7 @@ class Installer * * @return Installer */ - public function setUpdateAllowList(array $packages): Installer + public function setUpdateAllowList(array $packages): self { $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 * @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)) { throw new \RuntimeException("Invalid value for updateAllowTransitiveDependencies supplied"); @@ -1347,7 +1347,7 @@ class Installer * @param bool $preferStable * @return Installer */ - public function setPreferStable(bool $preferStable = true): Installer + public function setPreferStable(bool $preferStable = true): self { $this->preferStable = (bool) $preferStable; @@ -1360,7 +1360,7 @@ class Installer * @param bool $preferLowest * @return Installer */ - public function setPreferLowest(bool $preferLowest = true): Installer + public function setPreferLowest(bool $preferLowest = true): self { $this->preferLowest = (bool) $preferLowest; @@ -1375,7 +1375,7 @@ class Installer * @param bool $writeLock * @return Installer */ - public function setWriteLock(bool $writeLock = true): Installer + public function setWriteLock(bool $writeLock = true): self { $this->writeLock = (bool) $writeLock; @@ -1390,7 +1390,7 @@ class Installer * @param bool $executeOperations * @return Installer */ - public function setExecuteOperations(bool $executeOperations = true): Installer + public function setExecuteOperations(bool $executeOperations = true): self { $this->executeOperations = (bool) $executeOperations; @@ -1406,7 +1406,7 @@ class Installer * * @return Installer */ - public function disablePlugins(): Installer + public function disablePlugins(): self { $this->installationManager->disablePlugins(); @@ -1417,7 +1417,7 @@ class Installer * @param SuggestedPackagesReporter $suggestedPackagesReporter * @return Installer */ - public function setSuggestedPackagesReporter(SuggestedPackagesReporter $suggestedPackagesReporter): Installer + public function setSuggestedPackagesReporter(SuggestedPackagesReporter $suggestedPackagesReporter): self { $this->suggestedPackagesReporter = $suggestedPackagesReporter; diff --git a/src/Composer/Package/Archiver/ArchiveManager.php b/src/Composer/Package/Archiver/ArchiveManager.php index 236304e69..c7f5def61 100644 --- a/src/Composer/Package/Archiver/ArchiveManager.php +++ b/src/Composer/Package/Archiver/ArchiveManager.php @@ -68,7 +68,7 @@ class ArchiveManager * * @return $this */ - public function setOverwriteFiles(bool $overwriteFiles) + public function setOverwriteFiles(bool $overwriteFiles): self { $this->overwriteFiles = $overwriteFiles; diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index b7fe52207..cd1f9e2ba 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -49,7 +49,7 @@ class ArrayLoader implements LoaderInterface /** * @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') { 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 */ - public function loadPackages(array $versions) + public function loadPackages(array $versions): array { $packages = 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 string $class FQCN to be instantiated @@ -108,7 +108,7 @@ class ArrayLoader implements LoaderInterface * * @phpstan-param class-string $class */ - private function createObject(array $config, string $class) + private function createObject(array $config, string $class): CompletePackage { if (!isset($config['name'])) { 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 */ - private function configureObject(PackageInterface $package, array $config): PackageInterface + private function configureObject(PackageInterface $package, array $config): BasePackage { if (!$package instanceof CompletePackage) { throw new \LogicException('ArrayLoader expects instances of the Composer\Package\CompletePackage class to function correctly'); diff --git a/src/Composer/Package/Loader/JsonLoader.php b/src/Composer/Package/Loader/JsonLoader.php index 9e9ae689e..4bfeaff8b 100644 --- a/src/Composer/Package/Loader/JsonLoader.php +++ b/src/Composer/Package/Loader/JsonLoader.php @@ -13,8 +13,11 @@ namespace Composer\Package\Loader; use Composer\Json\JsonFile; +use Composer\Package\BasePackage; use Composer\Package\CompletePackage; use Composer\Package\CompleteAliasPackage; +use Composer\Package\RootPackage; +use Composer\Package\RootAliasPackage; /** * @author Konstantin Kudryashiv @@ -31,9 +34,9 @@ class JsonLoader /** * @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) { $config = $json->read(); diff --git a/src/Composer/Package/Loader/LoaderInterface.php b/src/Composer/Package/Loader/LoaderInterface.php index 01c1910da..c81176ded 100644 --- a/src/Composer/Package/Loader/LoaderInterface.php +++ b/src/Composer/Package/Loader/LoaderInterface.php @@ -17,6 +17,7 @@ use Composer\Package\CompletePackage; use Composer\Package\CompleteAliasPackage; use Composer\Package\RootAliasPackage; use Composer\Package\RootPackage; +use Composer\Package\BasePackage; /** * 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 * - * @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 $class + * @phpstan-param class-string $class */ - public function load(array $config, string $class = 'Composer\Package\CompletePackage'); + public function load(array $config, string $class = 'Composer\Package\CompletePackage'): BasePackage; } diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 0ab5cefec..89eb27636 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -61,15 +61,13 @@ class RootPackageLoader extends ArrayLoader /** * @inheritDoc * - * @template PackageClass of RootPackage - * * @param string|null $cwd * * @return RootPackage|RootAliasPackage * - * @phpstan-param class-string $class + * @phpstan-param class-string $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') { trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', E_USER_DEPRECATED); diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 85f4cb67e..997287f44 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -59,7 +59,7 @@ class ValidatingArrayLoader implements LoaderInterface /** * @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->warnings = array(); diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index 096ab9820..d1a10e3ea 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -97,7 +97,7 @@ class ArrayRepository implements RepositoryInterface /** * @inheritDoc */ - public function findPackage($name, $constraint) + public function findPackage(string $name, $constraint) { $name = strtolower($name); @@ -121,7 +121,7 @@ class ArrayRepository implements RepositoryInterface /** * @inheritDoc */ - public function findPackages($name, $constraint = null) + public function findPackages(string $name, $constraint = null) { // normalize name $name = strtolower($name); @@ -237,7 +237,7 @@ class ArrayRepository implements RepositoryInterface /** * @inheritDoc */ - public function getProviders($packageName) + public function getProviders(string $packageName) { $result = array(); diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index edb382264..22f8c5548 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -187,7 +187,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @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 $hasProviders = $this->hasProviders(); @@ -227,7 +227,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito /** * @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 $hasProviders = $this->hasProviders(); @@ -598,7 +598,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito return parent::search($query, $mode); } - public function getProviders($packageName) + public function getProviders(string $packageName) { $this->loadRootServerFile(); $result = array(); diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index 990df2910..81745ed7b 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -116,7 +116,7 @@ class FilesystemRepository extends WritableArrayRepository /** * 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()); $dumper = new ArrayDumper(); diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 8bbf65730..9978413c7 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -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}} */ - 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 // this ensures that a package can be renamed in one place and that all old tags diff --git a/src/Composer/Repository/WritableArrayRepository.php b/src/Composer/Repository/WritableArrayRepository.php index 722cc68f1..6f98ad18d 100644 --- a/src/Composer/Repository/WritableArrayRepository.php +++ b/src/Composer/Repository/WritableArrayRepository.php @@ -57,7 +57,7 @@ class WritableArrayRepository extends ArrayRepository implements WritableReposit /** * @inheritDoc */ - public function write($devMode, InstallationManager $installationManager) + public function write(bool $devMode, InstallationManager $installationManager) { $this->devMode = $devMode; } diff --git a/src/Composer/Script/Event.php b/src/Composer/Script/Event.php index ed6b7f0ba..0f05a7291 100644 --- a/src/Composer/Script/Event.php +++ b/src/Composer/Script/Event.php @@ -40,7 +40,7 @@ class Event extends BaseEvent private $devMode; /** - * @var BaseEvent + * @var BaseEvent|null */ private $originatingEvent; @@ -97,7 +97,7 @@ class Event extends BaseEvent * * @return ?BaseEvent */ - public function getOriginatingEvent() + public function getOriginatingEvent(): ?BaseEvent { return $this->originatingEvent; } @@ -108,7 +108,7 @@ class Event extends BaseEvent * @param BaseEvent $event * @return $this */ - public function setOriginatingEvent(BaseEvent $event) + public function setOriginatingEvent(BaseEvent $event): self { $this->originatingEvent = $this->calculateOriginatingEvent($event); diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index be86b3dd0..f28271c74 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -422,7 +422,7 @@ class Git /** * @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'))) . ')'; } @@ -430,7 +430,7 @@ class Git /** * @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'))) . ')'; } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index f10f4b4f0..ee21169e1 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -151,7 +151,7 @@ class Perforce /** * @return non-empty-string */ - public function generateUniquePerforceClientName() + public function generateUniquePerforceClientName(): string { return gethostname() . "_" . time(); } @@ -281,7 +281,7 @@ class Perforce /** * @return non-empty-string */ - public function getP4ClientSpec() + public function getP4ClientSpec(): string { return $this->path . '/' . $this->getClient() . '.p4.spec'; } @@ -330,7 +330,7 @@ class Perforce * @param string $name * @return ?string */ - protected function getP4variable(string $name) + protected function getP4variable(string $name): ?string { if ($this->windowsFlag) { $command = 'p4 set'; @@ -385,7 +385,7 @@ class Perforce * * @return non-empty-string */ - public function generateP4Command(string $command, bool $useClient = true) + public function generateP4Command(string $command, bool $useClient = true): string { $p4Command = 'p4 '; $p4Command .= '-u ' . $this->getUser() . ' '; @@ -614,7 +614,7 @@ class Perforce /** * @return array{master: string} */ - public function getBranches() + public function getBranches(): array { $possibleBranches = array(); if (!$this->isStream()) { diff --git a/src/bootstrap.php b/src/bootstrap.php index 39eba0065..f61063a4a 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -10,11 +10,7 @@ * file that was distributed with this source code. */ -/** - * @param string $file - * @return ?\Composer\Autoload\ClassLoader - */ -function includeIfExists(string $file) +function includeIfExists(string $file): ?\Composer\Autoload\ClassLoader { return file_exists($file) ? include $file : null; } diff --git a/tests/Composer/Test/TestCase.php b/tests/Composer/Test/TestCase.php index e901822ba..0e61bb87a 100644 --- a/tests/Composer/Test/TestCase.php +++ b/tests/Composer/Test/TestCase.php @@ -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 $name @@ -124,7 +124,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase * @phpstan-param class-string $class * @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);