Moved duplicated table render code to a new method in BaseCommand

main
Simon Berger 4 years ago
parent 86ff43d8b9
commit 687f886d56

@ -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();
}
}

@ -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);
}
/**

@ -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);
}
}

@ -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 <fabien.potencier@gmail.com>
@ -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;
}

Loading…
Cancel
Save