From 25d062ccb49d3bd16c87b0ad1a5f935649460638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Scho=CC=88nthal?= Date: Fri, 22 Nov 2013 10:24:10 +0100 Subject: [PATCH] some minor refactorings --- src/Composer/Command/HomeCommand.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Composer/Command/HomeCommand.php b/src/Composer/Command/HomeCommand.php index 376d99050..b1d3aac76 100644 --- a/src/Composer/Command/HomeCommand.php +++ b/src/Composer/Command/HomeCommand.php @@ -29,8 +29,9 @@ use Symfony\Component\Process\Exception\InvalidArgumentException; */ class HomeCommand extends Command { - protected $versionParser; - + /** + * {@inheritDoc} + */ protected function configure() { $this @@ -45,18 +46,20 @@ EOT ); } + /** + * {@inheritDoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { $repo = $this->initializeRepo($input, $output); $package = $this->getPackage($repo, $input->getArgument('package')); - /** @var CompletePackageInterface $package */ - if ($package instanceof CompletePackageInterface && filter_var($package->getSourceUrl(), FILTER_VALIDATE_URL)) { + if (!$package instanceof CompletePackageInterface) { + throw new InvalidArgumentException('package not found'); + } elseif (filter_var($package->getSourceUrl(), FILTER_VALIDATE_URL)) { $this->openBrowser($package->getSourceUrl()); - } elseif ($package instanceof CompletePackageInterface) { - $this->getIO()->write('no valid source-url given for ' . $package->getName()); } else { - throw new InvalidArgumentException('package not found'); + $output->writeln('no valid source-url given for ' . $package->getName()); } } @@ -92,18 +95,19 @@ EOT */ private function openBrowser($url) { + if (defined('PHP_WINDOWS_VERSION_MAJOR')) { + return passthru('start "web" explorer "' . $url . '"'); + } + passthru('which xdg-open', $linux); passthru('which open', $osx); - $windows = defined('PHP_WINDOWS_VERSION_MAJOR'); if (0 === $linux) { passthru('xdg-open ' . $url); } elseif (0 === $osx) { passthru('open ' . $url); - } elseif (true === $windows) { - passthru('start "web" explorer "' . $url . '"'); } else { - $this->getIO()->write('no suitable browser opening tool found, open yourself: ' . $url); + $this->getIO()->write('no suitable browser opening command found, open yourself: ' . $url); } }