Completed
Push — master ( 96fcad...d3856b )
by Tobias
02:21
created

Request::getUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nyholm\Psr7;
6
7
use Nyholm\Psr7\Factory\StreamFactory;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\StreamInterface;
10
use Psr\Http\Message\UriInterface;
11
12
/**
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15
final class Request implements RequestInterface
16
{
17
    use MessageTrait;
18
    use RequestTrait;
19
20
    /**
21
     * @param string                               $method  HTTP method
22
     * @param string|UriInterface                  $uri     URI
23
     * @param array                                $headers Request headers
24
     * @param string|null|resource|StreamInterface $body    Request body
25
     * @param string                               $version Protocol version
26
     */
27 63 View Code Duplication
    public function __construct(
1 ignored issue
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...
28
        string $method,
29
        $uri,
30
        array $headers = [],
31
        $body = null,
32
        string $version = '1.1'
33
    ) {
34 63
        if (!($uri instanceof UriInterface)) {
35 61
            $uri = new Uri($uri);
36
        }
37
38 62
        $this->method = $method;
39 62
        $this->uri = $uri;
40 62
        $this->setHeaders($headers);
41 62
        $this->protocol = $version;
42
43 62
        if (!$this->hasHeader('Host')) {
44 61
            $this->updateHostFromUri();
45
        }
46
47 62
        if ('' !== $body && null !== $body) {
48 3
            $this->stream = (new StreamFactory())->createStream($body);
49
        }
50 62
    }
51
}
52