SlimStreamFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10
c 4
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A createStream() 0 17 5
1
<?php
2
3
namespace Http\Message\StreamFactory;
4
5
use Http\Message\StreamFactory;
6
use Psr\Http\Message\StreamInterface;
7
use Slim\Http\Stream;
8
9
/**
10
 * Creates Slim 3 streams.
11
 *
12
 * @author Mika Tuupola <[email protected]>
13
 *
14
 * @deprecated This will be removed in php-http/message2.0. Consider using the official Slim PSR-17 factory
15
 */
16
final class SlimStreamFactory implements StreamFactory
17
{
18
    /**
19 9
     * {@inheritdoc}
20
     */
21 9
    public function createStream($body = null)
22 2
    {
23
        if ($body instanceof StreamInterface) {
24
            return $body;
25 7
        }
26 3
27
        if (is_resource($body)) {
28
            return new Stream($body);
29 4
        }
30 4
31 4
        $resource = fopen('php://memory', 'r+');
32 2
        $stream = new Stream($resource);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $stream of Slim\Http\Stream::__construct() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        $stream = new Stream(/** @scrutinizer ignore-type */ $resource);
Loading history...
33
        if (null !== $body && '' !== $body) {
34
            $stream->write((string) $body);
35 4
        }
36
37
        return $stream;
38
    }
39
}
40