Skip to content

Commit

Permalink
Normalise extension requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Oct 24, 2024
1 parent 0b0ef26 commit cac2432
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Vendor/Composer/PackageHashNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function normalize(Json $json): Json
continue;
}

$packages = self::mergeDuplicateExtensions($packages);
$decoded->{$name} = self::sortPackages($packages);
}

Expand Down Expand Up @@ -114,4 +115,38 @@ private static function sortPackages(array $packages): array

return $packages;
}

/**
* This code is adopted from composer/composer (originally licensed under MIT by Nils Adermann <[email protected]>
* and Jordi Boggiano <[email protected]>).
*
* @see https://github.com/composer/composer/blob/2.8.1/src/Composer/Repository/PlatformRepository.php#L682
*
* @param array<string, string> $packages
*
* @return array<string, string>
*/
private static function mergeDuplicateExtensions($packages): array
{
foreach ($packages as $name => $value) {

Check warning on line 131 in src/Vendor/Composer/PackageHashNormalizer.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ */ private static function mergeDuplicateExtensions($packages) : array { - foreach ($packages as $name => $value) { + foreach (array() as $name => $value) { if (!\str_starts_with($name, 'ext-')) { continue; }
if (!\str_starts_with($name, 'ext-')) {

Check warning on line 132 in src/Vendor/Composer/PackageHashNormalizer.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ private static function mergeDuplicateExtensions($packages) : array { foreach ($packages as $name => $value) { - if (!\str_starts_with($name, 'ext-')) { + if (\str_starts_with($name, 'ext-')) { continue; } $newName = \str_replace(' ', '-', \strtolower($name));
continue;

Check warning on line 133 in src/Vendor/Composer/PackageHashNormalizer.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ { foreach ($packages as $name => $value) { if (!\str_starts_with($name, 'ext-')) { - continue; + break; } $newName = \str_replace(' ', '-', \strtolower($name)); if ($name === $newName) {
}

$newName = \str_replace(' ', '-', \strtolower($name));

if ($name === $newName) {
continue;
}

if (isset($packages[$newName])) {
$value .= '||' . $packages[$newName];

Check warning on line 143 in src/Vendor/Composer/PackageHashNormalizer.php

View check run for this annotation

Codecov / codecov/patch

src/Vendor/Composer/PackageHashNormalizer.php#L142-L143

Added lines #L142 - L143 were not covered by tests
}

$packages[$newName] = $value;
unset($packages[$name]);

Check warning on line 147 in src/Vendor/Composer/PackageHashNormalizer.php

View check run for this annotation

Codecov / codecov/patch

src/Vendor/Composer/PackageHashNormalizer.php#L146-L147

Added lines #L146 - L147 were not covered by tests
}

return $packages;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"homepage": "https://github.com/ergebnis/composer-normalize/issues/1388",
"value-contains-packages-and-version-constraints": {
"ext-extension-name": "1 || 2 || 3 || 4 || 5 || 6"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://github.com/ergebnis/composer-normalize/issues/1388",
"value-contains-packages-and-version-constraints": {
"ext-extension name": "1",
"ext-Extension Name": "2",
"ext-EXTENSION NAME": "3",
"ext-extension-name": "4",
"ext-Extension-Name": "5",
"ext-EXTENSION-NAME": "6"
}
}

0 comments on commit cac2432

Please sign in to comment.