From b2098160568d161a9b7a35c05f2dd1c78fb9d8d8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 17 Oct 2021 14:21:19 +0200 Subject: [PATCH] Type annotations --- src/Composer/DependencyResolver/Pool.php | 14 +++++++- .../DependencyResolver/PoolBuilder.php | 21 +++++++++++ src/Composer/DependencyResolver/Problem.php | 24 +++++++++++++ src/Composer/DependencyResolver/Request.php | 36 +++++++++++++++++++ src/Composer/DependencyResolver/RuleSet.php | 12 +++++++ .../DependencyResolver/RuleSetGenerator.php | 18 ++++++++++ .../DependencyResolver/RuleSetIterator.php | 15 ++++++++ src/Composer/DependencyResolver/Solver.php | 21 +++++++++++ .../SolverProblemsException.php | 14 +++++++- src/Composer/Downloader/ArchiveDownloader.php | 7 ++++ src/Composer/Downloader/DownloadManager.php | 3 ++ src/Composer/Downloader/GitDownloader.php | 7 ++++ .../Downloader/PerforceDownloader.php | 6 ++++ .../EventDispatcher/EventDispatcher.php | 9 ++++- src/Composer/Factory.php | 12 +++++++ 15 files changed, 216 insertions(+), 3 deletions(-) diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index 2e1125872..68673453b 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -107,7 +107,10 @@ class Pool implements \Countable } /** - * @see whatProvides + * @param string $name The package name to be searched for + * @param ConstraintInterface $constraint A constraint that all returned + * packages must match or null to return all + * @return BasePackage[] */ private function computeWhatProvides($name, $constraint) { @@ -126,6 +129,9 @@ class Pool implements \Countable return $matches; } + /** + * @return BasePackage + */ public function literalToPackage($literal) { $packageId = abs($literal); @@ -133,6 +139,9 @@ class Pool implements \Countable return $this->packageById($packageId); } + /** + * @return string + */ public function literalToPrettyString($literal, $installedMap) { $package = $this->literalToPackage($literal); @@ -195,6 +204,9 @@ class Pool implements \Countable return false; } + /** + * @return bool + */ public function isUnacceptableFixedOrLockedPackage(BasePackage $package) { return \in_array($package, $this->unacceptableFixedOrLockedPackages, true); diff --git a/src/Composer/DependencyResolver/PoolBuilder.php b/src/Composer/DependencyResolver/PoolBuilder.php index 97159a3c8..e0a06dc27 100644 --- a/src/Composer/DependencyResolver/PoolBuilder.php +++ b/src/Composer/DependencyResolver/PoolBuilder.php @@ -139,6 +139,9 @@ class PoolBuilder $this->io = $io; } + /** + * @return Pool + */ public function buildPool(array $repositories, Request $request) { if ($request->getUpdateAllowList()) { @@ -261,6 +264,9 @@ class PoolBuilder return $pool; } + /** + * @return void + */ private function markPackageNameForLoading(Request $request, $name, ConstraintInterface $constraint) { // Skip platform requires at this stage @@ -316,6 +322,9 @@ class PoolBuilder unset($this->loadedPackages[$name]); } + /** + * @return void + */ private function loadPackagesMarkedForLoading(Request $request, $repositories) { foreach ($this->packagesToLoad as $name => $constraint) { @@ -348,6 +357,9 @@ class PoolBuilder } } + /** + * @return void + */ private function loadPackage(Request $request, BasePackage $package, $propagateUpdate = true) { $index = $this->indexCounter++; @@ -445,6 +457,7 @@ class PoolBuilder /** * Checks whether the update allow list allows this package in the lock file to be updated + * * @return bool */ private function isUpdateAllowed(PackageInterface $package) @@ -469,6 +482,9 @@ class PoolBuilder return false; } + /** + * @return void + */ private function warnAboutNonMatchingUpdateAllowList(Request $request) { foreach ($this->updateAllowList as $pattern => $void) { @@ -496,6 +512,8 @@ class PoolBuilder /** * Reverts the decision to use a locked package if a partial update with transitive dependencies * found that this package actually needs to be updated + * + * @return void */ private function unlockPackage(Request $request, $name) { @@ -534,6 +552,9 @@ class PoolBuilder } } + /** + * @return void + */ private function removeLoadedPackage(Request $request, PackageInterface $package, $index) { unset($this->packages[$index]); diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index 35ce3b045..076c3a2a4 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -102,6 +102,7 @@ class Problem /** * @internal + * @return string */ public static function formatDeduplicatedRules($rules, $indent, RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, array $installedMap = array(), array $learnedPool = array()) { @@ -144,6 +145,9 @@ class Problem return "\n$indent- ".implode("\n$indent- ", $result); } + /** + * @return bool + */ public function isCausedByLock(RepositorySet $repositorySet, Request $request, Pool $pool) { foreach ($this->reasons as $sectionRules) { @@ -153,6 +157,8 @@ class Problem } } } + + return false; } /** @@ -160,6 +166,8 @@ class Problem * * @param string $id A canonical identifier for the reason * @param Rule $reason The reason descriptor + * + * @return void */ protected function addReason($id, Rule $reason) { @@ -172,6 +180,9 @@ class Problem } } + /** + * @return void + */ public function nextSection() { $this->section++; @@ -179,6 +190,7 @@ class Problem /** * @internal + * @return array{0: string, 1: string} */ public static function getMissingPackageReason(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, $packageName, $constraint = null) { @@ -331,6 +343,7 @@ class Problem /** * @internal + * @return string */ public static function getPackageList(array $packages, $isVerbose) { @@ -360,6 +373,11 @@ class Problem return implode(', ', $prepared); } + /** + * @param string $version + * @param string $packageName + * @return string + */ private static function getPlatformPackageVersion(Pool $pool, $packageName, $version) { $available = $pool->whatProvides($packageName); @@ -410,6 +428,9 @@ class Problem return $filtered; } + /** + * @return bool + */ private static function hasMultipleNames(array $packages) { $name = null; @@ -424,6 +445,9 @@ class Problem return false; } + /** + * @return array{0: string, 1: string} + */ private static function computeCheckForLowerPrioRepo($isVerbose, $packageName, $constraint, array $higherRepoPackages, array $allReposPackages, $reason) { $nextRepoPackages = array(); diff --git a/src/Composer/DependencyResolver/Request.php b/src/Composer/DependencyResolver/Request.php index 3514bd4c8..dc5ba0365 100644 --- a/src/Composer/DependencyResolver/Request.php +++ b/src/Composer/DependencyResolver/Request.php @@ -123,46 +123,73 @@ class Request $this->updateAllowTransitiveDependencies = $updateAllowTransitiveDependencies; } + /** + * @return string[] + */ public function getUpdateAllowList() { return $this->updateAllowList; } + /** + * @return bool + */ public function getUpdateAllowTransitiveDependencies() { return $this->updateAllowTransitiveDependencies !== self::UPDATE_ONLY_LISTED; } + /** + * @return bool + */ public function getUpdateAllowTransitiveRootDependencies() { return $this->updateAllowTransitiveDependencies === self::UPDATE_LISTED_WITH_TRANSITIVE_DEPS; } + /** + * @return array + */ public function getRequires() { return $this->requires; } + /** + * @return array + */ public function getFixedPackages() { return $this->fixedPackages; } + /** + * @return bool + */ public function isFixedPackage(PackageInterface $package) { return isset($this->fixedPackages[spl_object_hash($package)]); } + /** + * @return array + */ public function getLockedPackages() { return $this->lockedPackages; } + /** + * @return bool + */ public function isLockedPackage(PackageInterface $package) { return isset($this->lockedPackages[spl_object_hash($package)]) || isset($this->fixedLockedPackages[spl_object_hash($package)]); } + /** + * @return array + */ public function getFixedOrLockedPackages() { return array_merge($this->fixedPackages, $this->lockedPackages); @@ -170,6 +197,9 @@ class Request // TODO look into removing the packageIds option, the only place true is used is for the installed map in the solver problems // some locked packages may not be in the pool so they have a package->id of -1 + /** + * @return array + */ public function getPresentMap($packageIds = false) { $presentMap = array(); @@ -187,6 +217,9 @@ class Request return $presentMap; } + /** + * @return PackageInterface[] + */ public function getFixedPackagesMap() { $fixedPackagesMap = array(); @@ -198,6 +231,9 @@ class Request return $fixedPackagesMap; } + /** + * @return ?LockArrayRepository + */ public function getLockedRepository() { return $this->lockedRepository; diff --git a/src/Composer/DependencyResolver/RuleSet.php b/src/Composer/DependencyResolver/RuleSet.php index ba9aeaee2..9d75dac70 100644 --- a/src/Composer/DependencyResolver/RuleSet.php +++ b/src/Composer/DependencyResolver/RuleSet.php @@ -100,12 +100,18 @@ class RuleSet implements \IteratorAggregate, \Countable } } + /** + * @return int + */ #[\ReturnTypeWillChange] public function count() { return $this->nextRuleId; } + /** + * @return Rule + */ public function ruleById($id) { return $this->ruleById[$id]; @@ -148,6 +154,9 @@ class RuleSet implements \IteratorAggregate, \Countable return new RuleSetIterator($rules); } + /** + * @return RuleSetIterator + */ public function getIteratorWithout($types) { if (!\is_array($types)) { @@ -172,6 +181,9 @@ class RuleSet implements \IteratorAggregate, \Countable return array_keys($types); } + /** + * @return string + */ public function getPrettyString(RepositorySet $repositorySet = null, Request $request = null, Pool $pool = null, $isVerbose = false) { $string = "\n"; diff --git a/src/Composer/DependencyResolver/RuleSetGenerator.php b/src/Composer/DependencyResolver/RuleSetGenerator.php index 245f1fdda..2c6a94803 100644 --- a/src/Composer/DependencyResolver/RuleSetGenerator.php +++ b/src/Composer/DependencyResolver/RuleSetGenerator.php @@ -122,6 +122,9 @@ class RuleSetGenerator return new Rule2Literals(-$issuer->id, -$provider->id, $reason, $reasonData); } + /** + * @return Rule + */ protected function createMultiConflictRule(array $packages, $reason, $reasonData = null) { $literals = array(); @@ -144,6 +147,8 @@ class RuleSetGenerator * * @param int $type A TYPE_* constant defining the rule type * @param Rule $newRule The rule about to be added + * + * @return void */ private function addRule($type, Rule $newRule = null) { @@ -154,6 +159,9 @@ class RuleSetGenerator $this->rules->add($newRule, $type); } + /** + * @return void + */ protected function addRulesForPackage(BasePackage $package, $ignorePlatformReqs) { /** @var \SplQueue */ @@ -202,6 +210,9 @@ class RuleSetGenerator } } + /** + * @return void + */ protected function addConflictRules($ignorePlatformReqs = false) { /** @var BasePackage $package */ @@ -237,6 +248,9 @@ class RuleSetGenerator } } + /** + * @return void + */ protected function addRulesForRequest(Request $request, $ignorePlatformReqs) { foreach ($request->getFixedPackages() as $package) { @@ -278,6 +292,9 @@ class RuleSetGenerator } } + /** + * @return void + */ protected function addRulesForRootAliases($ignorePlatformReqs) { foreach ($this->pool->getPackages() as $package) { @@ -295,6 +312,7 @@ class RuleSetGenerator /** * @param bool|array $ignorePlatformReqs + * @return RuleSet */ public function getRulesFor(Request $request, $ignorePlatformReqs = false) { diff --git a/src/Composer/DependencyResolver/RuleSetIterator.php b/src/Composer/DependencyResolver/RuleSetIterator.php index 2726253d2..1450c1cba 100644 --- a/src/Composer/DependencyResolver/RuleSetIterator.php +++ b/src/Composer/DependencyResolver/RuleSetIterator.php @@ -42,18 +42,27 @@ class RuleSetIterator implements \Iterator $this->rewind(); } + /** + * @return Rule + */ #[\ReturnTypeWillChange] public function current() { return $this->rules[$this->currentType][$this->currentOffset]; } + /** + * @return RuleSet::TYPE_*|-1 + */ #[\ReturnTypeWillChange] public function key() { return $this->currentType; } + /** + * @return void + */ #[\ReturnTypeWillChange] public function next() { @@ -79,6 +88,9 @@ class RuleSetIterator implements \Iterator } } + /** + * @return void + */ #[\ReturnTypeWillChange] public function rewind() { @@ -99,6 +111,9 @@ class RuleSetIterator implements \Iterator } while (isset($this->types[$this->currentTypeOffset]) && !\count($this->rules[$this->currentType])); } + /** + * @return bool + */ #[\ReturnTypeWillChange] public function valid() { diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 7454ea74e..af474240c 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -76,6 +76,9 @@ class Solver return \count($this->rules); } + /** + * @return Pool + */ public function getPool() { return $this->pool; @@ -83,6 +86,9 @@ class Solver // aka solver_makeruledecisions + /** + * @return void + */ private function makeAssertionRuleDecisions() { $decisionStart = \count($this->decisions) - 1; @@ -153,6 +159,9 @@ class Solver } } + /** + * @return void + */ protected function setupFixedMap(Request $request) { $this->fixedMap = array(); @@ -164,6 +173,8 @@ class Solver /** * @param Request $request * @param bool|array $ignorePlatformReqs + * + * @return void */ protected function checkForRootRequireProblems(Request $request, $ignorePlatformReqs) { @@ -251,6 +262,8 @@ class Solver * Reverts a decision at the given level. * * @param int $level + * + * @return void */ private function revert($level) { @@ -513,6 +526,9 @@ class Solver return array($learnedLiterals[0], $ruleLevel, $newRule, $why); } + /** + * @return void + */ private function analyzeUnsolvableRule(Problem $problem, Rule $conflictRule, array &$ruleSeen) { $why = spl_object_hash($conflictRule); @@ -599,6 +615,8 @@ class Solver * we have enabled or disabled some of our rules. We now re-enable all * of our learnt rules except the ones that were learnt from rules that * are now disabled. + * + * @return void */ private function enableDisableLearnedRules() { @@ -622,6 +640,9 @@ class Solver } } + /** + * @return void + */ private function runSat() { $this->propagateIndex = 0; diff --git a/src/Composer/DependencyResolver/SolverProblemsException.php b/src/Composer/DependencyResolver/SolverProblemsException.php index 846648752..ec86c5fa3 100644 --- a/src/Composer/DependencyResolver/SolverProblemsException.php +++ b/src/Composer/DependencyResolver/SolverProblemsException.php @@ -40,6 +40,9 @@ class SolverProblemsException extends \RuntimeException parent::__construct('Failed resolving dependencies with '.count($problems).' problems, call getPrettyString to get formatted details', self::ERROR_DEPENDENCY_RESOLUTION_FAILED); } + /** + * @return string + */ public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, $isDevExtraction = false) { $installedMap = $request->getPresentMap(true); @@ -54,7 +57,7 @@ class SolverProblemsException extends \RuntimeException $hasExtensionProblems = true; } - $isCausedByLock |= $problem->isCausedByLock($repositorySet, $request, $pool); + $isCausedByLock = $isCausedByLock || $problem->isCausedByLock($repositorySet, $request, $pool); } $i = 1; @@ -93,11 +96,17 @@ class SolverProblemsException extends \RuntimeException return $text; } + /** + * @return Problem[] + */ public function getProblems() { return $this->problems; } + /** + * @return string + */ private function createExtensionHint() { $paths = IniHelper::getAll(); @@ -113,6 +122,9 @@ class SolverProblemsException extends \RuntimeException return $text; } + /** + * @return bool + */ private function hasExtensionProblems(array $reasonSets) { foreach ($reasonSets as $reasonSet) { diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index 8b72f3518..6e168369f 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -32,6 +32,9 @@ abstract class ArchiveDownloader extends FileDownloader */ public $cleanupExecuted = array(); + /** + * @return PromiseInterface|null + */ public function prepare($type, PackageInterface $package, $path, PackageInterface $prevPackage = null) { unset($this->cleanupExecuted[$package->getName()]); @@ -39,6 +42,9 @@ abstract class ArchiveDownloader extends FileDownloader return parent::prepare($type, $package, $path, $prevPackage); } + /** + * @return PromiseInterface|null + */ public function cleanup($type, PackageInterface $package, $path, PackageInterface $prevPackage = null) { $this->cleanupExecuted[$package->getName()] = true; @@ -50,6 +56,7 @@ abstract class ArchiveDownloader extends FileDownloader * {@inheritDoc} * @throws \RuntimeException * @throws \UnexpectedValueException + * @return PromiseInterface */ public function install(PackageInterface $package, $path, $output = true) { diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index 7616229cb..fb119be0c 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -163,6 +163,9 @@ class DownloadManager return $downloader; } + /** + * @return string + */ public function getDownloaderType(DownloaderInterface $downloader) { return array_search($downloader, $this->downloaders); diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index f8e157894..770a3f0b8 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -218,6 +218,9 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface return trim($output) ?: null; } + /** + * @return null|string + */ public function getUnpushedChanges(PackageInterface $package, $path) { GitUtil::cleanEnv(); @@ -590,6 +593,10 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface return is_dir($path.'/.git'); } + /** + * @param string $reference + * @return string + */ protected function getShortHash($reference) { if (!$this->io->isVerbose() && preg_match('{^[0-9a-f]{40}$}', $reference)) { diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index dc30f8361..9172fa3ca 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -52,6 +52,9 @@ class PerforceDownloader extends VcsDownloader return \React\Promise\resolve(); } + /** + * @return string|null + */ private function getLabelFromSourceReference($ref) { $pos = strpos($ref, '@'); @@ -78,6 +81,9 @@ class PerforceDownloader extends VcsDownloader $this->perforce = Perforce::create($repoConfig, $url, $path, $this->process, $this->io); } + /** + * @return array + */ private function getRepoConfig(VcsRepository $repository) { return $repository->getRepoConfig(); diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index ca23a1bdd..c273fdf59 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -77,6 +77,7 @@ class EventDispatcher * Set whether script handlers are active or not * * @param bool $runScripts + * @return $this */ public function setRunScripts($runScripts = true) { @@ -336,6 +337,9 @@ class EventDispatcher return $returnMax; } + /** + * @return int + */ protected function executeTty($exec) { if ($this->io->isInteractive()) { @@ -345,6 +349,9 @@ class EventDispatcher return $this->process->execute($exec); } + /** + * @return string + */ protected function getPhpExecCommand() { $finder = new PhpExecutableFinder(); @@ -536,7 +543,7 @@ class EventDispatcher /** * Pops the active event from the stack * - * @return mixed + * @return string|null */ protected function popEvent() { diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index d67ccf29a..6d870f6b9 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -241,11 +241,17 @@ class Factory return $config; } + /** + * @return string + */ public static function getComposerFile() { return trim(getenv('COMPOSER')) ?: './composer.json'; } + /** + * @return string + */ public static function getLockFile($composerFile) { return "json" === pathinfo($composerFile, PATHINFO_EXTENSION) @@ -253,6 +259,9 @@ class Factory : $composerFile . '.lock'; } + /** + * @return array{highlight: OutputFormatterStyle, warning: OutputFormatterStyle} + */ public static function createAdditionalStyles() { return array( @@ -596,6 +605,9 @@ class Factory } } + /** + * @return Package\Loader\RootPackageLoader + */ protected function loadRootPackage(RepositoryManager $rm, Config $config, VersionParser $parser, VersionGuesser $guesser, IOInterface $io) { return new Package\Loader\RootPackageLoader($rm, $config, $parser, $guesser, $io);