Passed
Push — master ( 39db36...6e2c57 )
by David
01:54
created

DiactorosStreamFactory::createStream()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 13
c 1
b 0
f 0
nc 7
nop 1
dl 0
loc 25
ccs 7
cts 7
cp 1
crap 7
rs 8.8333
1
<?php
2
3
namespace Http\Message\StreamFactory;
4
5
use Http\Message\StreamFactory;
6
use Laminas\Diactoros\Stream as LaminasStream;
7
use Psr\Http\Message\StreamInterface;
8
use Zend\Diactoros\Stream as ZendStream;
0 ignored issues
show
Bug introduced by
The type Zend\Diactoros\Stream was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Creates Diactoros streams.
12
 *
13
 * @author Михаил Красильников <[email protected]>
14
 *
15
 * @deprecated This will be removed in php-http/message2.0. Consider using the official Diactoros PSR-17 factory
16
 */
17
final class DiactorosStreamFactory implements StreamFactory
18
{
19 9
    /**
20
     * {@inheritdoc}
21 9
     */
22 2
    public function createStream($body = null)
23
    {
24
        if ($body instanceof StreamInterface) {
25 7
            return $body;
26 3
        }
27
28
        if (is_resource($body)) {
29 4
            if (class_exists(LaminasStream::class)) {
30 4
                return new LaminasStream($body);
31 2
            }
32
33
            return new ZendStream($body);
34 4
        }
35
36
        if (class_exists(LaminasStream::class)) {
37
            $stream = new LaminasStream('php://memory', 'rw');
38
        } else {
39
            $stream = new ZendStream('php://memory', 'rw');
40
        }
41
42
        if (null !== $body && '' !== $body) {
43
            $stream->write((string) $body);
44
        }
45
46
        return $stream;
47
    }
48
}
49