1
0
Fork 0

Fix licenses command summary to count all licenses of a package

pull/10516/head
Jordi Boggiano 2022-02-16 12:26:49 +01:00
parent 8756f54da0
commit 6ea5b84bd9
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 10 additions and 7 deletions

View File

@ -93,7 +93,7 @@ EOT
$tableStyle->setVerticalBorderChar('');
}
$tableStyle->setCellRowContentFormat('%s ');
$table->setHeaders(array('Name', 'Version', 'License'));
$table->setHeaders(array('Name', 'Version', 'Licenses'));
foreach ($packages as $package) {
$table->addRow(array(
$package->getPrettyName(),
@ -124,14 +124,17 @@ EOT
case 'summary':
$usedLicenses = array();
foreach ($packages as $package) {
$license = $package instanceof CompletePackageInterface ? $package->getLicense() : array();
$licenseName = array_key_exists(0, $license) ? $license[0] : 'none';
$licenses = $package instanceof CompletePackageInterface ? $package->getLicense() : array();
if (count($licenses) === 0) {
$licenses[] = 'none';
}
foreach ($licenses as $licenseName) {
if (!isset($usedLicenses[$licenseName])) {
$usedLicenses[$licenseName] = 0;
}
$usedLicenses[$licenseName]++;
}
}
// Sort licenses so that the most used license will appear first
arsort($usedLicenses, SORT_NUMERIC);