RegisteredUserValidator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 7
Bugs 2 Features 0
Metric Value
wmc 7
c 7
b 2
f 0
lcom 1
cbo 3
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B validate() 0 13 6
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