1
0
Fork 0

Use more BasePackage instead of PackageInterface

pull/10177/head
Jordi Boggiano 2021-10-17 14:43:34 +02:00
parent b209816056
commit a6f1e803b1
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
7 changed files with 44 additions and 28 deletions

View File

@ -13,7 +13,7 @@
namespace Composer\DependencyResolver;
use Composer\Package\Package;
use Composer\Package\PackageInterface;
use Composer\Package\BasePackage;
use Composer\Repository\LockArrayRepository;
use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Constraint\MatchAllConstraint;
@ -44,11 +44,11 @@ class Request
protected $lockedRepository;
/** @var array<string, ConstraintInterface> */
protected $requires = array();
/** @var array<string, PackageInterface> */
/** @var array<string, BasePackage> */
protected $fixedPackages = array();
/** @var array<string, PackageInterface> */
/** @var array<string, BasePackage> */
protected $lockedPackages = array();
/** @var array<string, PackageInterface> */
/** @var array<string, BasePackage> */
protected $fixedLockedPackages = array();
/** @var string[] */
protected $updateAllowList = array();
@ -79,7 +79,7 @@ class Request
* This is used for platform packages which cannot be modified by Composer. A rule enforcing their installation is
* generated for dependency resolution. Partial updates with dependencies cannot in any way modify these packages.
*/
public function fixPackage(PackageInterface $package)
public function fixPackage(BasePackage $package)
{
$this->fixedPackages[spl_object_hash($package)] = $package;
}
@ -94,7 +94,7 @@ class Request
* if nothing requires these packages they will be removed. Additionally in a partial update these packages can be
* unlocked, meaning other versions can be installed if explicitly requested as part of the update.
*/
public function lockPackage(PackageInterface $package)
public function lockPackage(BasePackage $package)
{
$this->lockedPackages[spl_object_hash($package)] = $package;
}
@ -106,13 +106,13 @@ class Request
* removal of any packages. At the same time lock packages there cannot simply be marked fixed, as error reporting
* would then report them as platform packages, so this still marks them as locked packages at the same time.
*/
public function fixLockedPackage(PackageInterface $package)
public function fixLockedPackage(BasePackage $package)
{
$this->fixedPackages[spl_object_hash($package)] = $package;
$this->fixedLockedPackages[spl_object_hash($package)] = $package;
}
public function unlockPackage(PackageInterface $package)
public function unlockPackage(BasePackage $package)
{
unset($this->lockedPackages[spl_object_hash($package)]);
}
@ -156,7 +156,7 @@ class Request
}
/**
* @return array<string, PackageInterface>
* @return array<string, BasePackage>
*/
public function getFixedPackages()
{
@ -166,13 +166,13 @@ class Request
/**
* @return bool
*/
public function isFixedPackage(PackageInterface $package)
public function isFixedPackage(BasePackage $package)
{
return isset($this->fixedPackages[spl_object_hash($package)]);
}
/**
* @return array<string, PackageInterface>
* @return array<string, BasePackage>
*/
public function getLockedPackages()
{
@ -182,13 +182,13 @@ class Request
/**
* @return bool
*/
public function isLockedPackage(PackageInterface $package)
public function isLockedPackage(BasePackage $package)
{
return isset($this->lockedPackages[spl_object_hash($package)]) || isset($this->fixedLockedPackages[spl_object_hash($package)]);
}
/**
* @return array<string, PackageInterface>
* @return array<string, BasePackage>
*/
public function getFixedOrLockedPackages()
{
@ -198,7 +198,7 @@ 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<int|string, PackageInterface>
* @return array<int|string, BasePackage>
*/
public function getPresentMap($packageIds = false)
{
@ -218,7 +218,7 @@ class Request
}
/**
* @return PackageInterface[]
* @return BasePackage[]
*/
public function getFixedPackagesMap()
{

View File

@ -13,7 +13,7 @@
namespace Composer\DependencyResolver;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Composer\Package\BasePackage;
use Composer\Repository\PlatformRepository;
/**
@ -36,7 +36,7 @@ class Solver
protected $watchGraph;
/** @var Decisions */
protected $decisions;
/** @var PackageInterface[] */
/** @var BasePackage[] */
protected $fixedMap;
/** @var int */

View File

@ -84,13 +84,13 @@ class Installer
protected $config;
/**
* @var RootPackageInterface
* @var RootPackageInterface&BasePackage
*/
protected $package;
// TODO can we get rid of the below and just use the package itself?
/**
* @var RootPackageInterface
* @var RootPackageInterface&BasePackage
*/
protected $fixedRootPackage;
@ -187,7 +187,7 @@ class Installer
*
* @param IOInterface $io
* @param Config $config
* @param RootPackageInterface $package
* @param RootPackageInterface&BasePackage $package
* @param DownloadManager $downloadManager
* @param RepositoryManager $repositoryManager
* @param Locker $locker
@ -845,6 +845,7 @@ class Installer
}
/**
* @param RootPackageInterface&BasePackage $rootPackage
* @return Request
*/
private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo, LockArrayRepository $lockedRepository = null)

View File

@ -190,8 +190,8 @@ class DefaultPolicyTest extends TestCase
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '2.0'));
$packageA->setProvides(array(new Link('A', 'X', new Constraint('==', '1.0'), Link::TYPE_PROVIDE)));
$packageB->setProvides(array(new Link('B', 'X', new Constraint('==', '1.0'), Link::TYPE_PROVIDE)));
$packageA->setProvides(array('x' => new Link('A', 'X', new Constraint('==', '1.0'), Link::TYPE_PROVIDE)));
$packageB->setProvides(array('x' => new Link('B', 'X', new Constraint('==', '1.0'), Link::TYPE_PROVIDE)));
$this->repositorySet->addRepository($this->repo);
@ -210,7 +210,7 @@ class DefaultPolicyTest extends TestCase
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '2.0'));
$packageB->setReplaces(array(new Link('B', 'A', new Constraint('==', '1.0'), Link::TYPE_REPLACE)));
$packageB->setReplaces(array('a' => new Link('B', 'A', new Constraint('==', '1.0'), Link::TYPE_REPLACE)));
$this->repositorySet->addRepository($this->repo);
@ -230,8 +230,8 @@ class DefaultPolicyTest extends TestCase
$this->repo->addPackage($packageB = $this->getPackage('vendor-b/replacer', '1.0'));
$this->repo->addPackage($packageA = $this->getPackage('vendor-a/replacer', '1.0'));
$packageA->setReplaces(array(new Link('vendor-a/replacer', 'vendor-a/package', new Constraint('==', '1.0'), Link::TYPE_REPLACE)));
$packageB->setReplaces(array(new Link('vendor-b/replacer', 'vendor-a/package', new Constraint('==', '1.0'), Link::TYPE_REPLACE)));
$packageA->setReplaces(array('vendor-a/package' => new Link('vendor-a/replacer', 'vendor-a/package', new Constraint('==', '1.0'), Link::TYPE_REPLACE)));
$packageB->setReplaces(array('vendor-a/package' => new Link('vendor-b/replacer', 'vendor-a/package', new Constraint('==', '1.0'), Link::TYPE_REPLACE)));
$this->repositorySet->addRepository($this->repo);

View File

@ -26,6 +26,7 @@ use Composer\Repository\ArrayRepository;
use Composer\Repository\RepositoryManager;
use Composer\Repository\InstalledArrayRepository;
use Composer\Package\RootPackageInterface;
use Composer\Package\BasePackage;
use Composer\Package\Link;
use Composer\Package\Locker;
use Composer\Test\Mock\FactoryMock;
@ -58,6 +59,7 @@ class InstallerTest extends TestCase
/**
* @dataProvider provideInstaller
* @param RootPackageInterface&BasePackage $rootPackage
*/
public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options)
{

View File

@ -31,8 +31,8 @@ class InstalledRepositoryTest extends TestCase
$arrayRepoTwo->addPackage($bar = $this->getPackage('bar', '1'));
$arrayRepoTwo->addPackage($bar2 = $this->getPackage('bar', '2'));
$foo->setReplaces(array(new Link('foo', 'provided', new MatchAllConstraint())));
$bar2->setProvides(array(new Link('bar', 'provided', new MatchAllConstraint())));
$foo->setReplaces(array('provided' => new Link('foo', 'provided', new MatchAllConstraint())));
$bar2->setProvides(array('provided' => new Link('bar', 'provided', new MatchAllConstraint())));
$repo = new InstalledRepository(array($arrayRepoOne, $arrayRepoTwo));

View File

@ -22,6 +22,10 @@ use Composer\Util\Silencer;
use Symfony\Component\Process\ExecutableFinder;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\BasePackage;
use Composer\Package\RootPackage;
use Composer\Package\RootAliasPackage;
use Composer\Package\CompletePackage;
use Composer\Package\CompleteAliasPackage;
abstract class TestCase extends PolyfillTestCase
{
@ -74,7 +78,16 @@ abstract class TestCase extends PolyfillTestCase
return $constraint;
}
protected function getPackage($name, $version, $class = 'Composer\Package\Package')
/**
* @template PackageClass of PackageInterface
*
* @param string $class FQCN to be instantiated
*
* @return CompletePackage|CompleteAliasPackage|RootPackage|RootAliasPackage
*
* @phpstan-param class-string<PackageClass> $class
*/
protected function getPackage($name, $version, $class = 'Composer\Package\CompletePackage')
{
$normVersion = self::getVersionParser()->normalize($version);