Completed
Push — master ( f28c46...016359 )
by David
11s
created

DiactorosStreamFactory::createStream()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
dl 22
loc 22
ccs 13
cts 13
cp 1
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 12
nc 4
nop 1
crap 5
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 View Code Duplication
final class DiactorosStreamFactory implements StreamFactory
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 || '' === $body) {
28 2
                    return $stream;
29
                }
30
31 2
                $stream->write((string) $body);
32
33 2
                $body = $stream;
34
            }
35 3
        }
36
37 4
        $body->rewind();
38
39 4
        return $body;
40
    }
41
}
42