<commit_before><?php
/**
 * Humbug
 *
 * @category   Humbug
 * @package    Humbug
 * @copyright  Copyright (c) 2015 <NAME> (http://blog.astrumfutura.com)
 * @license    https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
 */

namespace Humbug\Renderer;

use Symfony\Component\Console\Output\OutputInterface;

class Text
{

    protected $output;

    protected $progressCount = 0;

    protected $type = OutputInterface::OUTPUT_NORMAL;

    protected $useBuffer;

    protected $buffer;

    public function __construct(OutputInterface $output, $buffer = false, $colors = true)
    {
        $this->output = $output;
        if (!$colors) {
            $this->type = OutputInterface::OUTPUT_PLAIN;
        }
        $this->useBuffer = $buffer;
    }

    public function write($string, $eol = true)
    {
        if ($eol) {
            $this->output->writeln($string, $this->type);
        } else {
            $this->output->write($string, false, $this->type);
        }
        if ($this->useBuffer) {
            $this->buffer .= strip_tags($string) . ($eol? PHP_EOL : '');
        }
    }

    public function getBuffer()
    {
        $return = $this->buffer;
        $this->buffer = '';
        return $return;
    }

    /**
     * Render message preceeding the initial test run
     *
     * @param array $result
     */
    public function renderPreTestIntroduction()
    {
        $this->write('Humbug running test suite to generate logs and code coverage data...');
    }

    /**
     * Render message where the initial test run didn't pass (excl. incomplete/skipped/risky tests)
     *
     * @param array $result
     */
    public function renderInitialRunFail(array $result)
    {
        $this->write('<warning>Tests must be in a fully passing state before Humbug is run.</warning>');
        $this->write('<warning>Incomplete, skipped or risky tests are allowed.</warning>');
        if (!empty($result['stdout'])) {
            $this->write('<warning>Stdout: \n' . $this->indent($result['stdout']) . '\n</warning>');
        }
        if (!empty($result['stderr'])) {
            $this->write('<warning>Stderr: \n' . $this->indent($result['stderr']) . '\n</warning>');
        }
    }

    /**
     * Render message where the initial test run didn't pass (excl. incomplete/skipped/risky tests)
     *
     * @param array $result
     */
    public function renderInitialRunPass(array $result)
    {
        $this->write('Humbug has completed the initial test run successfully.');
    }

    /**
     * Render message that Humbug is analysing files.
     *
     * @param array $result
     */
    public function renderStaticAnalysisStart()
    {
        $this->write('Humbug is analysing source files...');
    }

    /**
     * Render message that mutation testing loop is starting
     *
     * @param array $result
     */
    public function renderMutationTestingStart()
    {
        $this->write('Mutation Testing is commencing...');
        $this->write(
            '(<options=bold>.</options=bold>: killed, '
            . '<fg=red;options=bold>M</fg=red;options=bold>: escaped, '
            . '<fg=blue;options=bold>S</fg=blue;options=bold>: uncovered, '
            . '<fg=yellow;options=bold>E</fg=yellow;options=bold>: fatal error, '
            . '<fg=cyan;options=bold>T</fg=cyan;options=bold>: timed out)'
        );
    }

    /**
     * Render a progress marker:
     *  T: The test run timed out, possibly due to an infinite loop or underestimated timeout
     *  E: The test run hit a fatal error, either kicked out from a test or due to a Humbug issue
     *  M: The test run was successful. The mutation went undetected by the unit tests.
     *  .: The test run included a fail condition. The mutation was detected!!!
     *
     * @param array $result
     */
    public function renderProgressMark(array $result, $eolInterval = 60)
    {
        $this->progressCount++;
        if ($result['timeout'] === true) {
            $this->write('<fg=cyan;options=bold>T</fg=cyan;options=bold>', false);
        } elseif (strlen($result['stderr']) > 0) {
            $this->write('<fg=yellow;options=bold>E</fg=yellow;options=bold>', false);
        } elseif ($result['passed'] === true) {
            $this->write('<fg=red;options=bold>M</fg=red;options=bold>', false);
        } else {
            $this->write('<options=bold>.</options=bold>', false);
        }
        if (($this->progressCount % $eolInterval) == 0) {
            $counter = str_pad($this->progressCount, 5, ' ', STR_PAD_LEFT);
            $this->write(' |' . $counter . PHP_EOL, false);
        }
    }

    /**
     * Render a shadow marker, i.e. a mutation whose source code line is
     * not covered by any test based on current code coverage data.
     *
     * @param array $result
     */
    public function renderShadowMark($eolInterval = 60)
    {
        $this->progressCount++;
        $this->write('<fg=blue;options=bold>S</fg=blue;options=bold>', false);
        if (($this->progressCount % $eolInterval) == 0) {
            $counter = str_pad($this->progressCount, 5, ' ', STR_PAD_LEFT);
            $this->write(' |' . $counter . PHP_EOL, false);
        }
    }

    /**
     * Render performance data for the mutation testing run<commit_msg>Bump progress line from 60 to 70 EOL intervals<commit_after><?php
/**
 * Humbug
 *
 * @category   Humbug
 * @package    Humbug
 * @copyright  Copyright (c) 2015 <NAME> (http://blog.astrumfutura.com)
 * @license    https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
 */

namespace Humbug\Renderer;

use Symfony\Component\Console\Output\OutputInterface;

class Text
{

    protected $output;

    protected $progressCount = 0;

    protected $type = OutputInterface::OUTPUT_NORMAL;

    protected $useBuffer;

    protected $buffer;

    public function __construct(OutputInterface $output, $buffer = false, $colors = true)
    {
        $this->output = $output;
        if (!$colors) {
            $this->type = OutputInterface::OUTPUT_PLAIN;
        }
        $this->useBuffer = $buffer;
    }

    public function write($string, $eol = true)
    {
        if ($eol) {
            $this->output->writeln($string, $this->type);
        } else {
            $this->output->write($string, false, $this->type);
        }
        if ($this->useBuffer) {
            $this->buffer .= strip_tags($string) . ($eol? PHP_EOL : '');
        }
    }

    public function getBuffer()
    {
        $return = $this->buffer;
        $this->buffer = '';
        return $return;
    }

    /**
     * Render message preceeding the initial test run
     *
     * @param array $result
     */
    public function renderPreTestIntroduction()
    {
        $this->write('Humbug running test suite to generate logs and code coverage data...');
    }

    /**
     * Render message where the initial test run didn't pass (excl. incomplete/skipped/risky tests)
     *
     * @param array $result
     */
    public function renderInitialRunFail(array $result)
    {
        $this->write('<warning>Tests must be in a fully passing state before Humbug is run.</warning>');
        $this->write('<warning>Incomplete, skipped or risky tests are allowed.</warning>');
        if (!empty($result['stdout'])) {
            $this->write('<warning>Stdout: \n' . $this->indent($result['stdout']) . '\n</warning>');
        }
        if (!empty($result['stderr'])) {
            $this->write('<warning>Stderr: \n' . $this->indent($result['stderr']) . '\n</warning>');
        }
    }

    /**
     * Render message where the initial test run didn't pass (excl. incomplete/skipped/risky tests)
     *
     * @param array $result
     */
    public function renderInitialRunPass(array $result)
    {
        $this->write('Humbug has completed the initial test run successfully.');
    }

    /**
     * Render message that Humbug is analysing files.
     *
     * @param array $result
     */
    public function renderStaticAnalysisStart()
    {
        $this->write('Humbug is analysing source files...');
    }

    /**
     * Render message that mutation testing loop is starting
     *
     * @param array $result
     */
    public function renderMutationTestingStart()
    {
        $this->write('Mutation Testing is commencing...');
        $this->write(
            '(<options=bold>.</options=bold>: killed, '
            . '<fg=red;options=bold>M</fg=red;options=bold>: escaped, '
            . '<fg=blue;options=bold>S</fg=blue;options=bold>: uncovered, '
            . '<fg=yellow;options=bold>E</fg=yellow;options=bold>: fatal error, '
            . '<fg=cyan;options=bold>T</fg=cyan;options=bold>: timed out)'
        );
    }

    /**
     * Render a progress marker:
     *  T: The test run timed out, possibly due to an infinite loop or underestimated timeout
     *  E: The test run hit a fatal error, either kicked out from a test or due to a Humbug issue
     *  M: The test run was successful. The mutation went undetected by the unit tests.
     *  .: The test run included a fail condition. The mutation was detected!!!
     *
     * @param array $result
     */
    public function renderProgressMark(array $result, $eolInterval = 70)
    {
        $this->progressCount++;
        if ($result['timeout'] === true) {
            $this->write('<fg=cyan;options=bold>T</fg=cyan;options=bold>', false);
        } elseif (strlen($result['stderr']) > 0) {
            $this->write('<fg=yellow;options=bold>E</fg=yellow;options=bold>', false);
        } elseif ($result['passed'] === true) {
            $this->write('<fg=red;options=bold>M</fg=red;options=bold>', false);
        } else {
            $this->write('<options=bold>.</options=bold>', false);
        }
        if (($this->progressCount % $eolInterval) == 0) {
            $counter = str_pad($this->progressCount, 5, ' ', STR_PAD_LEFT);
            $this->write(' |' . $counter . PHP_EOL, false);
        }
    }

    /**
     * Render a shadow marker, i.e. a mutation whose source code line is
     * not covered by any test based on current code coverage data.
     *
     * @param array $result
     */
    public function renderShadowMark($eolInterval = 70)
    {
        $this->progressCount++;
        $this->write('<fg=blue;options=bold>S</fg=blue;options=bold>', false);
        if (($this->progressCount % $eolInterval) == 0) {
            $counter = str_pad($this->progressCount, 5, ' ', STR_PAD_LEFT);
            $this->write(' |' . $counter . PHP_EOL, false);
        }
    }

    /**
     * Render performance data for the mutation testing run
{'fraction_non_alphanumeric': 0.14933534458376543, 'fraction_numerical': 0.0030168756481568776, 'mean_word_length': 2.3967339097022093, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 137, 'https://': 2, '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': '6860241', 'n_tokens_mistral': 3191, 'n_tokens_neox': 3104, 'n_words': 777}