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

QueryParameterVersionResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 21
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 8 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 QueryParameterVersionResolver implements VersionResolverInterface
21
{
22
    private $parameterName;
23
24 7
    public function __construct(string $parameterName)
25
    {
26 7
        $this->parameterName = $parameterName;
27 7
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 5
    public function resolve(Request $request): ?string
33
    {
34 5
        if (!$request->query->has($this->parameterName)) {
35 3
            return null;
36
        }
37
38 2
        return (string) $request->query->get($this->parameterName);
39
    }
40
}
41