From 668655c21a99a5016d6a959d0df4bb5e86fe4e9f Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Tue, 23 Jun 2020 19:43:27 +0200 Subject: [PATCH 1/5] Rename variable for clarity --- src/Composer/Command/LicensesCommand.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index c9a099f26..9140aa48d 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -96,9 +96,9 @@ EOT break; case 'json': - $dependencies = array(); + $usedLicenses = array(); foreach ($packages as $package) { - $dependencies[$package->getPrettyName()] = array( + $usedLicenses[$package->getPrettyName()] = array( 'version' => $package->getFullPrettyVersion(), 'license' => $package->getLicense(), ); @@ -108,23 +108,23 @@ EOT 'name' => $root->getPrettyName(), 'version' => $root->getFullPrettyVersion(), 'license' => $root->getLicense(), - 'dependencies' => $dependencies, + 'dependencies' => $usedLicenses, ))); break; case 'summary': - $dependencies = array(); + $usedLicenses = array(); foreach ($packages as $package) { $license = $package->getLicense(); $licenseName = $license[0]; - if (!isset($dependencies[$licenseName])) { - $dependencies[$licenseName] = 0; + if (!isset($usedLicenses[$licenseName])) { + $usedLicenses[$licenseName] = 0; } - $dependencies[$licenseName]++; + $usedLicenses[$licenseName]++; } $rows = array(); - foreach ($dependencies as $usedLicense => $numberOfDependencies) { + foreach ($usedLicenses as $usedLicense => $numberOfDependencies) { $rows[] = array($usedLicense, $numberOfDependencies); } From ec6e05d55fd783757baa3f33cb904e10d861632b Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Tue, 23 Jun 2020 19:44:12 +0200 Subject: [PATCH 2/5] Sort licenses so that the most used license will appear first --- src/Composer/Command/LicensesCommand.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index 9140aa48d..ce1e3a390 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -123,6 +123,9 @@ EOT $usedLicenses[$licenseName]++; } + // Sort licenses so that the most used license will appear first + arsort($dependencies, SORT_NUMERIC); + $rows = array(); foreach ($usedLicenses as $usedLicense => $numberOfDependencies) { $rows[] = array($usedLicense, $numberOfDependencies); From 73a721c7e5fb959b507790e8a08611e067f49e3d Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Tue, 23 Jun 2020 19:45:26 +0200 Subject: [PATCH 3/5] Add the missing summary format to command-line help text --- src/Composer/Command/LicensesCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index ce1e3a390..2147e3aef 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -34,7 +34,7 @@ class LicensesCommand extends BaseCommand ->setName('licenses') ->setDescription('Shows information about licenses of dependencies.') ->setDefinition(array( - new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'), + new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text, json or summary', 'text'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'), )) ->setHelp( From d5d956df4d9d8356d8192972f3a33399e704a5a3 Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Tue, 23 Jun 2020 19:50:27 +0200 Subject: [PATCH 4/5] Use correct variable name --- src/Composer/Command/LicensesCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index 2147e3aef..dd0de2d8a 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -124,7 +124,7 @@ EOT } // Sort licenses so that the most used license will appear first - arsort($dependencies, SORT_NUMERIC); + arsort($usedLicenses, SORT_NUMERIC); $rows = array(); foreach ($usedLicenses as $usedLicense => $numberOfDependencies) { From eea7564c9ec428cd82bd4068ab8fcddc5d938779 Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Wed, 24 Jun 2020 07:28:22 +0200 Subject: [PATCH 5/5] Revert accidental rename of $dependencies variable in unrelated code branch --- src/Composer/Command/LicensesCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index dd0de2d8a..ec0c38acc 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -96,9 +96,9 @@ EOT break; case 'json': - $usedLicenses = array(); + $dependencies = array(); foreach ($packages as $package) { - $usedLicenses[$package->getPrettyName()] = array( + $dependencies[$package->getPrettyName()] = array( 'version' => $package->getFullPrettyVersion(), 'license' => $package->getLicense(), ); @@ -108,7 +108,7 @@ EOT 'name' => $root->getPrettyName(), 'version' => $root->getFullPrettyVersion(), 'license' => $root->getLicense(), - 'dependencies' => $usedLicenses, + 'dependencies' => $dependencies, ))); break;