1
0
Fork 0

Add types to `Package` (#10210)

pull/10212/head
Martin Herndl 2021-10-25 13:45:09 +02:00 committed by GitHub
parent 36484ff01a
commit bd8b39fe01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 131 additions and 15 deletions

View File

@ -29,6 +29,7 @@ class AliasPackage extends BasePackage
/** @var bool */ /** @var bool */
protected $rootPackageAlias = false; protected $rootPackageAlias = false;
/** @var string */ /** @var string */
/** @phpstan-var 'stable'|'RC'|'beta'|'alpha'|'dev' */
protected $stability; protected $stability;
/** @var bool */ /** @var bool */
protected $hasSelfVersionRequires = false; protected $hasSelfVersionRequires = false;
@ -214,6 +215,9 @@ class AliasPackage extends BasePackage
return $links; return $links;
} }
/**
* @return bool
*/
public function hasSelfVersionRequires() public function hasSelfVersionRequires()
{ {
return $this->hasSelfVersionRequires; return $this->hasSelfVersionRequires;

View File

@ -168,6 +168,9 @@ abstract class BasePackage implements PackageInterface
return $this->getName().'-'.$this->getVersion(); return $this->getName().'-'.$this->getVersion();
} }
/**
* @return bool
*/
public function equals(PackageInterface $package) public function equals(PackageInterface $package)
{ {
$self = $this; $self = $this;
@ -231,6 +234,11 @@ abstract class BasePackage implements PackageInterface
return $this->getPrettyVersion() . ' ' . $reference; return $this->getPrettyVersion() . ' ' . $reference;
} }
/**
* @return int
*
* @phpstan-return self::STABILITY_*
*/
public function getStabilityPriority() public function getStabilityPriority()
{ {
return self::$stabilities[$this->getStability()]; return self::$stabilities[$this->getStability()];

View File

@ -251,6 +251,9 @@ class Locker
return $requirements; return $requirements;
} }
/**
* @return string
*/
public function getMinimumStability() public function getMinimumStability()
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
@ -258,6 +261,9 @@ class Locker
return isset($lockData['minimum-stability']) ? $lockData['minimum-stability'] : 'stable'; return isset($lockData['minimum-stability']) ? $lockData['minimum-stability'] : 'stable';
} }
/**
* @return array<string, string>
*/
public function getStabilityFlags() public function getStabilityFlags()
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
@ -265,6 +271,9 @@ class Locker
return isset($lockData['stability-flags']) ? $lockData['stability-flags'] : array(); return isset($lockData['stability-flags']) ? $lockData['stability-flags'] : array();
} }
/**
* @return bool|null
*/
public function getPreferStable() public function getPreferStable()
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
@ -274,6 +283,9 @@ class Locker
return isset($lockData['prefer-stable']) ? $lockData['prefer-stable'] : null; return isset($lockData['prefer-stable']) ? $lockData['prefer-stable'] : null;
} }
/**
* @return bool|null
*/
public function getPreferLowest() public function getPreferLowest()
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
@ -283,6 +295,9 @@ class Locker
return isset($lockData['prefer-lowest']) ? $lockData['prefer-lowest'] : null; return isset($lockData['prefer-lowest']) ? $lockData['prefer-lowest'] : null;
} }
/**
* @return array<string, string>
*/
public function getPlatformOverrides() public function getPlatformOverrides()
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
@ -290,6 +305,11 @@ class Locker
return isset($lockData['platform-overrides']) ? $lockData['platform-overrides'] : array(); return isset($lockData['platform-overrides']) ? $lockData['platform-overrides'] : array();
} }
/**
* @return string[][]
*
* @phpstan-return list<array<string, string>>
*/
public function getAliases() public function getAliases()
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
@ -297,6 +317,9 @@ class Locker
return isset($lockData['aliases']) ? $lockData['aliases'] : array(); return isset($lockData['aliases']) ? $lockData['aliases'] : array();
} }
/**
* @return array<string, mixed>
*/
public function getLockData() public function getLockData()
{ {
if (null !== $this->lockDataCache) { if (null !== $this->lockDataCache) {
@ -313,19 +336,21 @@ class Locker
/** /**
* Locks provided data into lockfile. * Locks provided data into lockfile.
* *
* @param array $packages array of packages * @param PackageInterface[] $packages array of packages
* @param mixed $devPackages array of dev packages or null if installed without --dev * @param PackageInterface[]|null $devPackages array of dev packages or null if installed without --dev
* @param array $platformReqs array of package name => constraint for required platform packages * @param array<string, string> $platformReqs array of package name => constraint for required platform packages
* @param mixed $platformDevReqs array of package name => constraint for dev-required platform packages * @param array<string, string> $platformDevReqs array of package name => constraint for dev-required platform packages
* @param array $aliases array of aliases * @param string[][] $aliases array of aliases
* @param string $minimumStability * @param string $minimumStability
* @param array $stabilityFlags * @param array<string, int> $stabilityFlags
* @param bool $preferStable * @param bool $preferStable
* @param bool $preferLowest * @param bool $preferLowest
* @param array $platformOverrides * @param array<string, string> $platformOverrides
* @param bool $write Whether to actually write data to disk, useful in tests and for --dry-run * @param bool $write Whether to actually write data to disk, useful in tests and for --dry-run
* *
* @return bool * @return bool
*
* @phpstan-param list<array<string, string>> $aliases
*/ */
public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags, $preferStable, $preferLowest, array $platformOverrides, $write = true) public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags, $preferStable, $preferLowest, array $platformOverrides, $write = true)
{ {
@ -386,6 +411,13 @@ class Locker
return false; return false;
} }
/**
* @param PackageInterface[] $packages
*
* @return mixed[][]
*
* @phpstan-return list<array<string, mixed>>
*/
private function lockPackages(array $packages) private function lockPackages(array $packages)
{ {
$locked = array(); $locked = array();

View File

@ -59,6 +59,7 @@ class Package extends BasePackage
/** @var bool */ /** @var bool */
protected $dev; protected $dev;
/** @var string */ /** @var string */
/** @phpstan-var 'stable'|'RC'|'beta'|'alpha'|'dev' */
protected $stability; protected $stability;
/** @var ?string */ /** @var ?string */
protected $notificationUrl; protected $notificationUrl;
@ -114,6 +115,8 @@ class Package extends BasePackage
/** /**
* @param string $type * @param string $type
*
* @return void
*/ */
public function setType($type) public function setType($type)
{ {
@ -138,6 +141,8 @@ class Package extends BasePackage
/** /**
* @param string $targetDir * @param string $targetDir
*
* @return void
*/ */
public function setTargetDir($targetDir) public function setTargetDir($targetDir)
{ {
@ -157,7 +162,9 @@ class Package extends BasePackage
} }
/** /**
* @param array $extra * @param mixed[] $extra
*
* @return void
*/ */
public function setExtra(array $extra) public function setExtra(array $extra)
{ {
@ -173,7 +180,9 @@ class Package extends BasePackage
} }
/** /**
* @param array $binaries * @param string[] $binaries
*
* @return void
*/ */
public function setBinaries(array $binaries) public function setBinaries(array $binaries)
{ {
@ -190,6 +199,8 @@ class Package extends BasePackage
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @return void
*/ */
public function setInstallationSource($type) public function setInstallationSource($type)
{ {
@ -206,6 +217,8 @@ class Package extends BasePackage
/** /**
* @param string $type * @param string $type
*
* @return void
*/ */
public function setSourceType($type) public function setSourceType($type)
{ {
@ -222,6 +235,8 @@ class Package extends BasePackage
/** /**
* @param string $url * @param string $url
*
* @return void
*/ */
public function setSourceUrl($url) public function setSourceUrl($url)
{ {
@ -238,6 +253,8 @@ class Package extends BasePackage
/** /**
* @param string $reference * @param string $reference
*
* @return void
*/ */
public function setSourceReference($reference) public function setSourceReference($reference)
{ {
@ -254,6 +271,8 @@ class Package extends BasePackage
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @return void
*/ */
public function setSourceMirrors($mirrors) public function setSourceMirrors($mirrors)
{ {
@ -278,6 +297,8 @@ class Package extends BasePackage
/** /**
* @param string $type * @param string $type
*
* @return void
*/ */
public function setDistType($type) public function setDistType($type)
{ {
@ -294,6 +315,8 @@ class Package extends BasePackage
/** /**
* @param string $url * @param string $url
*
* @return void
*/ */
public function setDistUrl($url) public function setDistUrl($url)
{ {
@ -310,6 +333,8 @@ class Package extends BasePackage
/** /**
* @param string $reference * @param string $reference
*
* @return void
*/ */
public function setDistReference($reference) public function setDistReference($reference)
{ {
@ -326,6 +351,8 @@ class Package extends BasePackage
/** /**
* @param string $sha1checksum * @param string $sha1checksum
*
* @return void
*/ */
public function setDistSha1Checksum($sha1checksum) public function setDistSha1Checksum($sha1checksum)
{ {
@ -342,6 +369,8 @@ class Package extends BasePackage
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @return void
*/ */
public function setDistMirrors($mirrors) public function setDistMirrors($mirrors)
{ {
@ -400,6 +429,8 @@ class Package extends BasePackage
* Set the releaseDate * Set the releaseDate
* *
* @param \DateTime $releaseDate * @param \DateTime $releaseDate
*
* @return void
*/ */
public function setReleaseDate(\DateTime $releaseDate) public function setReleaseDate(\DateTime $releaseDate)
{ {
@ -418,6 +449,8 @@ class Package extends BasePackage
* Set the required packages * Set the required packages
* *
* @param array<string, Link> $requires A set of package links * @param array<string, Link> $requires A set of package links
*
* @return void
*/ */
public function setRequires(array $requires) public function setRequires(array $requires)
{ {
@ -436,6 +469,8 @@ class Package extends BasePackage
* Set the conflicting packages * Set the conflicting packages
* *
* @param array<string, Link> $conflicts A set of package links * @param array<string, Link> $conflicts A set of package links
*
* @return void
*/ */
public function setConflicts(array $conflicts) public function setConflicts(array $conflicts)
{ {
@ -455,6 +490,8 @@ class Package extends BasePackage
* Set the provided virtual packages * Set the provided virtual packages
* *
* @param array<string, Link> $provides A set of package links * @param array<string, Link> $provides A set of package links
*
* @return void
*/ */
public function setProvides(array $provides) public function setProvides(array $provides)
{ {
@ -474,6 +511,8 @@ class Package extends BasePackage
* Set the packages this one replaces * Set the packages this one replaces
* *
* @param array<string, Link> $replaces A set of package links * @param array<string, Link> $replaces A set of package links
*
* @return void
*/ */
public function setReplaces(array $replaces) public function setReplaces(array $replaces)
{ {
@ -493,6 +532,8 @@ class Package extends BasePackage
* Set the recommended packages * Set the recommended packages
* *
* @param array<string, Link> $devRequires A set of package links * @param array<string, Link> $devRequires A set of package links
*
* @return void
*/ */
public function setDevRequires(array $devRequires) public function setDevRequires(array $devRequires)
{ {
@ -511,6 +552,8 @@ class Package extends BasePackage
* Set the suggested packages * Set the suggested packages
* *
* @param array<string, string> $suggests A set of package names/comments * @param array<string, string> $suggests A set of package names/comments
*
* @return void
*/ */
public function setSuggests(array $suggests) public function setSuggests(array $suggests)
{ {
@ -529,6 +572,10 @@ class Package extends BasePackage
* Set the autoload mapping * Set the autoload mapping
* *
* @param array $autoload Mapping of autoloading rules * @param array $autoload Mapping of autoloading rules
*
* @return void
*
* @phpstan-param array{psr-0?: array<string, string|string[]>, psr-4?: array<string, string|string[]>, classmap?: list<string>, files?: list<string>} $autoload
*/ */
public function setAutoload(array $autoload) public function setAutoload(array $autoload)
{ {
@ -547,6 +594,10 @@ class Package extends BasePackage
* Set the dev autoload mapping * Set the dev autoload mapping
* *
* @param array $devAutoload Mapping of dev autoloading rules * @param array $devAutoload Mapping of dev autoloading rules
*
* @return void
*
* @phpstan-param array{psr-0?: array<string, string|string[]>, psr-4?: array<string, string|string[]>, classmap?: list<string>, files?: list<string>} $devAutoload
*/ */
public function setDevAutoload(array $devAutoload) public function setDevAutoload(array $devAutoload)
{ {
@ -564,7 +615,9 @@ class Package extends BasePackage
/** /**
* Sets the list of paths added to PHP's include path. * Sets the list of paths added to PHP's include path.
* *
* @param array $includePaths List of directories. * @param string[] $includePaths List of directories.
*
* @return void
*/ */
public function setIncludePaths(array $includePaths) public function setIncludePaths(array $includePaths)
{ {
@ -583,6 +636,8 @@ class Package extends BasePackage
* Sets the notification URL * Sets the notification URL
* *
* @param string $notificationUrl * @param string $notificationUrl
*
* @return void
*/ */
public function setNotificationUrl($notificationUrl) public function setNotificationUrl($notificationUrl)
{ {
@ -599,6 +654,8 @@ class Package extends BasePackage
/** /**
* @param bool $defaultBranch * @param bool $defaultBranch
*
* @return void
*/ */
public function setIsDefaultBranch($defaultBranch) public function setIsDefaultBranch($defaultBranch)
{ {
@ -639,6 +696,8 @@ class Package extends BasePackage
* *
* @param string $version The package's normalized version * @param string $version The package's normalized version
* @param string $prettyVersion The package's non-normalized version * @param string $prettyVersion The package's non-normalized version
*
* @return void
*/ */
public function replaceVersion($version, $prettyVersion) public function replaceVersion($version, $prettyVersion)
{ {
@ -649,6 +708,17 @@ class Package extends BasePackage
$this->dev = $this->stability === 'dev'; $this->dev = $this->stability === 'dev';
} }
/**
* @param string|null $url
* @param mixed[]|null $mirrors
* @param string|null $ref
* @param string|null $type
* @param string $urlType
*
* @return string[]
*
* @phpstan-param list<array{url: string, preferred: bool}>|null $mirrors
*/
protected function getUrls($url, $mirrors, $ref, $type, $urlType) protected function getUrls($url, $mirrors, $ref, $type, $urlType)
{ {
if (!$url) { if (!$url) {

View File

@ -240,6 +240,8 @@ interface PackageInterface
* Returns the stability of this package: one of (dev, alpha, beta, RC, stable) * Returns the stability of this package: one of (dev, alpha, beta, RC, stable)
* *
* @return string * @return string
*
* @phpstan-return 'stable'|'RC'|'beta'|'alpha'|'dev'
*/ */
public function getStability(); public function getStability();

View File

@ -1292,7 +1292,7 @@ EOF;
->with(ScriptEvents::POST_AUTOLOAD_DUMP, false); ->with(ScriptEvents::POST_AUTOLOAD_DUMP, false);
$package = new RootPackage('root/a', '1.0', '1.0'); $package = new RootPackage('root/a', '1.0', '1.0');
$package->setAutoload(array('psr-0' => array('foo/bar/non/existing/'))); $package->setAutoload(array('psr-0' => array('Prefix' => 'foo/bar/non/existing/')));
$this->repository->expects($this->once()) $this->repository->expects($this->once())
->method('getCanonicalPackages') ->method('getCanonicalPackages')