Passed
Push — master ( 478a0c...9f2f7c )
by Zlatin
01:26
created

Request::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.054

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 5
dl 0
loc 15
ccs 9
cts 11
cp 0.8182
crap 3.054
rs 9.4285
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 = [], $body = 'php://temp', $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 11
        } else if (is_resource($body)) {
30
            $this->body = (new Factory\StreamFactory())->createStreamFromResource($body);
31
        } else {
32 10
            $this->body = (new Factory\StreamFactory())->createStreamFromFile($body, "r+");
33
        }
34
35 12
        $this->headers = $headers;
36 12
        $this->protocolVersion = $protocolVersion;
37 12
    }
38
}
39