FactoryRegistry::findForConstraint()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
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