ContainerConstraintValidatorFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstance() 0 9 2
1
<?php
2
3
namespace Storeman\Validation;
4
5
use Psr\Container\ContainerInterface;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidatorFactory;
8
9
/**
10
 * Allows dependency injection for constraint validators.
11
 */
12
class ContainerConstraintValidatorFactory extends ConstraintValidatorFactory
13
{
14
    /**
15
     * @var ContainerInterface
16
     */
17
    protected $container;
18
19
    public function __construct(ContainerInterface $container)
20
    {
21
        $this->container = $container;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getInstance(Constraint $constraint)
28
    {
29
        if ($this->container->has($constraint->validatedBy()))
30
        {
31
            return $this->container->get($constraint->validatedBy());
32
        }
33
34
        return parent::getInstance($constraint);
35
    }
36
}
37