Fix licenses command summary to count all licenses of a package

main
Jordi Boggiano 2 years ago
parent 8756f54da0
commit 6ea5b84bd9
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -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,13 +124,16 @@ 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';
if (!isset($usedLicenses[$licenseName])) {
$usedLicenses[$licenseName] = 0;
$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]++;
}
$usedLicenses[$licenseName]++;
}
// Sort licenses so that the most used license will appear first

Loading…
Cancel
Save