Completed
Push — master ( fe8029...f95222 )
by Michał
432:28 queued 418:44
created

Validator/Constraints/RegisteredUserValidator.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\UserBundle\Validator\Constraints;
13
14
use Sylius\Component\Resource\Repository\RepositoryInterface;
15
use Symfony\Component\Validator\Constraint;
16
use Symfony\Component\Validator\ConstraintValidator;
17
18
/**
19
 * @author Michał Marcinkowski <[email protected]>
20
 * @author Mateusz Zalewski <[email protected]>
21
 */
22
class RegisteredUserValidator extends ConstraintValidator
23
{
24
    /**
25
     * @var RepositoryInterface
26
     */
27
    private $customerRepository;
28
29
    /**
30
     * @param RepositoryInterface $customerRepository
31
     */
32
    public function __construct(RepositoryInterface $customerRepository)
33
    {
34
        $this->customerRepository = $customerRepository;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function validate($customer, Constraint $constraint)
41
    {
42
        $existingCustomer = $this->customerRepository->findOneBy(['email' => $customer->getEmail()]);
43
        if (null !== $existingCustomer && null !== $existingCustomer->getUser()) {
44
            $this->context->addViolationAt(
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Valida...rface::addViolationAt() has been deprecated with message: since version 2.5, to be removed in 3.0. Use {@link Context\ExecutionContextInterface::buildViolation()} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
                'email',
46
                $constraint->message,
47
                [],
48
                null
49
            );
50
        }
51
    }
52
}
53