Completed
Push — master ( a435b5...54b9b0 )
by Guillaume
14:56
created

LeadExistValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Starkerxp\LeadBundle\Validator;
4
5
use Starkerxp\LeadBundle\Entity\Lead;
6
use Starkerxp\LeadBundle\Repository\LeadRepository;
7
use Symfony\Component\Validator\Constraint;
8
use Symfony\Component\Validator\ConstraintValidator;
9
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
10
11
/**
12
 * @Annotation
13
 */
14 View Code Duplication
class LeadExistValidator extends ConstraintValidator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * @var LeadRepository
18
     */
19
    protected $repositoryLead;
20
21
    /**
22
     * NotCreatedSameLeadValidator constructor.
23
     * @param LeadRepository $repositoryLead
24
     */
25
    public function __construct(LeadRepository $repositoryLead)
26
    {
27
        $this->repositoryLead = $repositoryLead;
28
    }
29
30
    public function validate($value, Constraint $constraint)
31
    {
32
        if (!$constraint instanceof LeadExist) {
33
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\LeadExist');
34
        }
35
36
        /** @var Lead $lead */
37
        $lead = $this->context->getRoot()->getData();
38
        if ($this->repositoryLead->leadExist($lead->getOrigin(), $lead->getExternalReference())) {
39
            $this->context->buildViolation($constraint->message)
40
                ->setParameter('{{ origin }}', $lead->getOrigin())
41
                ->setParameter('{{ external_reference }}', $lead->getExternalReference())
42
                ->addViolation();
43
        }
44
    }
45
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
46