ChainVersionResolver::addResolver()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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