<commit_before><?php

namespace Gitonomy\Bundle\FrontendBundle\Validation\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Bundle\DoctrineBundle\Registry;

class UserEmailValidator extends ConstraintValidator
{
    /**
     * @var Symfony\Bundle\DoctrineBundle\Registry
     */
    protected $doctrineRegistry;

    function __construct(Registry $doctrineRegistry)
    {
        $this->doctrineRegistry = $doctrineRegistry;
    }

    public function isValid($value, Constraint $constraint)
    {
        if (null === $value) {
            return true;
        }

        $count = $this->doctrineRegistry
            ->getRepository('GitonomyCoreBundle:Email')
            ->createQueryBuilder('e')
            ->select('COUNT(e)')
            ->where('e.email = :email')
            ->setParameters(array(
                'email' => $value
            ))
            ->getQuery()
            ->getSingleScalarResult()
        ;

        if ($count == 0) {
            $this->setMessage($constraint->message);

            return false;
        }

        return true;
    }
}
<commit_msg>Check email before user email validator<commit_after><?php

namespace Gitonomy\Bundle\FrontendBundle\Validation\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Bundle\DoctrineBundle\Registry;

class UserEmailValidator extends ConstraintValidator
{
    /**
     * @var Symfony\Bundle\DoctrineBundle\Registry
     */
    protected $doctrineRegistry;

    function __construct(Registry $doctrineRegistry)
    {
        $this->doctrineRegistry = $doctrineRegistry;
    }

    public function isValid($value, Constraint $constraint)
    {
        if (null === $value) {
            return true;
        }

        if (false === filter_var($value, FILTER_VALIDATE_EMAIL)) {
            return true;
        }

        $count = $this->doctrineRegistry
            ->getRepository('GitonomyCoreBundle:Email')
            ->createQueryBuilder('e')
            ->select('COUNT(e)')
            ->where('e.email = :email')
            ->setParameters(array(
                'email' => $value
            ))
            ->getQuery()
            ->getSingleScalarResult()
        ;

        if ($count == 0) {
            $this->setMessage($constraint->message);

            return false;
        }

        return true;
    }
}

{'fraction_non_alphanumeric': 0.11568228105906314, 'fraction_numerical': 0.000814663951120163, 'mean_word_length': 2.1649484536082473, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '3959955', 'n_tokens_mistral': 659, 'n_tokens_neox': 640, 'n_words': 115}