Passed
Push — master ( 42b16f...37358f )
by Zlatin
01:56
created

StreamFactory::createStreamFromResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace DevOp\Core\Http\Factory;
3
4
use DevOp\Core\Http\Stream;
5
use Psr\Http\Message\StreamInterface;
6
use Interop\Http\Factory\StreamFactoryInterface;
7
8
class StreamFactory implements StreamFactoryInterface
9
{
10
11
    /**
12
     * @param string $content
13
     * @return StreamInterface
14
     */
15 12
    public function createStream($content = '')
16
    {
17 12
        $resource = fopen("php://temp", "r+");
18 12
        fwrite($resource, $content);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $handle of fwrite() 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

18
        fwrite(/** @scrutinizer ignore-type */ $resource, $content);
Loading history...
19 12
        rewind($resource);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $handle of rewind() 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

19
        rewind(/** @scrutinizer ignore-type */ $resource);
Loading history...
20
21 12
        return $this->createStreamFromResource($resource);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $resource of DevOp\Core\Http\Factory\...ateStreamFromResource() 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

21
        return $this->createStreamFromResource(/** @scrutinizer ignore-type */ $resource);
Loading history...
22
    }
23
24
    /**
25
     * @param string $filename
26
     * @param string $mode
27
     * @return StreamInterface
28
     */
29 4
    public function createStreamFromFile($filename, $mode = 'r')
30
    {
31 4
        $resource = fopen($filename, $mode);
32
33 4
        return $this->createStreamFromResource($resource);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $resource of DevOp\Core\Http\Factory\...ateStreamFromResource() 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

33
        return $this->createStreamFromResource(/** @scrutinizer ignore-type */ $resource);
Loading history...
34
    }
35
36
    /**
37
     * @param resource $resource
38
     * @return StreamInterface
39
     */
40 16
    public function createStreamFromResource($resource)
41
    {
42 16
        var_dump($resource);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($resource) looks like debug code. Are you sure you do not want to remove it?
Loading history...
43 16
        return new Stream($resource);
0 ignored issues
show
Bug introduced by
$resource of type resource is incompatible with the type Psr\Http\Message\StreamInterface expected by parameter $handle of DevOp\Core\Http\Stream::__construct(). ( Ignorable by Annotation )

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

43
        return new Stream(/** @scrutinizer ignore-type */ $resource);
Loading history...
44
    }
45
}
46