-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drupal 10 compatibility check must respect --locked command parameter
Also introduce our own domain concept for an installed package repository.
- Loading branch information
Showing
8 changed files
with
183 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Domain/InstalledPackages/InstalledPackagesReadOnlyRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2023-2024 Dezső Biczó | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/mxr576/ddqg-composer-audit/LICENSE.md | ||
* | ||
*/ | ||
|
||
namespace mxr576\ddqgComposerAudit\Domain\InstalledPackages; | ||
|
||
use Composer\Package\PackageInterface; | ||
use Composer\Semver\Constraint\ConstraintInterface; | ||
|
||
interface InstalledPackagesReadOnlyRepository | ||
{ | ||
public function findByName(string $package_name, string|ConstraintInterface $version): ?PackageInterface; | ||
|
||
/** | ||
* @return \Composer\Package\PackageInterface[] | ||
*/ | ||
public function getPackages(): array; | ||
} |
118 changes: 118 additions & 0 deletions
118
src/Infrastructure/Composer/InstalledPackagesReadOnlyRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2023-2024 Dezső Biczó | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/mxr576/ddqg-composer-audit/LICENSE.md | ||
* | ||
*/ | ||
|
||
namespace mxr576\ddqgComposerAudit\Infrastructure\Composer; | ||
|
||
use Composer\Package\Locker; | ||
use Composer\Package\PackageInterface; | ||
use Composer\Package\RootPackageInterface; | ||
use Composer\Repository\InstalledRepository; | ||
use Composer\Repository\LockArrayRepository; | ||
use Composer\Repository\RepositoryUtils; | ||
use Composer\Semver\Constraint\ConstraintInterface; | ||
use mxr576\ddqgComposerAudit\Domain\InstalledPackages\InstalledPackagesReadOnlyRepository as InstalledPackagesReadOnlyRepositoryConstract; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InstalledPackagesReadOnlyRepository implements InstalledPackagesReadOnlyRepositoryConstract | ||
{ | ||
/** | ||
* @var callable(string, string|ConstraintInterface): ?PackageInterface | ||
*/ | ||
private $packageFinder; | ||
|
||
/** | ||
* @var callable(): PackageInterface[] | ||
*/ | ||
private $packageGetter; | ||
|
||
/** | ||
* Constructs a new object. | ||
* | ||
* @param callable(string $package_name, string|ConstraintInterface $version): ?PackageInterface $packageFinder | ||
* @param callable(): PackageInterface[] $packageGetter | ||
*/ | ||
private function __construct( | ||
$packageFinder, | ||
$packageGetter | ||
) { | ||
$this->packageGetter = $packageGetter; | ||
$this->packageFinder = $packageFinder; | ||
} | ||
|
||
public static function fromLocker(Locker $locker, bool $withDevDependencies): self | ||
{ | ||
if (!$locker->isLocked()) { | ||
throw new \InvalidArgumentException('Valid composer.json and composer.lock files are required to run this command with --locked'); | ||
} | ||
|
||
try { | ||
return self::fromLockedPackages($locker->getLockedRepository($withDevDependencies)); | ||
} catch (\RuntimeException $e) { | ||
throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e); | ||
} | ||
} | ||
|
||
public static function fromLockedPackages(LockArrayRepository $lockArrayRepository): self | ||
{ | ||
return new self( | ||
static fn (string $package_name, string|ConstraintInterface $version): ?PackageInterface => $lockArrayRepository->findPackage($package_name, $version), | ||
/** @return PackageInterface[] */ | ||
static fn (): array => $lockArrayRepository->getPackages(), | ||
); | ||
} | ||
|
||
public static function fromInstalledPackages(InstalledRepository $installedRepository): self | ||
{ | ||
return new self( | ||
static fn (string $package_name, string|ConstraintInterface $version): ?PackageInterface => $installedRepository->findPackage($package_name, $version), | ||
/** @return PackageInterface[] */ | ||
static fn (): array => $installedRepository->getPackages(), | ||
); | ||
} | ||
|
||
public static function fromInstalledRequiredPackages(InstalledRepository $installedRepository, RootPackageInterface $rootPackage): self | ||
{ | ||
return new self( | ||
static function (string $package_name, string|ConstraintInterface $version) use ( | ||
$installedRepository, $rootPackage | ||
): ?PackageInterface { | ||
$package = $installedRepository->findPackage($package_name, $version); | ||
if (null === $package) { | ||
return null; | ||
} | ||
|
||
$tmp = RepositoryUtils::filterRequiredPackages([$package], $rootPackage); | ||
if ([] === $tmp) { | ||
return null; | ||
} | ||
|
||
return $package; | ||
}, | ||
/** @return PackageInterface[] */ | ||
static fn (): array => $installedRepository->getPackages(), | ||
); | ||
} | ||
|
||
public function findByName(string $package_name, string|ConstraintInterface $version): ?PackageInterface | ||
{ | ||
return ($this->packageFinder)($package_name, $version); | ||
} | ||
|
||
public function getPackages(): array | ||
{ | ||
return ($this->packageGetter)(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters