@param string $message
@param array  $expectedValues
@param mixed  $default

@return string
357946
protected function choice($message, $expectedValues, $default = null
    )
    {
        /** @var QuestionHelper $q */
        $q = $this->getHelperSet()->get('question');

        $question = new ChoiceQuestion(
            $message . ($default ? (sprintf(' [%s]', $default)) : '') . ' : ',
            $expectedValues,
            $default
        );

        $question->setMaxAttempts(5);

        $response = $q->ask($this->getInput(), $this->getOutput(), $question);

        return $response;
    }
1229013
protected function raiseMismatch($expectedType)
    {
        $value = $this->value;

        if (is_object($value)) {
            $value = get_class($value);
        } elseif (is_array($value)) {
            $value = implode(',', $value);
        }

        throw new CastingMismatchException(sprintf(self::MISMATCH_MESSAGE, $value, $expectedType));
    }
445607
protected function prompt($message, $default = null, $hidden = false)
    {
        /** @var QuestionHelper $q */
        $q = $this->getHelperSet()->get('question');

        $question = new Question($message . ($default ? (sprintf(' [%s]', $default)) : '') . ' : ', $default);

        if (true === (bool)$hidden) {
            $question->setHidden($hidden);
        }

        $question->setValidator(function ($answer) {
            $len = function_exists('mb_strlen') ? mb_strlen($answer) : strlen($answer);

            if (0 === $len) {
                throw new \RuntimeException("You must enter a value", 23);
            }

            return $answer;
        });

        $question->setMaxAttempts(3);

        $response = $q->ask($this->getInput(), $this->getOutput(), $question);

        return $response;
    }
622060
public function renderInOrder(array $expected, array $actual): string
    {
        if (empty($expected)) {
            return $this->reset . 'Expected events.' . PHP_EOL .
                $this->failStart . 'No events recorded.' . $this->reset;
        }

        $from = $this->renderEvents($expected);
        $to = $this->renderEvents($actual);

        $matcher = new DifferenceSequenceMatcher($from, $to);
        $diff = [];

        foreach ($matcher->getOpcodes() as $opcode) {
            list($tag, $i1, $i2, $j1, $j2) = $opcode;

            if ($tag === 'equal') {
                foreach (array_slice($from, $i1, $i2 - $i1) as $event) {
                    $diff[] = '    ' . $this->pass . '   ' . $event;
                }
            } else {
                if ($tag === 'replace' || $tag === 'delete') {
                    foreach (array_slice($from, $i1, $i2 - $i1) as $event) {
                        $diff[] =
                            '    ' . $this->fail . ' ' .
                            $this->removeStart . $event . $this->removeEnd;
                    }
                }

                if ($tag === 'replace' || $tag === 'insert') {
                    foreach (array_slice($to, $j1, $j2 - $j1) as $event) {
                        $diff[] =
                            '    - ' . $this->addStart . $event . $this->addEnd;
                    }
                }
            }
        }

        $renderedExpected = [];

        foreach ($from as $event) {
            $renderedExpected[] = '    - ' . $event;
        }

        $renderedActual = [];

        foreach ($to as $event) {
            $renderedActual[] = '    - ' . $event;
        }

        return $this->reset . 'Expected events in order:' . PHP_EOL .
            implode(PHP_EOL, $renderedExpected) . PHP_EOL .
            'Actual order:' . PHP_EOL .
            implode(PHP_EOL, $renderedActual) . PHP_EOL .
            'Difference:' . PHP_EOL .
            implode(PHP_EOL, $diff);
    }
404359
protected function _debugExpectedFields($expectedFields = [], $missingMessage = '')
    {
        if (count($expectedFields) === 0) {
            return null;
        }

        $expectedFieldNames = [];
        foreach ((array)$expectedFields as $key => $expectedField) {
            if (is_int($key)) {
                $expectedFieldNames[] = $expectedField;
            } else {
                $expectedFieldNames[] = $key;
            }
        }

        return sprintf($missingMessage, implode(', ', $expectedFieldNames));
    }
323676
public static function unexpectedCharacter(Input $definition, array $expected = []): self
    {
        $pointer = self::createPointerString($definition->getInput(), $definition->getIndex());

        if (empty($expected)) {
            return new self("Unexpected character:\n$pointer");
        }

        $expected = $expected ?? $definition->getLatestExpectations();

        $expected = array_map(function (string $e) {
            return "'$e'";
        }, $expected);

        $expected = implode(", ", $expected);

        return new self("Unexpected character (expected $expected):\n$pointer");
    }
974238
private function invalidReturnValue(string $what, string $expected, $actual) : \UnexpectedValueException
    {
        $message = 'Invalid return value from %s: expected %s, got %s.';
        $actual  = is_object($actual) ? get_class($actual) : gettype($actual);

        return new \UnexpectedValueException(sprintf($message, $what, $expected, $actual));
    }
846633
public function confirmation($message, $choices = ['y' => true, 'n' => false], $default = false)
    {
        $message = is_array($message) ? call_user_func_array('sprintf', $message) : $message;

        $answers = [];
        foreach ($choices as $answer => $value) {
            $answers[$answer] = $answer;
            if ($value === $default) $answers[$answer] = ucfirst($answer);
        }
        
        $this->send(sprintf('%s [%s]: ', $message, join('/', $answers)), '');
        $answer = $this->readline();
        if ($answer === '') return $default;

        if (array_key_exists($answer, $choices)) {
            return $choices[$answer];
        } else {
            foreach ($choices as $key => $value) {
                if ($answer === substr($key, 0, strlen($answer))) return $value;
            }
            return $default;
        }
    }
595641
protected function getI18nPhpVersionText($expectedValue, $currentValue, $isValid)
    {
        if ($this->translator !== null) {
            if ($isValid) {
                $sentence = 'PHP version %currentValue% matches the minimum required (PHP %expectedValue%).';
            } else {
                $sentence = 'The installer detected PHP version %currentValue%, but Thelia 2 requires PHP %expectedValue% or newer.';
            }

            $translatedText = $this->translator->trans(
                $sentence,
                array(
                    '%expectedValue%' => $expectedValue,
                    '%currentValue%' => $currentValue,
                )
            );
        } else {
            $translatedText = sprintf('Thelia requires PHP %s or newer (%s currently).', $expectedValue, $currentValue);
        }

        return $translatedText;
    }
132455
private function getBadTypeInTypeMessage($childType, $parentType, array $expectedTypes)
    {
        if ($this->type !== $parentType) {
            $parentType = $this->type;
        }

        $message = sprintf(
            ' %s with dimensions 0x%X (%2$d) in %3$s, expected ',
            $this->getTypeName($childType),
            $this->getDimensions($childType),
            $this->getTypeName($parentType)
        );

        if (! in_array($this->getTypePrimitive($childType), $expectedTypes, true)) {
            if (1 === count($expectedTypes)) {
                $message .= $this->getTypeName($expectedTypes[0]);
            } else {
                $last = $this->getTypeName(array_pop($expectedTypes));
                $message .= implode(array_map(array($this, 'getTypeName'), $expectedTypes), ', ') . ' or ' . $last;
            }

            $message = 'Unexpected' . $message . ' with ';
        } else {
            $message = 'Bad' . $message;
        }

        return $message . sprintf('dimensions 0x%X (%1$d)', $this->dimensions);
    }
142066
protected function getWildcardCustomMessages($messages, $search, $default)
    {
        foreach ($messages as $key => $message) {
            if ($search === $key || (Str::contains($key, ['*']) && Str::is($key, $search))) {
                return $message;
            }
        }

        return $default;
    }
1089876
public function expectImplicit($expectedTag = null): ImplicitTagging
    {
        $el = $this;
        if (!$el instanceof ImplicitTagging) {
            throw new \UnexpectedValueException(
                "Element doesn't implement implicit tagging.");
        }
        if (isset($expectedTag)) {
            $el->expectTagged($expectedTag);
        }
        return $el;
    }
971477
public function send(Message $message, $messageCode, $expectedResponseCode)
    {
        $payload  = $this->encodeMessage($message, $messageCode);
        $stream   = $this->connection->send($payload);

        return $this->receiveMessage($stream, $expectedResponseCode);
    }
825509
public function askQuestion($message, $default = null)
    {
        $question = new Question($this->formatMessage($message, $default), $default);
        
        return $this->question->ask($this->input, $this->output, $question);
    }
947932
public function pregValues($pattern, $defaultResult = null, $flags = 0)
    {
        $result = preg_grep($pattern, array_values($this->target), $flags);

        return $result ? array_values($result) : $defaultResult;
    }
63144
public function getFrom(Message $message = null) 
    {
        $from = $message === null ? null : $message->getFrom();
        if (!$from) {
            $from = $this->getOption(self::CONFIG_DEFAULT_SENDER);
        }
        return $from;
    }
301804
private function formatMessage(string $defaultMessage, array $args = []): string
    {
        $message = $this->getFormatter()->formatMessage($defaultMessage, $args);

        return $message;
    }