From 9bc2ee02e4a994522fc6761faa191e14921b569a Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Thu, 18 Feb 2016 22:26:44 +0100 Subject: [PATCH] Process feedback, code cleanup. --- src/Composer/Command/DependsCommand.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Composer/Command/DependsCommand.php b/src/Composer/Command/DependsCommand.php index 32441bb0c..bc39d0c3e 100644 --- a/src/Composer/Command/DependsCommand.php +++ b/src/Composer/Command/DependsCommand.php @@ -15,7 +15,7 @@ namespace Composer\Command; use Composer\DependencyResolver\Pool; use Composer\Package\Link; use Composer\Package\PackageInterface; -use Composer\Package\RootPackage; +use Composer\Package\RootPackageInterface; use Composer\Repository\ArrayRepository; use Composer\Repository\CompositeRepository; use Composer\Repository\PlatformRepository; @@ -90,13 +90,15 @@ EOT $constraint = null; } $matchInvert = $input->getOption('invert-match-constraint'); + + // Parse rendering options $renderTree = $input->getOption('tree'); $recursive = $renderTree || $input->getOption('recursive'); // Resolve dependencies $results = $this->getDependents($needle, $repository->getPackages(), $constraint, $matchInvert, $recursive); if (empty($results)) { - $extra = isset($constraint) ? sprintf(' in versions %smatching %s', $matchInvert ? 'not ' : '', $textConstraint) : ''; + $extra = (null !== $constraint) ? sprintf(' in versions %smatching %s', $matchInvert ? 'not ' : '', $textConstraint) : ''; $this->getIO()->writeError(sprintf('There is no installed package depending on "%s"%s', $needle, $extra)); } elseif ($renderTree) { @@ -172,7 +174,7 @@ EOT } /** - * @param string $needle The package to inspect. + * @param string|string[] $needle The package(s) to inspect. * @param PackageInterface[] $packages List of installed packages. * @param ConstraintInterface|null $constraint Optional constraint to filter by. * @param bool $invert Whether to invert matches on the previous constraint. @@ -184,14 +186,13 @@ EOT $needles = is_array($needle) ? $needle : array($needle); $results = array(); - /** - * Loop over all currently installed packages. - */ + // Loop over all currently installed packages. foreach ($packages as $package) { - // Retrieve all requirements, but dev only for the root package - $links = $package->getRequires(); - $links += $package->getReplaces(); - if ($package instanceof RootPackage) { + // Requirements and replaces are both considered valid reasons for a package to be installed + $links = $package->getRequires() + $package->getReplaces(); + + // Require-dev is only relevant for the root package + if ($package instanceof RootPackageInterface) { $links += $package->getDevRequires(); }