Skip to content

Commit

Permalink
Prefer caret over tilde when removing overlapping
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Oct 5, 2023
1 parent 3ecb33b commit 1e1f011
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
18 changes: 12 additions & 6 deletions src/Vendor/Composer/VersionConstraintNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -199,10 +199,16 @@ 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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 1e1f011

Please sign in to comment.