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

Request::__construct()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 9
nop 5
dl 0
loc 20
ccs 16
cts 16
cp 1
crap 5
rs 8.8571
c 0
b 0
f 0
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