Completed
Push — master ( 62eba7...9fc3a4 )
by Márk
08:43 queued 05:59
created

DiactorosStreamFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createStream() 0 20 4
1
<?php
2
3
namespace Http\Message\StreamFactory;
4
5
use Http\Message\StreamFactory;
6
use Psr\Http\Message\StreamInterface;
7
use Zend\Diactoros\Stream;
8
9
/**
10
 * Creates Diactoros streams.
11
 *
12
 * @author Михаил Красильников <[email protected]>
13
 */
14
final class DiactorosStreamFactory implements StreamFactory
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 6
    public function createStream($body = null)
20
    {
21 6
        if (!$body instanceof StreamInterface) {
22 5
            if (is_resource($body)) {
23 1
                $body = new Stream($body);
24 1
            } else {
25 4
                $stream = new Stream('php://memory', 'rw');
26
27 4
                if (null !== $body) {
28 1
                    $stream->write((string) $body);
29 1
                }
30
31 4
                $body = $stream;
32
            }
33 5
        }
34
35 6
        $body->rewind();
36
37 6
        return $body;
38
    }
39
}
40