<commit_before><?php

namespace KnpU\ActivityRunner\Activity\MultipleChoice;

class AnswerBuilder
{
    private $answers = array();

    private $correctAnswerIndex;

    /**
     * @param string $text
     * @param bool $isCorrect
     * @returns AnswerBuilder
     * @throws \Exception
     */
    public function addAnswer($text, $isCorrect = false)
    {
        $key = md5($text);
        $this->answers[$key] = $text;

        if ($isCorrect) {
            if ($this->correctAnswerIndex !== null) {
                throw new \LogicException(sprintf(
                    'Another answer is already marked as being correct: "%s"',
                    $this->getCorrectAnswerText()
                ));
            }

            $this->correctAnswerIndex = $key;
        }

        return $this;
    }

    /**
     * @return string
     * @throws \Exception
     */
    public function getCorrectAnswerText()
    {
        if ($this->correctAnswerIndex === null) {
            throw new \Exception('No answers are correct!');
        }

        return $this->answers[$this->correctAnswerIndex];
    }

    /**
     * @param string $sha
     * @return bool
     */
    public function isAnswerCorrect($sha)
    {
        return $this->correctAnswerIndex == $sha;
    }

    public function getCorrectAnswerIndex()
    {
        return $this->correctAnswerIndex;
    }

    public function getAnswers()
    {
        return $this->answers;
    }
}<commit_msg>Fixing bug where printing from the AnswerBuilder sometimes might not display<commit_after><?php

namespace KnpU\ActivityRunner\Activity\MultipleChoice;

class AnswerBuilder
{
    private $answers = array();

    private $correctAnswerIndex;

    /**
     * @param string $text
     * @param bool $isCorrect
     * @returns AnswerBuilder
     * @throws \Exception
     */
    public function addAnswer($text, $isCorrect = false)
    {
        $text = $this->textifyAnswer($text);
        $key = md5($text);
        $this->answers[$key] = $text;

        if ($isCorrect) {
            if ($this->correctAnswerIndex !== null) {
                throw new \LogicException(sprintf(
                    'Another answer is already marked as being correct: "%s"',
                    $this->getCorrectAnswerText()
                ));
            }

            $this->correctAnswerIndex = $key;
        }

        return $this;
    }

    /**
     * @return string
     * @throws \Exception
     */
    public function getCorrectAnswerText()
    {
        if ($this->correctAnswerIndex === null) {
            throw new \Exception('No answers are correct!');
        }

        return $this->answers[$this->correctAnswerIndex];
    }

    /**
     * @param string $sha
     * @return bool
     */
    public function isAnswerCorrect($sha)
    {
        return $this->correctAnswerIndex == $sha;
    }

    public function getCorrectAnswerIndex()
    {
        return $this->correctAnswerIndex;
    }

    public function getAnswers()
    {
        return $this->answers;
    }

    /**
     * Tries to make sure answers are in a decent format for displaying
     *
     * @param $answer
     * @return string
     */
    private function textifyAnswer($answer)
    {
        if ($answer === true) {
            return 'true';
        }

        if ($answer === false) {
            return 'false';
        }

        if ($answer === 0) {
            // even returning the string 0 isn't printing well
            return '0&nbsp;';
        }

        return (string) $answer;
    }

}
{'fraction_non_alphanumeric': 0.1188118811881188, 'fraction_numerical': 0.0014144271570014145, 'mean_word_length': 1.8152866242038217, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '6720356', 'n_tokens_mistral': 1030, 'n_tokens_neox': 946, 'n_words': 237}