ValidatorMap   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getValidator() 0 10 4
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