Skip to content

Commit

Permalink
Refactor SemverUtil::class stability normalization logic. (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Sep 24, 2024
1 parent dfc2523 commit 1acdd78
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 286 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Change Log

## 0.1.3 Under development

- Enh #87: Refactor `SemverUtil::class` stability normalization logic (@terabytesoftw)

## 0.1.2 June 10, 2024

- Bug #64: Update docs, `composer.lock` and change directory in `Solver.php` (@terabytesoftw)
Expand Down
484 changes: 244 additions & 240 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/Asset/AssetManagerFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ final class AssetManagerFinder
private array $managers = [];

/**
* Constructor.
*
* @psalm-param AssetManagerInterface[] $managers The asset managers
*/
public function __construct(array $managers = [])
Expand Down
2 changes: 0 additions & 2 deletions src/Asset/AssetPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ final class AssetPackage implements AssetPackageInterface
protected array $package = [];

/**
* Constructor.
*
* @param RootPackageInterface $rootPackage The composer root package
* @param JsonFile $jsonFile The json file
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Config
private array $cacheEnv = [];

/**
* Constructor.
*
* @param array $config The config.
* @param array $defaults The default values.
*/
Expand Down
55 changes: 27 additions & 28 deletions src/Converter/SemverUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,33 @@ private static function cleanVersion(string $version, array $matches): array

$matches = [];
preg_match('/^[a-z]+/', $end, $matches);
$type = isset($matches[0]) ? VersionParser::normalizeStability($matches[0]) : '';
$type = isset($matches[0]) ? self::normalizeStability($matches[0]) : '';
$end = substr($end, \strlen($type));

return [$type, $version, $end];
}

/**
* Normalize the stability.
*
* @param string $stability The stability.
*
* @return string The normalized stability.
*/
private static function normalizeStability(string $stability): string
{
$stability = strtolower($stability);

return match ($stability) {
'a' => 'alpha',
'b', 'pre' => 'beta',
'build' => 'patch',
'rc' => 'RC',
'dev', 'snapshot' => 'dev',
default => VersionParser::normalizeStability($stability),
};
}

/**
* Match the version.
*
Expand All @@ -140,34 +161,12 @@ private static function cleanVersion(string $version, array $matches): array
*/
private static function matchVersion(string $version, string $type): array
{
$patchVersion = true;

switch ($type) {
case 'dev':
case 'snapshot':
$type = 'dev';
$patchVersion = false;
$type = match ($type) {
'dev', 'snapshot' => 'dev',
default => \in_array($type, ['alpha', 'beta', 'RC'], true) ? $type : 'patch',
};

break;

case 'a':
$type = 'alpha';

break;

case 'b':
case 'pre':
$type = 'beta';

break;

default:
if (!\in_array($type, ['alpha', 'beta', 'RC'], true)) {
$type = 'patch';
}

break;
}
$patchVersion = !\in_array($type, ['dev'], true);

$version .= $type;

Expand Down
2 changes: 0 additions & 2 deletions src/Event/AbstractSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
abstract class AbstractSolveEvent extends Event
{
/**
* Constructor.
*
* @param string $name The event name.
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
Expand Down
2 changes: 0 additions & 2 deletions src/Event/GetAssetsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
final class GetAssetsEvent extends AbstractSolveEvent
{
/**
* Constructor.
*
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
* @param array $assets The map of asset package name and the asset package path.
Expand Down
2 changes: 0 additions & 2 deletions src/Event/PostSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
final class PostSolveEvent extends AbstractSolveEvent
{
/**
* Constructor.
*
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
* @param int $runResult The process result of asset manager execution.
Expand Down
2 changes: 0 additions & 2 deletions src/Event/PreSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
final class PreSolveEvent extends AbstractSolveEvent
{
/**
* Constructor.
*
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Fallback/ComposerFallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ final class ComposerFallback implements FallbackInterface
protected array $lock = [];

/**
* Constructor.
*
* @param Composer $composer The composer.
* @param IOInterface $io The IO.
* @param Config $config The config.
Expand Down
2 changes: 0 additions & 2 deletions src/Solver/Solver.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
final class Solver implements SolverInterface
{
/**
* Constructor.
*
* @param AssetManagerInterface $assetManager The asset manager instance.
* @param Config $config The config instance.
* @param FallbackInterface|null $composerFallback The composer fallback instance.
Expand Down

0 comments on commit 1acdd78

Please sign in to comment.