Completed
Push — master ( a69311...5b5097 )
by Christian
02:43
created

HeaderVersionResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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\Resolver;
13
14
use FOS\RestBundle\Version\VersionResolverInterface;
15
use Symfony\Component\HttpFoundation\Request;
16
17
/**
18
 * @author Ener-Getick <[email protected]>
19
 */
20
final class HeaderVersionResolver implements VersionResolverInterface
21
{
22
    private $headerName;
23
24 7
    public function __construct(string $headerName)
25
    {
26 7
        $this->headerName = $headerName;
27 7
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 7
    public function resolve(Request $request): ?string
33
    {
34 7
        if (!$request->headers->has($this->headerName)) {
35 6
            return null;
36
        }
37
38 1
        return (string) $request->headers->get($this->headerName);
39
    }
40
}
41