protected function getValidator(array $options, $required, $optionValueIsAnswer)
    {
        // @codingStandardsIgnoreStart
        if ($options) {
            $useValue = $this->isList($options) && $optionValueIsAnswer;

            return function ($value) use ($options, $useValue) {
                if ($useValue && !array_key_exists($value, $options)
                    || !$useValue && !in_array($value, $options, true)
                ) {
                    throw new LogicException("Incorrect value '$value'.");
                }

                return $useValue ? $options[$value] : $value;
            };
        } else {
            return function ($value) use ($required) {
                if ($required && (null === $value)) {
                    throw new LogicException('Empty value.');
                }

                return $value;
            };
        }
        // @codingStandardsIgnoreEnd
    }