Skip to content

Commit 685add7

Browse files
committed
Refactor the BasePackage::$stabilities into a constant
1 parent 07aee7e commit 685add7

23 files changed

+80
-54
lines changed

composer.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Composer/Command/ArchiveCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected function selectPackage(IOInterface $io, string $packageName, ?string $
169169
}
170170

171171
if ($version !== null && Preg::isMatchStrictGroups('{@(stable|RC|beta|alpha|dev)$}i', $version, $match)) {
172-
$minStability = $match[1];
172+
$minStability = VersionParser::normalizeStability($match[1]);
173173
$version = (string) substr($version, 0, -strlen($match[0]));
174174
}
175175

src/Composer/Command/ConfigCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static function ($vals) {
664664
}],
665665
'minimum-stability' => [
666666
static function ($val): bool {
667-
return isset(BasePackage::$stabilities[VersionParser::normalizeStability($val)]);
667+
return isset(BasePackage::STABILITIES[VersionParser::normalizeStability($val)]);
668668
},
669669
static function ($val): string {
670670
return VersionParser::normalizeStability($val);

src/Composer/Command/CreateProjectCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ protected function installRootPackage(InputInterface $input, IOInterface $io, Co
375375
if (null === $stability) {
376376
if (null === $packageVersion) {
377377
$stability = 'stable';
378-
} elseif (Preg::isMatchStrictGroups('{^[^,\s]*?@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $packageVersion, $match)) {
378+
} elseif (Preg::isMatchStrictGroups('{^[^,\s]*?@('.implode('|', array_keys(BasePackage::STABILITIES)).')$}i', $packageVersion, $match)) {
379379
$stability = $match[1];
380380
} else {
381381
$stability = VersionParser::parseStability($packageVersion);
@@ -384,8 +384,8 @@ protected function installRootPackage(InputInterface $input, IOInterface $io, Co
384384

385385
$stability = VersionParser::normalizeStability($stability);
386386

387-
if (!isset(BasePackage::$stabilities[$stability])) {
388-
throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::$stabilities)));
387+
if (!isset(BasePackage::STABILITIES[$stability])) {
388+
throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::STABILITIES)));
389389
}
390390

391391
$composer = $this->createComposerInstance($input, $io, $config->all(), $disablePlugins, $disableScripts);

src/Composer/Command/InitCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function configure()
6161
new InputOption('homepage', null, InputOption::VALUE_REQUIRED, 'Homepage of package'),
6262
new InputOption('require', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Package to require with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"', null, $this->suggestAvailablePackageInclPlatform()),
6363
new InputOption('require-dev', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Package to require for development with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"', null, $this->suggestAvailablePackageInclPlatform()),
64-
new InputOption('stability', 's', InputOption::VALUE_REQUIRED, 'Minimum stability (empty or one of: '.implode(', ', array_keys(BasePackage::$stabilities)).')'),
64+
new InputOption('stability', 's', InputOption::VALUE_REQUIRED, 'Minimum stability (empty or one of: '.implode(', ', array_keys(BasePackage::STABILITIES)).')'),
6565
new InputOption('license', 'l', InputOption::VALUE_REQUIRED, 'License of package'),
6666
new InputOption('repository', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Add custom repositories, either by URL or using JSON arrays'),
6767
new InputOption('autoload', 'a', InputOption::VALUE_REQUIRED, 'Add PSR-4 autoload mapping. Maps your package\'s namespace to the provided directory. (Expects a relative path, e.g. src/)'),
@@ -364,10 +364,10 @@ static function ($value) use ($minimumStability) {
364364
return $minimumStability;
365365
}
366366

367-
if (!isset(BasePackage::$stabilities[$value])) {
367+
if (!isset(BasePackage::STABILITIES[$value])) {
368368
throw new \InvalidArgumentException(
369369
'Invalid minimum stability "'.$value.'". Must be empty or one of: '.
370-
implode(', ', array_keys(BasePackage::$stabilities))
370+
implode(', ', array_keys(BasePackage::STABILITIES))
371371
);
372372
}
373373

src/Composer/Command/PackageDiscoveryTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Composer\Filter\PlatformRequirementFilter\IgnoreAllPlatformRequirementFilter;
1717
use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory;
1818
use Composer\IO\IOInterface;
19+
use Composer\Package\BasePackage;
1920
use Composer\Package\CompletePackageInterface;
2021
use Composer\Package\PackageInterface;
2122
use Composer\Package\Version\VersionParser;
@@ -52,6 +53,9 @@ protected function getRepos(): CompositeRepository
5253
return $this->repos;
5354
}
5455

56+
/**
57+
* @param key-of<BasePackage::STABILITIES>|null $minimumStability
58+
*/
5559
private function getRepositorySet(InputInterface $input, ?string $minimumStability = null): RepositorySet
5660
{
5761
$key = $minimumStability ?? 'default';
@@ -64,6 +68,9 @@ private function getRepositorySet(InputInterface $input, ?string $minimumStabili
6468
return $this->repositorySets[$key];
6569
}
6670

71+
/**
72+
* @return key-of<BasePackage::STABILITIES>
73+
*/
6774
private function getMinimumStability(InputInterface $input): string
6875
{
6976
if ($input->hasOption('stability')) { // @phpstan-ignore-line as InitCommand does have this option but not all classes using this trait do

src/Composer/Command/ShowCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ private function findLatestPackage(PackageInterface $package, Composer $composer
14541454
$stability = $composer->getPackage()->getMinimumStability();
14551455
$flags = $composer->getPackage()->getStabilityFlags();
14561456
if (isset($flags[$name])) {
1457-
$stability = array_search($flags[$name], BasePackage::$stabilities, true);
1457+
$stability = array_search($flags[$name], BasePackage::STABILITIES, true);
14581458
}
14591459

14601460
$bestStability = $stability;

src/Composer/DependencyResolver/DefaultPolicy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(bool $preferStable = false, bool $preferLowest = fal
5353
public function versionCompare(PackageInterface $a, PackageInterface $b, string $operator): bool
5454
{
5555
if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) {
56-
return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB];
56+
return BasePackage::STABILITIES[$stabA] < BasePackage::STABILITIES[$stabB];
5757
}
5858

5959
// dev versions need to be compared as branches via matchSpecific's special treatment, the rest can be optimized with compiling matcher

src/Composer/DependencyResolver/PoolBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class PoolBuilder
4040
{
4141
/**
4242
* @var int[]
43-
* @phpstan-var array<string, BasePackage::STABILITY_*>
43+
* @phpstan-var array<key-of<BasePackage::STABILITIES>, BasePackage::STABILITY_*>
4444
*/
4545
private $acceptableStabilities;
4646
/**
@@ -153,7 +153,7 @@ class PoolBuilder
153153

154154
/**
155155
* @param int[] $acceptableStabilities array of stability => BasePackage::STABILITY_* value
156-
* @phpstan-param array<string, BasePackage::STABILITY_*> $acceptableStabilities
156+
* @phpstan-param array<key-of<BasePackage::STABILITIES>, BasePackage::STABILITY_*> $acceptableStabilities
157157
* @param int[] $stabilityFlags an array of package name => BasePackage::STABILITY_* value
158158
* @phpstan-param array<string, BasePackage::STABILITY_*> $stabilityFlags
159159
* @param array[] $rootAliases

src/Composer/Installer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ private function createRepositorySet(bool $forUpdate, PlatformRepository $platfo
910910
$this->fixedRootPackage->setRequires([]);
911911
$this->fixedRootPackage->setDevRequires([]);
912912

913-
$stabilityFlags[$this->package->getName()] = BasePackage::$stabilities[VersionParser::parseStability($this->package->getVersion())];
913+
$stabilityFlags[$this->package->getName()] = BasePackage::STABILITIES[VersionParser::parseStability($this->package->getVersion())];
914914

915915
$repositorySet = new RepositorySet($minimumStability, $stabilityFlags, $rootAliases, $this->package->getReferences(), $rootRequires, $this->temporaryConstraints);
916916
$repositorySet->addRepository(new RootPackageRepository($this->fixedRootPackage));

0 commit comments

Comments
 (0)