From 64139ba32743023701e7d9d2fa79a05325d0d627 Mon Sep 17 00:00:00 2001 From: Alexander Schwenn Date: Sun, 5 Mar 2017 22:49:06 +0100 Subject: [PATCH] Move loop-independent code outside of loop --- src/Composer/Command/ShowCommand.php | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 5a6f99fd4..b002ba4fd 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -232,6 +232,21 @@ EOT $packageListFilter = $this->getRootRequires(); } + list($width) = $this->getApplication()->getTerminalDimensions(); + if (null === $width) { + // In case the width is not detected, we're probably running the command + // outside of a real terminal, use space without a limit + $width = PHP_INT_MAX; + } + if (Platform::isWindows()) { + $width--; + } + + if ($input->getOption('path') && null === $composer) { + $io->writeError('No composer.json found in the current directory, disabling "path" option'); + $input->setOption('path', false); + } + foreach ($repos as $repo) { if ($repo === $platformRepo) { $type = 'platform'; @@ -296,20 +311,6 @@ EOT $nameLength = max($nameLength, strlen($package)); } } - list($width) = $this->getApplication()->getTerminalDimensions(); - if (null === $width) { - // In case the width is not detected, we're probably running the command - // outside of a real terminal, use space without a limit - $width = PHP_INT_MAX; - } - if (Platform::isWindows()) { - $width--; - } - - if ($input->getOption('path') && null === $composer) { - $io->writeError('No composer.json found in the current directory, disabling "path" option'); - $input->setOption('path', false); - } $writePath = !$input->getOption('name-only') && $input->getOption('path'); $writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width);