Completed
Push — master ( 007cba...a69311 )
by Christian
01:55 queued 11s
created

QueryParameterVersionResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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 QueryParameterVersionResolver implements VersionResolverInterface
21
{
22
    private $parameterName;
23
24
    public function __construct(string $parameterName)
25
    {
26
        $this->parameterName = $parameterName;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function resolve(Request $request): ?string
33
    {
34
        if (!$request->query->has($this->parameterName)) {
35
            return null;
36
        }
37
38
        return (string) $request->query->get($this->parameterName);
39
    }
40
}
41