Passed
Push — master ( 37358f...e9906c )
by Zlatin
01:33
created

Request::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.0961

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 5
dl 0
loc 15
ccs 9
cts 11
cp 0.8182
crap 4.0961
rs 9.2
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 string|UriInterface $uri
18
     * @param array $headers
19
     * @param string|resource|StreamInterface $body
20
     * @param string $protocolVersion
21
     */
22 12
    public function __construct($method, UriInterface $uri, array $headers = [], StreamInterface $body = null, $protocolVersion = '1.1')
23
    {
24 12
        $this->method = $method;
25 12
        $this->uri = new Uri($uri);
26
        
27 12
        if ($body instanceof StreamInterface) {
28 2
            $this->body = $body;
29 10
        } else if (is_resource($body)) {
0 ignored issues
show
introduced by
The condition is_resource($body) can never be true.
Loading history...
30
            $this->body = (new Factory\StreamFactory())->createStreamFromFile($body, "r+");
31 10
        } else if (is_string($body)) {
0 ignored issues
show
introduced by
The condition is_string($body) can never be true.
Loading history...
32
            $this->body = (new Factory\StreamFactory())->createStream($body);
33
        }
34
        
35 12
        $this->headers = $headers;
36 12
        $this->protocolVersion = $protocolVersion;
37 12
    }
38
}
39