From d2f37b5680858435fc292e2a0502deb4a33c2d06 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 13 Sep 2022 15:08:37 +0200 Subject: [PATCH] Add hint as to why a package is suggested to be added to require-dev, fixes #11040 --- src/Composer/Command/RequireCommand.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 83c33aed6..5b4e1e3de 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -233,19 +233,26 @@ EOT } $pkg = PackageSorter::getMostCurrentVersion($this->getRepos()->findPackages($name)); - if ($pkg instanceof CompletePackageInterface && count(array_intersect($devTags, array_map('strtolower', $pkg->getKeywords()))) > 0) { - $devPackages[] = $name; + if ($pkg instanceof CompletePackageInterface) { + $pkgDevTags = array_intersect($devTags, array_map('strtolower', $pkg->getKeywords())); + if (count($pkgDevTags) > 0) { + $devPackages[] = $pkgDevTags; + } } } if (count($devPackages) === count($requirements)) { $plural = count($requirements) > 1 ? 's' : ''; $plural2 = count($requirements) > 1 ? 'are' : 'is'; - $io->warning('The package'.$plural.' you required '.$plural2.' recommended to be placed in require-dev but you did not use --dev.'); + $plural3 = count($requirements) > 1 ? 'they are' : 'it is'; + $pkgDevTags = array_unique(array_merge(...$devPackages)); + $io->warning('The package'.$plural.' you required '.$plural2.' recommended to be placed in require-dev (because '.$plural3.' tagged as "'.implode('", "', $pkgDevTags).'") but you did not use --dev.'); if ($io->askConfirmation('Do you want to re-run the command with --dev? [yes]? ')) { $input->setOption('dev', true); } } + + unset($devPackages, $pkgDevTags); } $requireKey = $input->getOption('dev') ? 'require-dev' : 'require';