Passed
Push — master ( 2ee2bd...602ea4 )
by Benoit
02:02
created

FactoryRegistry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
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[]
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $factories of type iterable is incompatible with the declared type JBen87\ParsleyBundle\Con...tory\FactoryInterface[] of property $factories.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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