Completed
Push — 1.0.x-dev ( 34a83d...bde745 )
by Felix
18s queued 11s
created

SymfonyRequestAdapter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Starlit\Request\Authenticator\Hmac\Adapter;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
class SymfonyRequestAdapter implements RequestAdapterInterface
8
{
9
    /**
10
     * @var Request
11
     */
12
    private $request;
13
14 1
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
15
    {
16 1
        $this->request = $request;
17 1
    }
18
19 1
    public function getMethod(): string
20
    {
21 1
        return $this->request->getMethod();
22
    }
23
24
    /**
25
     * helper method to build a uri without reordering url parameters in a query string alphabetically
26
     * which the interal Request::getUri function does (called normalize)
27
     *
28
     * @see SymfonyRequest::getUri()
29
     * @see SymfonyRequest::getQueryString()
30
     * @see SymfonyRequest::normalizeQueryString()
31
     */
32 1
    public function getUri(): string
33
    {
34 1
        $queryString = $this->request->server->get('QUERY_STRING');
35 1
        if (!empty($queryString)) {
36 1
            $queryString = '?' . $queryString;
37
        }
38
39 1
        return $this->request->getSchemeAndHttpHost()
40 1
            . $this->request->getBaseUrl() . $this->request->getPathInfo() . $queryString;
41
    }
42
43 1
    public function getContent(): string
44
    {
45 1
        return $this->request->getContent();
46
    }
47
48 1
    public function getHeader(string $key): ?string
49
    {
50 1
        return $this->request->headers->get($key);
51
    }
52
}
53