Passed
Push — master ( 0ce391...b65012 )
by Zlatin
01:44
created

Request   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 20 5
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 StreamInterface $body
20
     * @param string $protocolVersion
21
     */
22 28
    public function __construct($method, UriInterface $uri, array $headers = [], $body, $protocolVersion = '1.1')
23
    {
24 28
        $this->method = $method;
25 28
        $this->uri = $uri;
26 28
        $this->body = $body;
27
        
28 28
        foreach ($headers AS $header => $value) {
29 2
            $this->headersName[strtolower($header)] = $header;
30 2
            $this->headers[$header] = !is_array($value) ? [$value] : $value;
31 14
        }
32
        
33 28
        if (!$this->hasHeader('Host')) {
34 28
            if (!$uri = $this->uri->getHost()) {
35 24
                $uri = 'localhost';
36 12
            }
37 28
            $this->headersName['host'] = 'Host';
38 28
            $this->headers['Host'] = [$uri];
39 14
        }
40
41 28
        $this->protocolVersion = $protocolVersion;
42 28
    }
43
}
44