From 3c5c1a4e7d51e87b28e7b52d48f66becd48a6047 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 5 Oct 2023 10:09:02 +0100 Subject: [PATCH] Prefer caret over tilde when removing overlapping --- .../Composer/VersionConstraintNormalizer.php | 19 +++++++--- .../Or/VersionRange/Mixed/normalized.json | 32 ++++++++++++++-- .../Or/VersionRange/Mixed/original.json | 37 +++++++++++++++++-- 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/src/Vendor/Composer/VersionConstraintNormalizer.php b/src/Vendor/Composer/VersionConstraintNormalizer.php index beb2a73e..cb34d590 100644 --- a/src/Vendor/Composer/VersionConstraintNormalizer.php +++ b/src/Vendor/Composer/VersionConstraintNormalizer.php @@ -85,10 +85,10 @@ private function normalizeVersionConstraint(string $versionConstraint): string $versionConstraint = self::replaceWildcardWithTilde($versionConstraint); $versionConstraint = self::replaceTildeWithCaret($versionConstraint); $versionConstraint = self::removeDuplicateVersionConstraints($versionConstraint); - $versionConstraint = self::removeOverlappingVersionConstraints($versionConstraint); $versionConstraint = self::removeUselessInlineAliases($versionConstraint); + $versionConstraint = self::sortVersionConstraints($versionConstraint); - return self::sortVersionConstraints($versionConstraint); + return self::removeOverlappingVersionConstraints($versionConstraint); } private static function trim(string $versionConstraint): string @@ -199,10 +199,17 @@ private static function removeOverlappingVersionConstraints(string $versionConst continue; } - if (Semver\Semver::satisfies(\ltrim($a, '^~'), $b)) { - $orConstraints[$i] = null; - } elseif (Semver\Semver::satisfies(\ltrim($b, '^~'), $a)) { - $orConstraints[$j] = null; + if (Semver\Semver::satisfies(\ltrim($a, '^~'), $b) || Semver\Semver::satisfies(\ltrim($b, '^~'), $a)) { + if ('^' === $a[0]) { + $orConstraints[$j] = null; + } elseif ('^' === $b[0]) { + $orConstraints[$i] = null; + } elseif ('~' === $a[0]) { + $orConstraints[$j] = null; + } elseif ('~' === $b[0 + ]) { + $orConstraints[$i] = null; + } } } } diff --git a/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/normalized.json b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/normalized.json index 14a5d16f..f5f3ccda 100644 --- a/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/normalized.json +++ b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/normalized.json @@ -1,9 +1,33 @@ { "homepage": "https://getcomposer.org/doc/articles/versions.md#version-range", "value-contains-packages-and-version-constraints": { - "combination-or-version-range-mixed/01": "^1.2", - "combination-or-version-range-mixed/02": "^1.2", - "combination-or-version-range-mixed/03": "^1.2", - "combination-or-version-range-mixed/04": "1.2.1 || ~1.2.3" + "combination-or-version-range-mixed/01-fixed-and-caret": "^1", + "combination-or-version-range-mixed/02-fixed-and-caret": "^1.2", + "combination-or-version-range-mixed/03-fixed-and-caret-zero": "^1.2.0", + "combination-or-version-range-mixed/04-fixed-and-caret-non-zero": "^1.2.1", + "combination-or-version-range-mixed/05-fixed-and-caret-same": "^1.2.3", + "combination-or-version-range-mixed/06-fixed-and-caret-greater": "1.2.3 || ^1.2.5", + "combination-or-version-range-mixed/07-fixed-and-tilde": "^1", + "combination-or-version-range-mixed/08-fixed-and-tilde": "^1.2", + "combination-or-version-range-mixed/09-fixed-and-tilde-zero": "~1.2.0", + "combination-or-version-range-mixed/10-fixed-and-tilde-non-zero": "~1.2.2", + "combination-or-version-range-mixed/11-fixed-and-tilde-same": "~1.2.3", + "combination-or-version-range-mixed/12-fixed-and-tilde-greater": "1.2.3 || ~1.2.5", + "combination-or-version-range-mixed/13-fixed-and-wildcard": "^1.0", + "combination-or-version-range-mixed/14-fixed-and-wildcard": "~1.2.0", + "combination-or-version-range-mixed/15-tilde-and-caret": "^1.2", + "combination-or-version-range-mixed/16-wildcard-and-caret": "^1.2", + "combination-or-version-range-mixed/17-tilde-and-wildcard": "~1.2.0", + "combination-or-version-range-mixed/18-tilde-and-wildcard-and-caret": "^1.2", + "combination-or-version-range-mixed/19-fixed-and-tilde-and-caret": "^1.2", + "combination-or-version-range-mixed/20-fixed-and-wildcard-and-caret": "^1.2", + "combination-or-version-range-mixed/21-fixed-and-tilde-and-wildcard": "~1.2.0", + "combination-or-version-range-mixed/22-fixed-and-tilde-and-wildcard-and-caret": "^1.2", + "combination-or-version-range-mixed/23-fixed-and-tilde-and-caret": "^1.2.3", + "combination-or-version-range-mixed/24-tilde-and-caret-and-fixed": "^1.2.3", + "combination-or-version-range-mixed/25-caret-and-fixed-and-tilde": "^1.2.3", + "combination-or-version-range-mixed/26-caret-and-tilde-and-fixed": "^1.2.3", + "combination-or-version-range-mixed/27-tilde-and-fixed-and-caret": "^1.2.3", + "combination-or-version-range-mixed/28-fixed-and-caret-and-tilde": "^1.2.3" } } diff --git a/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/original.json b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/original.json index 918922cb..2efc3cfb 100644 --- a/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/original.json +++ b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Combination/Or/VersionRange/Mixed/original.json @@ -1,9 +1,38 @@ { "homepage": "https://getcomposer.org/doc/articles/versions.md#version-range", "value-contains-packages-and-version-constraints": { - "combination-or-version-range-mixed/01": "1.2.3 || ^1.2", - "combination-or-version-range-mixed/02": "~1.2.3 || ^1.2", - "combination-or-version-range-mixed/03": "1.2.3 || ~1.2.1 || ^1.2", - "combination-or-version-range-mixed/04": "~1.2.3 || 1.2.1 || 1.2.4" + "combination-or-version-range-mixed/01-fixed-and-caret": "1.2.3 || ^1", + "combination-or-version-range-mixed/02-fixed-and-caret": "1.2.3 || ^1.2", + "combination-or-version-range-mixed/03-fixed-and-caret-zero": "1.2.3 || ^1.2.0", + "combination-or-version-range-mixed/04-fixed-and-caret-non-zero": "1.2.3 || ^1.2.1", + "combination-or-version-range-mixed/05-fixed-and-caret-same": "1.2.3 || ^1.2.3", + "combination-or-version-range-mixed/06-fixed-and-caret-greater": "1.2.3 || ^1.2.5", + + "combination-or-version-range-mixed/07-fixed-and-tilde": "1.2.3 || ~1", + "combination-or-version-range-mixed/08-fixed-and-tilde": "1.2.3 || ~1.2", + "combination-or-version-range-mixed/09-fixed-and-tilde-zero": "1.2.3 || ~1.2.0", + "combination-or-version-range-mixed/10-fixed-and-tilde-non-zero": "1.2.3 || ~1.2.2", + "combination-or-version-range-mixed/11-fixed-and-tilde-same": "1.2.3 || ~1.2.3", + "combination-or-version-range-mixed/12-fixed-and-tilde-greater": "1.2.3 || ~1.2.5", + + "combination-or-version-range-mixed/13-fixed-and-wildcard": "1.2.3 || 1.*", + "combination-or-version-range-mixed/14-fixed-and-wildcard": "1.2.3 || 1.2.*", + + "combination-or-version-range-mixed/15-tilde-and-caret": "~1.2.3 || ^1.2", + "combination-or-version-range-mixed/16-wildcard-and-caret": "1.2.* || ^1.2", + "combination-or-version-range-mixed/17-tilde-and-wildcard": "~1.2.3 || 1.2.*", + "combination-or-version-range-mixed/18-tilde-and-wildcard-and-caret": "~1.2.3 || 1.2.* || ^1.2", + + "combination-or-version-range-mixed/19-fixed-and-tilde-and-caret": "1.2.6 || ~1.2.3 || ^1.2", + "combination-or-version-range-mixed/20-fixed-and-wildcard-and-caret": "1.2.6 || 1.2.* || ^1.2", + "combination-or-version-range-mixed/21-fixed-and-tilde-and-wildcard": "1.2.6 || ~1.2.3 || 1.2.*", + "combination-or-version-range-mixed/22-fixed-and-tilde-and-wildcard-and-caret": "1.2.6 || ~1.2.3 || 1.2.* || ^1.2", + + "combination-or-version-range-mixed/23-fixed-and-tilde-and-caret": "1.2.3 || ~1.2.3 || ^1.2.3", + "combination-or-version-range-mixed/24-tilde-and-caret-and-fixed": "~1.2.3 || ^1.2.3 || 1.2.3", + "combination-or-version-range-mixed/25-caret-and-fixed-and-tilde": "^1.2.3 || 1.2.3 || ~1.2.3", + "combination-or-version-range-mixed/26-caret-and-tilde-and-fixed": "^1.2.3 || ~1.2.3 || 1.2.3", + "combination-or-version-range-mixed/27-tilde-and-fixed-and-caret": "~1.2.3 || 1.2.3 || ^1.2.3", + "combination-or-version-range-mixed/28-fixed-and-caret-and-tilde": "1.2.3 || ^1.2.3 || ~1.2.3" } }