From 687f886d56094d18b10dd64a3b428d4dafc40338 Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Thu, 3 Sep 2020 15:56:04 +0200 Subject: [PATCH] Moved duplicated table render code to a new method in BaseCommand --- src/Composer/Command/BaseCommand.php | 15 +++++++++++++++ src/Composer/Command/BaseDependencyCommand.php | 13 +------------ src/Composer/Command/CheckPlatformReqsCommand.php | 14 +------------- src/Composer/Command/RunScriptCommand.php | 12 +----------- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/Composer/Command/BaseCommand.php b/src/Composer/Command/BaseCommand.php index 8c45899cf..d4c90a196 100644 --- a/src/Composer/Command/BaseCommand.php +++ b/src/Composer/Command/BaseCommand.php @@ -21,6 +21,7 @@ use Composer\IO\NullIO; use Composer\Plugin\PreCommandRunEvent; use Composer\Package\Version\VersionParser; use Composer\Plugin\PluginEvents; +use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Command\Command; @@ -202,4 +203,18 @@ abstract class BaseCommand extends Command return $parser->parseNameVersionPairs($requirements); } + + protected function renderTable(array $table, OutputInterface $output) + { + $renderer = new Table($output); + $renderer->setStyle('compact'); + $rendererStyle = $renderer->getStyle(); + if (method_exists($rendererStyle, 'setVerticalBorderChars')) { + $rendererStyle->setVerticalBorderChars(''); + } else { + $rendererStyle->setVerticalBorderChar(''); + } + $rendererStyle->setCellRowContentFormat('%s '); + $renderer->setRows($table)->render(); + } } diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index 2ac82a764..2ca92fcef 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -24,7 +24,6 @@ use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Composer\Package\Version\VersionParser; -use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -178,17 +177,7 @@ class BaseDependencyCommand extends BaseCommand $table = array_merge($rows, $table); } while (!empty($results)); - // Render table - $renderer = new Table($output); - $renderer->setStyle('compact'); - $rendererStyle = $renderer->getStyle(); - if (method_exists($rendererStyle, 'setVerticalBorderChars')) { - $rendererStyle->setVerticalBorderChars(''); - } else { - $rendererStyle->setVerticalBorderChar(''); - } - $rendererStyle->setCellRowContentFormat('%s '); - $renderer->setRows($table)->render(); + $this->renderTable($table, $output); } /** diff --git a/src/Composer/Command/CheckPlatformReqsCommand.php b/src/Composer/Command/CheckPlatformReqsCommand.php index c80884444..773b97160 100644 --- a/src/Composer/Command/CheckPlatformReqsCommand.php +++ b/src/Composer/Command/CheckPlatformReqsCommand.php @@ -15,7 +15,6 @@ namespace Composer\Command; use Composer\Package\Link; use Composer\Package\PackageInterface; use Composer\Semver\Constraint\Constraint; -use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -169,18 +168,7 @@ EOT $status, ); } - $table = array_merge($rows, $table); - // Render table - $renderer = new Table($output); - $renderer->setStyle('compact'); - $rendererStyle = $renderer->getStyle(); - if (method_exists($rendererStyle, 'setVerticalBorderChars')) { - $rendererStyle->setVerticalBorderChars(''); - } else { - $rendererStyle->setVerticalBorderChar(''); - } - $rendererStyle->setCellRowContentFormat('%s '); - $renderer->setRows($table)->render(); + $this->renderTable($rows, $output); } } diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php index 1d1b6be76..8747af501 100644 --- a/src/Composer/Command/RunScriptCommand.php +++ b/src/Composer/Command/RunScriptCommand.php @@ -19,7 +19,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Helper\Table; /** * @author Fabien Potencier @@ -130,16 +129,7 @@ EOT $table[] = array(' '.$name, $description); } - $renderer = new Table($output); - $renderer->setStyle('compact'); - $rendererStyle = $renderer->getStyle(); - if (method_exists($rendererStyle, 'setVerticalBorderChars')) { - $rendererStyle->setVerticalBorderChars(''); - } else { - $rendererStyle->setVerticalBorderChar(''); - } - $rendererStyle->setCellRowContentFormat('%s '); - $renderer->setRows($table)->render(); + $this->renderTable($table, $output); return 0; }