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

View File

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

View File

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

View File

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

View File

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

View File

@ -1292,7 +1292,7 @@ EOF;
->with(ScriptEvents::POST_AUTOLOAD_DUMP, false);
$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())
->method('getCanonicalPackages')