ChainVersionResolver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 35
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A resolve() 0 12 3
A addResolver() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\Version;
13
14
use Symfony\Component\HttpFoundation\Request;
15
16
/**
17
 * @author Ener-Getick <[email protected]>
18
 */
19
final class ChainVersionResolver implements VersionResolverInterface
20
{
21
    private $resolvers = [];
22
23
    /**
24
     * @var VersionResolverInterface[]
25
     */
26 7
    public function __construct(array $resolvers)
27
    {
28 7
        foreach ($resolvers as $resolver) {
29
            $this->addResolver($resolver);
30
        }
31 7
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 7
    public function resolve(Request $request): ?string
37
    {
38 7
        foreach ($this->resolvers as $resolver) {
39 7
            $version = $resolver->resolve($request);
40
41 7
            if (null !== $version) {
42 4
                return $version;
43
            }
44
        }
45
46 3
        return null;
47
    }
48
49 7
    public function addResolver(VersionResolverInterface $resolver): void
50
    {
51 7
        $this->resolvers[] = $resolver;
52 7
    }
53
}
54