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

FactoryRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
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[]
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