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

RegisteredUserValidator::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 7
nc 2
nop 2
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\CoreBundle\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