Completed
Pull Request — master (#70)
by Márk
01:58
created

DiactorosStreamFactory::createStream()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
dl 20
loc 20
ccs 13
cts 13
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
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 4
                    $stream->write((string) $body);
29 4
                }
30
31 4
                $body = $stream;
32
            }
33 5
        }
34
35 6
        $body->rewind();
36
37 6
        return $body;
38
    }
39
}
40