FactoryRegistry   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findForConstraint() 0 9 3
1
<?php
2
3
namespace JBen87\ParsleyBundle\Constraint\Factory;
4
5
use JBen87\ParsleyBundle\Exception\ConstraintException;
6
use Symfony\Component\Validator\Constraint as SymfonyConstraint;
7
8
class FactoryRegistry
9
{
10
    /**
11
     * @var FactoryInterface[]|iterable
12
     */
13
    private $factories;
14
15
    /**
16
     * @param FactoryInterface[]|iterable $factories
17
     */
18 2
    public function __construct(iterable $factories)
19
    {
20 2
        $this->factories = $factories;
21 2
    }
22
23
    /**
24
     * @param SymfonyConstraint $constraint
25
     *
26
     * @return FactoryInterface
27
     * @throws ConstraintException
28
     */
29 2
    public function findForConstraint(SymfonyConstraint $constraint): FactoryInterface
30
    {
31 2
        foreach ($this->factories as $factory) {
32 1
            if ($factory->supports($constraint)) {
33 1
                return $factory;
34
            }
35
        }
36
37 1
        throw ConstraintException::createUnsupportedException();
38
    }
39
}
40