Passed
Push — master ( 5fb311...42b16f )
by Zlatin
02:02
created

Message::getStream()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.5923

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 2
dl 0
loc 11
ccs 4
cts 6
cp 0.6667
crap 4.5923
rs 9.2
c 0
b 0
f 0
1
<?php
2
namespace DevOp\Core\Http;
3
4
use Psr\Http\Message\StreamInterface;
5
use Psr\Http\Message\MessageInterface;
6
7
class Message implements MessageInterface
8
{
9
10
    use MessageTrait;
11
    
12
    /**
13
     * @param StreamInterface|resource|string $stream
14
     * @param string $mode
15
     * @return \DevOp\Core\Http\Stream|StreamInterface
16
     * @throws \InvalidArgumentException
17
     */
18 2
    public function getStream($stream, $mode = 'r')
19
    {
20 2
        if ($stream instanceof StreamInterface) {
21
            return $stream;
22
        }
23
        
24 2
        if (!is_string($stream) && !is_resource($stream)) {
25
            throw new \InvalidArgumentException('Stream must be a string or resource.');
26
        }
27
        
28 2
        return new Stream($stream, $mode);
29
    }
30
    
31
    /**
32
     * @param array $headers
33
     */
34 2
    public function setHeaders(array $headers = [])
35
    {
36 2
        foreach ($headers AS $header => $value) {
37
            $this->headersName[strtolower($header)] = $header;
38
            $this->headers[$header] = $value;
39
        }
40 2
    }
41
}
42