1
0
Fork 0

Type annotations

pull/10174/head
Jordi Boggiano 2021-10-17 10:18:22 +02:00
parent 9fde6ec88b
commit e137046558
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
14 changed files with 147 additions and 0 deletions

View File

@ -280,6 +280,9 @@ class Compiler
return $output; return $output;
} }
/**
* @return string
*/
private function getStub() private function getStub()
{ {
$stub = <<<'EOF' $stub = <<<'EOF'

View File

@ -67,6 +67,9 @@ class Composer
*/ */
const RUNTIME_API_VERSION = '2.1.0'; const RUNTIME_API_VERSION = '2.1.0';
/**
* @return string
*/
public static function getVersion() public static function getVersion()
{ {
// no replacement done, this must be a source checkout // no replacement done, this must be a source checkout

View File

@ -119,6 +119,9 @@ class Config
$this->configSource = $source; $this->configSource = $source;
} }
/**
* @return ConfigSourceInterface
*/
public function getConfigSource() public function getConfigSource()
{ {
return $this->configSource; return $this->configSource;
@ -129,6 +132,9 @@ class Config
$this->authConfigSource = $source; $this->authConfigSource = $source;
} }
/**
* @return ConfigSourceInterface
*/
public function getAuthConfigSource() public function getAuthConfigSource()
{ {
return $this->authConfigSource; return $this->authConfigSource;
@ -373,6 +379,9 @@ class Config
} }
} }
/**
* @return array<string, mixed[]>
*/
public function all($flags = 0) public function all($flags = 0)
{ {
$all = array( $all = array(
@ -385,6 +394,9 @@ class Config
return $all; return $all;
} }
/**
* @return array<string, mixed[]>
*/
public function raw() public function raw()
{ {
return array( return array(

View File

@ -468,6 +468,9 @@ class Application extends BaseApplication
return $this->io; return $this->io;
} }
/**
* @return string
*/
public function getHelp() public function getHelp()
{ {
return self::$logo . parent::getHelp(); return self::$logo . parent::getHelp();
@ -548,6 +551,9 @@ class Application extends BaseApplication
return $definition; return $definition;
} }
/**
* @return Command\BaseCommand[]
*/
private function getPluginCommands() private function getPluginCommands()
{ {
$commands = array(); $commands = array();

View File

@ -58,6 +58,9 @@ class HtmlOutputFormatter extends OutputFormatter
parent::__construct(true, $styles); parent::__construct(true, $styles);
} }
/**
* @return string
*/
public function format($message) public function format($message)
{ {
$formatted = parent::format($message); $formatted = parent::format($message);
@ -67,6 +70,9 @@ class HtmlOutputFormatter extends OutputFormatter
return preg_replace_callback("{\033\[([0-9;]+)m(.*?)\033\[(?:".$clearEscapeCodes.";)*?".$clearEscapeCodes."m}s", array($this, 'formatHtml'), $formatted); return preg_replace_callback("{\033\[([0-9;]+)m(.*?)\033\[(?:".$clearEscapeCodes.";)*?".$clearEscapeCodes."m}s", array($this, 'formatHtml'), $formatted);
} }
/**
* @return string
*/
private function formatHtml($matches) private function formatHtml($matches)
{ {
$out = '<span style="'; $out = '<span style="';

View File

@ -45,6 +45,9 @@ class Decisions implements \Iterator, \Countable
); );
} }
/**
* @return bool
*/
public function satisfy($literal) public function satisfy($literal)
{ {
$packageId = abs($literal); $packageId = abs($literal);
@ -55,6 +58,9 @@ class Decisions implements \Iterator, \Countable
); );
} }
/**
* @return bool
*/
public function conflict($literal) public function conflict($literal)
{ {
$packageId = abs($literal); $packageId = abs($literal);
@ -65,16 +71,25 @@ class Decisions implements \Iterator, \Countable
); );
} }
/**
* @return bool
*/
public function decided($literalOrPackageId) public function decided($literalOrPackageId)
{ {
return !empty($this->decisionMap[abs($literalOrPackageId)]); return !empty($this->decisionMap[abs($literalOrPackageId)]);
} }
/**
* @return bool
*/
public function undecided($literalOrPackageId) public function undecided($literalOrPackageId)
{ {
return empty($this->decisionMap[abs($literalOrPackageId)]); return empty($this->decisionMap[abs($literalOrPackageId)]);
} }
/**
* @return bool
*/
public function decidedInstall($literalOrPackageId) public function decidedInstall($literalOrPackageId)
{ {
$packageId = abs($literalOrPackageId); $packageId = abs($literalOrPackageId);
@ -82,6 +97,9 @@ class Decisions implements \Iterator, \Countable
return isset($this->decisionMap[$packageId]) && $this->decisionMap[$packageId] > 0; return isset($this->decisionMap[$packageId]) && $this->decisionMap[$packageId] > 0;
} }
/**
* @return int
*/
public function decisionLevel($literalOrPackageId) public function decisionLevel($literalOrPackageId)
{ {
$packageId = abs($literalOrPackageId); $packageId = abs($literalOrPackageId);
@ -92,6 +110,9 @@ class Decisions implements \Iterator, \Countable
return 0; return 0;
} }
/**
* @return mixed|null
*/
public function decisionRule($literalOrPackageId) public function decisionRule($literalOrPackageId)
{ {
$packageId = abs($literalOrPackageId); $packageId = abs($literalOrPackageId);
@ -105,26 +126,41 @@ class Decisions implements \Iterator, \Countable
return null; return null;
} }
/**
* @return array{0: int, 1: mixed} a literal and decision reason
*/
public function atOffset($queueOffset) public function atOffset($queueOffset)
{ {
return $this->decisionQueue[$queueOffset]; return $this->decisionQueue[$queueOffset];
} }
/**
* @return bool
*/
public function validOffset($queueOffset) public function validOffset($queueOffset)
{ {
return $queueOffset >= 0 && $queueOffset < \count($this->decisionQueue); return $queueOffset >= 0 && $queueOffset < \count($this->decisionQueue);
} }
/**
* @return mixed
*/
public function lastReason() public function lastReason()
{ {
return $this->decisionQueue[\count($this->decisionQueue) - 1][self::DECISION_REASON]; return $this->decisionQueue[\count($this->decisionQueue) - 1][self::DECISION_REASON];
} }
/**
* @return int
*/
public function lastLiteral() public function lastLiteral()
{ {
return $this->decisionQueue[\count($this->decisionQueue) - 1][self::DECISION_LITERAL]; return $this->decisionQueue[\count($this->decisionQueue) - 1][self::DECISION_LITERAL];
} }
/**
* @return void
*/
public function reset() public function reset()
{ {
while ($decision = array_pop($this->decisionQueue)) { while ($decision = array_pop($this->decisionQueue)) {
@ -132,6 +168,9 @@ class Decisions implements \Iterator, \Countable
} }
} }
/**
* @return void
*/
public function resetToOffset($offset) public function resetToOffset($offset)
{ {
while (\count($this->decisionQueue) > $offset + 1) { while (\count($this->decisionQueue) > $offset + 1) {
@ -140,53 +179,80 @@ class Decisions implements \Iterator, \Countable
} }
} }
/**
* @return void
*/
public function revertLast() public function revertLast()
{ {
$this->decisionMap[abs($this->lastLiteral())] = 0; $this->decisionMap[abs($this->lastLiteral())] = 0;
array_pop($this->decisionQueue); array_pop($this->decisionQueue);
} }
/**
* @return int
*/
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function count() public function count()
{ {
return \count($this->decisionQueue); return \count($this->decisionQueue);
} }
/**
* @return void
*/
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function rewind() public function rewind()
{ {
end($this->decisionQueue); end($this->decisionQueue);
} }
/**
* @return array{0: int, 1: mixed}|false
*/
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function current() public function current()
{ {
return current($this->decisionQueue); return current($this->decisionQueue);
} }
/**
* @return ?int
*/
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function key() public function key()
{ {
return key($this->decisionQueue); return key($this->decisionQueue);
} }
/**
* @return void
*/
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function next() public function next()
{ {
prev($this->decisionQueue); prev($this->decisionQueue);
} }
/**
* @return bool
*/
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function valid() public function valid()
{ {
return false !== current($this->decisionQueue); return false !== current($this->decisionQueue);
} }
/**
* @return bool
*/
public function isEmpty() public function isEmpty()
{ {
return \count($this->decisionQueue) === 0; return \count($this->decisionQueue) === 0;
} }
/**
* @return void
*/
protected function addDecision($literal, $level) protected function addDecision($literal, $level)
{ {
$packageId = abs($literal); $packageId = abs($literal);
@ -207,6 +273,9 @@ class Decisions implements \Iterator, \Countable
} }
} }
/**
* @return string
*/
public function toString(Pool $pool = null) public function toString(Pool $pool = null)
{ {
$decisionMap = $this->decisionMap; $decisionMap = $this->decisionMap;
@ -220,6 +289,9 @@ class Decisions implements \Iterator, \Countable
return $str; return $str;
} }
/**
* @return string
*/
public function __toString() public function __toString()
{ {
return $this->toString(); return $this->toString();

View File

@ -34,6 +34,9 @@ class DefaultPolicy implements PolicyInterface
$this->preferLowest = $preferLowest; $this->preferLowest = $preferLowest;
} }
/**
* @return bool
*/
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator) public function versionCompare(PackageInterface $a, PackageInterface $b, $operator)
{ {
if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) { if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) {
@ -46,6 +49,11 @@ class DefaultPolicy implements PolicyInterface
return $constraint->matchSpecific($version, true); return $constraint->matchSpecific($version, true);
} }
/**
* @param int[] $literals
* @param bool $requiredPackage
* @return int[]
*/
public function selectPreferredPackages(Pool $pool, array $literals, $requiredPackage = null) public function selectPreferredPackages(Pool $pool, array $literals, $requiredPackage = null)
{ {
$packages = $this->groupLiteralsByName($pool, $literals); $packages = $this->groupLiteralsByName($pool, $literals);
@ -72,6 +80,10 @@ class DefaultPolicy implements PolicyInterface
return $selected; return $selected;
} }
/**
* @param int[] $literals
* @return array<string, int[]>
*/
protected function groupLiteralsByName(Pool $pool, $literals) protected function groupLiteralsByName(Pool $pool, $literals)
{ {
$packages = array(); $packages = array();
@ -89,6 +101,7 @@ class DefaultPolicy implements PolicyInterface
/** /**
* @protected * @protected
* @return int
*/ */
public function compareByPriority(Pool $pool, BasePackage $a, BasePackage $b, $requiredPackage = null, $ignoreReplace = false) public function compareByPriority(Pool $pool, BasePackage $a, BasePackage $b, $requiredPackage = null, $ignoreReplace = false)
{ {
@ -159,6 +172,10 @@ class DefaultPolicy implements PolicyInterface
return false; return false;
} }
/**
* @param int[] $literals
* @return int[]
*/
protected function pruneToBestVersion(Pool $pool, $literals) protected function pruneToBestVersion(Pool $pool, $literals)
{ {
$operator = $this->preferLowest ? '<' : '>'; $operator = $this->preferLowest ? '<' : '>';
@ -186,6 +203,9 @@ class DefaultPolicy implements PolicyInterface
* Assumes that locally aliased (in root package requires) packages take priority over branch-alias ones * Assumes that locally aliased (in root package requires) packages take priority over branch-alias ones
* *
* If no package is a local alias, nothing happens * If no package is a local alias, nothing happens
*
* @param int[] $literals
* @return int[]
*/ */
protected function pruneRemoteAliases(Pool $pool, array $literals) protected function pruneRemoteAliases(Pool $pool, array $literals)
{ {

View File

@ -37,6 +37,9 @@ class GenericRule extends Rule
$this->literals = $literals; $this->literals = $literals;
} }
/**
* @return int[]
*/
public function getLiterals() public function getLiterals()
{ {
return $this->literals; return $this->literals;
@ -62,6 +65,9 @@ class GenericRule extends Rule
return $this->literals === $rule->getLiterals(); return $this->literals === $rule->getLiterals();
} }
/**
* @return bool
*/
public function isAssertion() public function isAssertion()
{ {
return 1 === \count($this->literals); return 1 === \count($this->literals);

View File

@ -95,6 +95,9 @@ class LockTransaction extends Transaction
} }
// TODO additionalFixedRepository needs to be looked at here as well? // TODO additionalFixedRepository needs to be looked at here as well?
/**
* @return BasePackage[]
*/
public function getNewLockPackages($devMode, $updateMirrors = false) public function getNewLockPackages($devMode, $updateMirrors = false)
{ {
$packages = array(); $packages = array();

View File

@ -42,6 +42,9 @@ class MultiConflictRule extends Rule
$this->literals = $literals; $this->literals = $literals;
} }
/**
* @return int[]
*/
public function getLiterals() public function getLiterals()
{ {
return $this->literals; return $this->literals;
@ -71,6 +74,9 @@ class MultiConflictRule extends Rule
return false; return false;
} }
/**
* @return bool
*/
public function isAssertion() public function isAssertion()
{ {
return false; return false;

View File

@ -51,6 +51,9 @@ class InstallOperation extends SolverOperation implements OperationInterface
return self::format($this->package, $lock); return self::format($this->package, $lock);
} }
/**
* @return string
*/
public static function format(PackageInterface $package, $lock = false) public static function format(PackageInterface $package, $lock = false)
{ {
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)'; return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';

View File

@ -51,6 +51,9 @@ class UninstallOperation extends SolverOperation implements OperationInterface
return self::format($this->package, $lock); return self::format($this->package, $lock);
} }
/**
* @return string
*/
public static function format(PackageInterface $package, $lock = false) public static function format(PackageInterface $package, $lock = false)
{ {
return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)'; return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';

View File

@ -72,6 +72,9 @@ class UpdateOperation extends SolverOperation implements OperationInterface
return self::format($this->initialPackage, $this->targetPackage, $lock); return self::format($this->initialPackage, $this->targetPackage, $lock);
} }
/**
* @return string
*/
public static function format(PackageInterface $initialPackage, PackageInterface $targetPackage, $lock = false) public static function format(PackageInterface $initialPackage, PackageInterface $targetPackage, $lock = false)
{ {
$fromVersion = $initialPackage->getFullPrettyVersion(); $fromVersion = $initialPackage->getFullPrettyVersion();

View File

@ -80,6 +80,7 @@ class Pool implements \Countable
/** /**
* Returns how many packages have been loaded into the pool * Returns how many packages have been loaded into the pool
* @return int
*/ */
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function count() public function count()