Passed
Push — master ( 75ce57...f33fa2 )
by Zlatin
01:39
created

Request   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 27 7
1
<?php
2
namespace DevOp\Core\Http;
3
4
use Psr\Http\Message\UriInterface;
5
use Psr\Http\Message\StreamInterface;
6
use Psr\Http\Message\RequestInterface;
7
8
class Request implements RequestInterface
9
{
10
11
    use Traits\MessageTrait;
12
    use Traits\RequestTrait;
13
14
    /**
15
     * 
16
     * @param string $method
17
     * @param UriInterface $uri
18
     * @param array $headers
19
     * @param string|resource|StreamInterface $body
20
     * @param string $protocolVersion
21
     */
22 22
    public function __construct($method, UriInterface $uri, array $headers = [], $body = 'php://temp', $protocolVersion = '1.1')
23
    {
24 22
        $this->method = $method;
25 22
        $this->uri = new Uri($uri);
26
27 22
        if ($body instanceof StreamInterface) {
28 2
            $this->body = $body;
29 22
        } else if (is_resource($body)) {
30
            $this->body = (new Factory\StreamFactory())->createStreamFromResource($body);
31
        } else {
32 20
            $this->body = (new Factory\StreamFactory())->createStreamFromFile($body, "wb+");
33
        }
34
35 22
        foreach ($headers AS $header => $value) {
36
            $this->headersName[strtolower($header)] = $header;
37
            $this->headers[$header] = !is_array($value) ? [$value] : $value;
38 22
        }
39
        
40 22
        if (!$this->hasHeader('Host')) {
41 22
            if (null === $uri = $this->uri->getHost()) {
0 ignored issues
show
introduced by
The condition null === $uri = $this->uri->getHost() can never be true.
Loading history...
42 22
                $uri = 'localhost';
43 22
            }
44 22
            $this->headersName['host'] = 'Host';
45 22
            $this->headers['Host'] = [$uri];
46 22
        }
47
48 22
        $this->protocolVersion = $protocolVersion;
49 22
    }
50
}
51