Completed
Push — master ( 677e94...463d73 )
by Gerrit
02:18
created

RequestArgument   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getValue() 0 13 1
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\SymfonyGenerics\Arguments;
14
15
use Addiks\SymfonyGenerics\Arguments\ArgumentInterface;
16
use Symfony\Component\HttpFoundation\RequestStack;
17
use Symfony\Component\HttpFoundation\Request;
18
use Webmozart\Assert\Assert;
19
20
final class RequestArgument implements ArgumentInterface
21
{
22
23
    /**
24
     * @var RequestStack
25
     */
26
    private $requestStack;
27
28
    /**
29
     * @var string
30
     */
31
    private $key;
32
33
    public function __construct(
34
        RequestStack $requestStack,
35
        string $key
36
    ) {
37
        $this->requestStack = $requestStack;
38
        $this->key = $key;
39
    }
40
41
    public function getValue()
42
    {
43
        /** @var Request $request */
44
        $request = $this->requestStack->getCurrentRequest();
45
46
        Assert::isInstanceOf(
47
            $request,
48
            Request::class,
49
            "Cannot resolve request-argument without active request!"
50
        );
51
52
        return $request->get($this->key);
53
    }
54
55
}
56