Browse Source

Move loop-independent code outside of loop

Alexander Schwenn 8 years ago
parent
commit
64139ba327
1 changed files with 15 additions and 14 deletions
  1. 15 14
      src/Composer/Command/ShowCommand.php

+ 15 - 14
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);