ValidatorMap::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Nicofuma\SwaggerBundle\Validator;
4
5
use Nicofuma\SwaggerBundle\Exception\NoValidatorException;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class ValidatorMap
10
{
11
    protected $container;
12
    protected $map;
13
14 3
    public function __construct(ContainerInterface $container, array $map)
15
    {
16 3
        $this->container = $container;
17 3
        $this->map = $map;
18 3
    }
19
20
    /**
21
     * @param Request $request
22
     *
23
     * @return Validator
24
     */
25 3
    public function getValidator(Request $request)
26
    {
27 3
        foreach ($this->map as $validatorId => $requestMatcher) {
28 2
            if (null === $requestMatcher || $requestMatcher->matches($request)) {
29 2
                return $this->container->get($validatorId);
30
            }
31 3
        }
32
33 1
        throw new NoValidatorException();
34
    }
35
}
36