diff --git a/src/Composer/Command/DependsCommand.php b/src/Composer/Command/DependsCommand.php index f695487ff..82ff5e02d 100644 --- a/src/Composer/Command/DependsCommand.php +++ b/src/Composer/Command/DependsCommand.php @@ -25,6 +25,8 @@ use Symfony\Component\Console\Output\OutputInterface; */ class DependsCommand extends Command { + protected $linkTypes = array('require', 'recommend', 'suggest'); + protected function configure() { $this @@ -32,7 +34,7 @@ class DependsCommand extends Command ->setDescription('Shows which packages depend on the given package') ->setDefinition(array( new InputArgument('package', InputArgument::REQUIRED, 'Package to inspect'), - new InputOption('link-type', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Link types to show', array('requires', 'recommends', 'suggests')) + new InputOption('link-type', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Link types to show', $this->linkTypes) )) ->setHelp(<<getRepositoryManager()->getRepositories(); $types = $input->getOption('link-type'); + foreach ($repos as $repository) { foreach ($repository->getPackages() as $package) { foreach ($types as $type) { - foreach ($package->{'get'.$type}() as $link) { + $type = rtrim($type, 's'); + if (!in_array($type, $this->linkTypes)) { + throw new \InvalidArgumentException('Unexpected link type: '.$type.', valid types: '.implode(', ', $this->linkTypes)); + } + foreach ($package->{'get'.$type.'s'}() as $link) { if ($link->getTarget() === $needle) { if ($verbose) { $references[] = array($type, $package, $link);