<commit_before><?php

namespace Leezy\PheanstalkBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Pheanstalk_Exception;

class StatsTubeCommand extends ContainerAwareCommand
{
    /**
     * @see Command
     */
    protected function configure()
    {
        $this
            ->setName('leezy:pheanstalk:stats-tube')
            ->addArgument('tube', InputArgument::OPTIONAL, 'Tube to get stats.', null)
            ->addArgument('pheanstalk', InputArgument::OPTIONAL, 'Pheanstalk name.', 'default')
            ->setDescription('Gives statistical information about the specified tube if it exists.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $pheanstalkName = $input->getArgument('pheanstalk');

        $pheanstalkLocator = $this->getContainer()->get('leezy.pheanstalk.pheanstalk_locator');
        $pheanstalk = $pheanstalkLocator->getPheanstalk($pheanstalkName);

        if (null === $pheanstalk) {
            $output->writeln('Pheanstalk not found : <error>' . $pheanstalkName . '</error>');

            return;
        }

        if (!$pheanstalk->getPheanstalk()->getConnection()->isServiceListening()) {
            $output->writeln('Pheanstalk not connected : <error>' . $pheanstalkName . '</error>');

            return;
        }

        $output->writeln('Pheanstalk : <info>' . $pheanstalkName . '</info>');

        try {
            $tubes = array();

            // if a tube argument is given, only consider that tube. If not, get stats for all tubes
            if ($tube = $input->getArgument('tube')) {
                $tubes[] = $tube;
            } else {
                $tubes = $pheanstalk->listTubes();
            };

            $whiteline = false;
            foreach ($tubes as $tube) {
                // fetch stats for each tube
                $stats = (array) $pheanstalk->statsTube($tube);

                if (count($stats) === 0 ) {
                    $output->writeln('Tube : <error>' . $tube . '</error>');
                    $output->writeln('<info>0 stats.</info>');
                } else {
                    // only add a whiteline if we are past the first tube (for BC)
                    if ($whiteline) {
                        $output->writeln('');
                    }

                    foreach ($stats as $key => $information) {
                        $output->writeln('- <info>' . $key . '</info> : ' . $information);
                    }
                }

                $whiteline = true;
            }<commit_msg>Small changes based on comments by @armetiz<commit_after><?php

namespace Leezy\PheanstalkBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Pheanstalk_Exception;

class StatsTubeCommand extends ContainerAwareCommand
{
    /**
     * @see Command
     */
    protected function configure()
    {
        $this
            ->setName('leezy:pheanstalk:stats-tube')
            ->addArgument('tube', InputArgument::OPTIONAL, 'Tube to get stats for.', null)
            ->addArgument('pheanstalk', InputArgument::OPTIONAL, 'Pheanstalk name.', null)
            ->setDescription('Gives statistical information about a specified tube, or about all tubes.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $pheanstalkName = $input->getArgument('pheanstalk');

        $pheanstalkLocator = $this->getContainer()->get('leezy.pheanstalk.pheanstalk_locator');
        /** @var \Pheanstalk_Pheanstalk $pheanstalk */
        $pheanstalk = $pheanstalkLocator->getPheanstalk($pheanstalkName);

        if (null === $pheanstalkName) {
            $pheanstalkName = 'default';
        }

        if (null === $pheanstalk) {
            $output->writeln('Pheanstalk not found : <error>' . $pheanstalkName . '</error>');

            return;
        }

        if (!$pheanstalk->getPheanstalk()->getConnection()->isServiceListening()) {
            $output->writeln('Pheanstalk not connected : <error>' . $pheanstalkName . '</error>');

            return;
        }

        $output->writeln('Pheanstalk : <info>' . $pheanstalkName . '</info>');

        try {
            $tubes = array();

            // if a tube argument is given, only consider that tube. If not, get stats for all tubes
            if ($tube = $input->getArgument('tube')) {
                $tubes[] = $tube;
            } else {
                $tubes = $pheanstalk->listTubes();
            };

            $whiteline = false;
            foreach ($tubes as $tube) {
                // fetch stats for each tube
                $stats = $pheanstalk->statsTube($tube);

                if (count($stats) === 0 ) {
                    $output->writeln('Tube : <error>' . $tube . '</error>');
                    $output->writeln('<info>0 stats.</info>');
                } else {
                    // only add a whiteline if we are past the first tube (for BC)
                    if ($whiteline) {
                        $output->writeln('Tube:');
                    }

                    foreach ($stats as $key => $information) {
                        $output->writeln('- <info>' . $key . '</info> : ' . $information);
                    }
                }

                $whiteline = true;
            }
{'fraction_non_alphanumeric': 0.13564111621335218, 'fraction_numerical': 0.0007064641469445425, 'mean_word_length': 1.9402907580477673, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 71, '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': '6617535', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1512, 'n_words': 337}