<commit_before><?php

namespace Skillberto\CommandHandler;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpProcess;
use Symfony\Component\Process\Process;

class CommandHandler
{
    protected $commands = array();

    protected $skipped = array();

    protected $error = null;

    protected $output;

    protected $php;

    /**
     * @param OutputInterface $outputInterface
     */
    public function __construct(OutputInterface $outputInterface, $php = true)
    {
        $this->output = $outputInterface;

        $this->php = $php;
    }

    /**
     * @param $commandString
     * @return $this
     */
    public function add($commandString)
    {
        $command = $this->createCommand()->add($commandString);

        $this->commands[] = $command;

        return $this;
    }

    /**
     * @param  string $commandString
     * @return $this
     */
    public function addSkippable($commandString)
    {
        $command = $this->createCommand()->add($commandString)->skippable();

        $this->commands[] = $command;

        return $this;
    }

    /**
     * @return $this
     */
    public function execute()
    {
        $output = $this->output;

        foreach ($this->commands as $command) {

            $this->info($command, 'Executing');

            $p = $this->createProcess($command->get());
            $p->setTimeout(null);
            $p->run(function($type, $data) use ($output) {
                $output->write($data, false, OutputInterface::OUTPUT_RAW);
            });

            if (!$p->isSuccessful()){
                if ($command->isSkippable() === false) {
                    $this->error = $command;

                    return $this;
                } else {
                    $this->skipped[] = $command;
                }
            }

            $this->output->writeln("");
        }

        return $this;
    }

    /**
     * @return bool
     */
    public function hasSkipped()
    {
        return (count($this->skipped) > 0) ? true : false;
    }

    /**
     * @return bool
     */
    public function hasError()
    {
        return $this->error ? true : false;
    }

    public function getSkippedMessages()
    {
        foreach ($this->skipped as $command) {
            $this->info($command, 'Skipped');
        }
    }

    /**
     * @return string
     */
    public function getErrorMessage()
    {
        $this->info($this->error, 'Error');
    }

    /**
     * @param Command $command
     * @param string  $info
     */
    protected function info($command, $info)
    {
        $this->output->writeln(sprintf('<info>%s:</info> %s', $info, $command->get()));<commit_msg>ignore empty error and skippable messages<commit_after><?php

namespace Skillberto\CommandHandler;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpProcess;
use Symfony\Component\Process\Process;

class CommandHandler
{
    protected $commands = array();

    protected $skipped = array();

    protected $error = null;

    protected $output;

    protected $php;

    /**
     * @param OutputInterface $outputInterface
     */
    public function __construct(OutputInterface $outputInterface, $php = true)
    {
        $this->output = $outputInterface;

        $this->php = $php;
    }

    /**
     * @param $commandString
     * @return $this
     */
    public function add($commandString)
    {
        $command = $this->createCommand()->add($commandString);

        $this->commands[] = $command;

        return $this;
    }

    /**
     * @param  string $commandString
     * @return $this
     */
    public function addSkippable($commandString)
    {
        $command = $this->createCommand()->add($commandString)->skippable();

        $this->commands[] = $command;

        return $this;
    }

    /**
     * @return $this
     */
    public function execute()
    {
        $output = $this->output;

        foreach ($this->commands as $command) {

            $this->info($command, 'Executing');

            $p = $this->createProcess($command->get());
            $p->setTimeout(null);
            $p->run(function($type, $data) use ($output) {
                $output->write($data, false, OutputInterface::OUTPUT_RAW);
            });

            if (!$p->isSuccessful()){
                if ($command->isSkippable() === false) {
                    $this->error = $command;

                    return $this;
                } else {
                    $this->skipped[] = $command;
                }
            }

            $this->output->writeln("");
        }

        return $this;
    }

    /**
     * @return bool
     */
    public function hasSkipped()
    {
        return (count($this->skipped) > 0) ? true : false;
    }

    /**
     * @return bool
     */
    public function hasError()
    {
        return $this->error ? true : false;
    }

    public function getSkippedMessages()
    {
        if (! $this->hasSkipped()) {
            return;
        }

        foreach ($this->skipped as $command) {
            $this->info($command, 'Skipped');
        }
    }

    /**
     * @return string
     */
    public function getErrorMessage()
    {
        if (! $this->hasError()) {
            return;
        }

        $this->info($this->error, 'Error');
    }

    /**
     * @param Command $command
     * @param string  $info
     */
    protected function info($command, $info)
    {
        $this->output->writeln(sprintf('<info>%s:</info> %s', $info, $command->get()));
{'fraction_non_alphanumeric': 0.15185318459877653, 'fraction_numerical': 0.0003598416696653472, 'mean_word_length': 1.830448065173116, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 75, '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': '1631756', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1565, 'n_words': 312}