Fix abandoned package list JSON serialization (#11647)
Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>pull/11664/head
parent
1f9f91cfea
commit
755de04bf5
|
@ -86,7 +86,10 @@ class Auditor
|
|||
if ($ignoredAdvisories !== []) {
|
||||
$json['ignored-advisories'] = $ignoredAdvisories;
|
||||
}
|
||||
$json['abandoned'] = $abandonedPackages;
|
||||
$json['abandoned'] = array_reduce($abandonedPackages, static function(array $carry, CompletePackageInterface $package): array {
|
||||
$carry[$package->getPrettyName()] = $package->getReplacementPackage();
|
||||
return $carry;
|
||||
}, []);
|
||||
|
||||
$io->write(JsonFile::encode($json));
|
||||
|
||||
|
@ -127,11 +130,11 @@ class Auditor
|
|||
|
||||
/**
|
||||
* @param array<PackageInterface> $packages
|
||||
* @return array<PackageInterface>
|
||||
* @return array<CompletePackageInterface>
|
||||
*/
|
||||
private function filterAbandonedPackages(array $packages): array
|
||||
{
|
||||
return array_filter($packages, function (PackageInterface $pkg) {
|
||||
return array_filter($packages, static function (PackageInterface $pkg) {
|
||||
return $pkg instanceof CompletePackageInterface && $pkg->isAbandoned();
|
||||
});
|
||||
}
|
||||
|
@ -305,7 +308,7 @@ class Auditor
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array<PackageInterface> $packages
|
||||
* @param array<CompletePackageInterface> $packages
|
||||
* @param self::FORMAT_PLAIN|self::FORMAT_TABLE $format
|
||||
*/
|
||||
private function outputAbandonedPackages(IOInterface $io, array $packages, string $format): void
|
||||
|
@ -314,10 +317,6 @@ class Auditor
|
|||
|
||||
if ($format === self::FORMAT_PLAIN) {
|
||||
foreach ($packages as $pkg) {
|
||||
if (!$pkg instanceof CompletePackageInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$replacement = $pkg->getReplacementPackage() !== null
|
||||
? 'Use '.$pkg->getReplacementPackage().' instead'
|
||||
: 'No replacement was suggested';
|
||||
|
@ -341,10 +340,6 @@ class Auditor
|
|||
->setColumnMaxWidth(1, 80);
|
||||
|
||||
foreach ($packages as $pkg) {
|
||||
if (!$pkg instanceof CompletePackageInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$replacement = $pkg->getReplacementPackage() !== null ? $pkg->getReplacementPackage() : 'none';
|
||||
$table->addRow([$this->getPackageNameWithLink($pkg), $replacement]);
|
||||
}
|
||||
|
|
|
@ -122,6 +122,26 @@ Found 2 abandoned packages:
|
|||
| vendor/abandoned2 | none |
|
||||
+-------------------+----------------------------------------------------------------------------------+',
|
||||
];
|
||||
|
||||
yield 'abandoned packages fails with json format' => [
|
||||
'data' => [
|
||||
'packages' => [
|
||||
$abandonedWithReplacement,
|
||||
$abandonedNoReplacement,
|
||||
],
|
||||
'warningOnly' => false,
|
||||
'abandoned' => Auditor::ABANDONED_FAIL,
|
||||
'format' => Auditor::FORMAT_JSON,
|
||||
],
|
||||
'expected' => 2,
|
||||
'output' => '{
|
||||
"advisories": [],
|
||||
"abandoned": {
|
||||
"vendor/abandoned": "foo/bar",
|
||||
"vendor/abandoned2": null
|
||||
}
|
||||
}',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue