RegisteredUserValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DoS\UserBundle\Validator\Constraints;
4
5
use Sylius\Component\Resource\Repository\RepositoryInterface;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidator;
8
9
class RegisteredUserValidator extends ConstraintValidator
10
{
11
    /**
12
     * @var RepositoryInterface
13
     */
14
    private $customerRepository;
15
16
    /**
17
     * @param RepositoryInterface $customerRepository
18
     */
19
    public function __construct(RepositoryInterface $customerRepository)
20
    {
21
        $this->customerRepository = $customerRepository;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function validate($customer, Constraint $constraint)
28
    {
29
        if ($mobile = $customer->getMobile()) {
30
            $existingMobile = $this->customerRepository->findOneBy(array('mobile' => $mobile));
31
32
            if (null !== $existingMobile
33
                && null !== $existingMobile->getUser()
34
                && $existingMobile->getId() !== $customer->getId()
35
            ) {
36
                $this->context->addViolationAt('mobile', $constraint->mobileMessage ?: $constraint->message, array(), null);
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...
37
            }
38
        }
39
    }
40
}
41