Completed
Push — master ( 463d73...47ba96 )
by Gerrit
02:04
created

RequestArgument::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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\Argument;
16
use Symfony\Component\HttpFoundation\RequestStack;
17
use Symfony\Component\HttpFoundation\Request;
18
use Webmozart\Assert\Assert;
19
20
final class RequestArgument implements Argument
21
{
22
23
    /**
24
     * @var RequestStack
25
     */
26
    private $requestStack;
27
28
    /**
29
     * @var string
30
     */
31
    private $key;
32
33 2
    public function __construct(
34
        RequestStack $requestStack,
35
        string $key
36
    ) {
37 2
        $this->requestStack = $requestStack;
38 2
        $this->key = $key;
39 2
    }
40
41 2 View Code Duplication
    public function resolve()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        /** @var Request $request */
44 2
        $request = $this->requestStack->getCurrentRequest();
45
46 2
        Assert::isInstanceOf(
47 2
            $request,
48 2
            Request::class,
49 2
            "Cannot resolve request-argument without active request!"
50
        );
51
52 1
        return $request->get($this->key);
53
    }
54
55
}
56