<commit_before><?php namespace MODX\Shell\Command\Extra;

use MODX\Shell\Command\BaseCmd;
use Symfony\Component\Console\Helper\Table;

/**
 * A command to list commands added by third party components
 */
class Components extends BaseCmd
{
    const MODX = true;

    protected $name = 'extra:components';
    protected $description = 'List commands added by third party components';

    protected function process()
    {
        $components = $this->getApplication()->getComponentsWithCommands();
        foreach ($components as $ns => $data) {
            $service = $this->getApplication()->getExtraService($data);
            if ($service && method_exists($service, 'getCommands')) {
                $table = $this->prepareTable();

                $this->info($ns);
                $classes = $service->getCommands();
                foreach ($classes as $class) {
                    $table->addRow($this->getTableRow($class));
                }
                $table->render();
            } else {
                $this->error($ns . ' is registered but does not implement a "getCommand" method.');
            }
        }
    }

    /**
     * Prepare a table instance to be rendered
     *
     * @return Table
     */
    protected function prepareTable()
    {
        $table = new Table($this->output);
        $table->setHeaders(array(<commit_msg>Send output when no extra commands have been registered by components<commit_after><?php namespace MODX\Shell\Command\Extra;

use MODX\Shell\Command\BaseCmd;
use Symfony\Component\Console\Helper\Table;

/**
 * A command to list commands added by third party components
 */
class Components extends BaseCmd
{
    const MODX = true;

    protected $name = 'extra:components';
    protected $description = 'List commands added by third party components';

    protected function process()
    {
        $components = $this->getApplication()->getComponentsWithCommands();
        if (empty($components)) {
            $this->info('No additional commands registered by components');
            return;
        }
        foreach ($components as $ns => $data) {
            $service = $this->getApplication()->getExtraService($data);
            if ($service && method_exists($service, 'getCommands')) {
                $table = $this->prepareTable();

                $this->info($ns);
                $classes = $service->getCommands();
                foreach ($classes as $class) {
                    $table->addRow($this->getTableRow($class));
                }
                $table->render();
            } else {
                $this->error($ns . ' is registered but does not implement a "getCommand" method.');
            }
        }
    }

    /**
     * Prepare a table instance to be rendered
     *
     * @return Table
     */
    protected function prepareTable()
    {
        $table = new Table($this->output);
        $table->setHeaders(array(
{'fraction_non_alphanumeric': 0.12594113620807665, 'fraction_numerical': 0.0, 'mean_word_length': 2.1396348012889366, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1189132', 'n_tokens_mistral': 743, 'n_tokens_neox': 727, 'n_words': 198}