<commit_before><?php

namespace Trellis\Runtime\Validator\Rule\Type;

use Trellis\Runtime\Attribute\AttributeInterface;
use Trellis\Runtime\Entity\EntityInterface;
use Trellis\Runtime\Validator\Result\IncidentInterface;
use Trellis\Runtime\Validator\Rule\Rule;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\EmailParser;
use Egulias\EmailValidator\EmailValidator;
use InvalidArgumentException;
use ReflectionClass;

class EmailRule extends Rule
{
    protected function execute($value, EntityInterface $entity = null)
    {
        if (!is_scalar($value) || !is_string($value)) {
            $this->throwError('invalid_type', [], IncidentInterface::CRITICAL);
            return false;
        }

        $null_value = $this->getOption(AttributeInterface::OPTION_NULL_VALUE, '');
        if ($value === $null_value) {
            $this->setSanitizedValue($null_value);
            return true;
        }

        $warnings = [];
        $reason = null;

        try {
            $parser = new EmailParser(new EmailLexer());
            $parser->parse($value);
            $warnings = $parser->getWarnings();
        } catch (InvalidArgumentException $parse_error) {
            $error_const = $parse_error->getMessage();
            $validator_reflection = new ReflectionClass(new EmailValidator());
            if ($validator_reflection->hasConstant($error_const)) {
                $reason = $error_const;
            }
            $this->throwError('invalid_format', [ 'reason' => $reason ], IncidentInterface::ERROR);
<commit_msg>Correct error message from validator<commit_after><?php

namespace Trellis\Runtime\Validator\Rule\Type;

use Trellis\Runtime\Attribute\AttributeInterface;
use Trellis\Runtime\Entity\EntityInterface;
use Trellis\Runtime\Validator\Result\IncidentInterface;
use Trellis\Runtime\Validator\Rule\Rule;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\EmailParser;
use Egulias\EmailValidator\EmailValidator;
use InvalidArgumentException;
use ReflectionClass;

class EmailRule extends Rule
{
    protected function execute($value, EntityInterface $entity = null)
    {
        if (!is_scalar($value) || !is_string($value)) {
            $this->throwError('invalid_type', [], IncidentInterface::CRITICAL);
            return false;
        }

        $null_value = $this->getOption(AttributeInterface::OPTION_NULL_VALUE, '');
        if ($value === $null_value) {
            $this->setSanitizedValue($null_value);
            return true;
        }

        $warnings = [];
        $reason = null;

        try {
            $parser = new EmailParser(new EmailLexer());
            $parser->parse($value);
            $warnings = $parser->getWarnings();
        } catch (InvalidArgumentException $parse_error) {
            $reason = $parse_error->getMessage();
            $this->throwError('invalid_format', [ 'reason' => $reason ], IncidentInterface::ERROR);

{'fraction_non_alphanumeric': 0.12273504273504274, 'fraction_numerical': 0.0, 'mean_word_length': 3.18, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '6637814', 'n_tokens_mistral': 809, 'n_tokens_neox': 800, 'n_words': 144}