Passed
Push — master ( 5679ef...aad9e9 )
by Kirill
04:11
created

StreamFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createStream() 0 6 1
A createStreamFromFile() 0 4 1
A createStreamFromResource() 0 3 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Auth\Diactoros;
13
14
use Psr\Http\Message\StreamFactoryInterface;
15
use Psr\Http\Message\StreamInterface;
16
use Laminas\Diactoros\Stream;
17
18
final class StreamFactory implements StreamFactoryInterface
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public function createStream(string $content = ''): StreamInterface
24
    {
25
        $resource = fopen('php://temp', 'rb+');
26
        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

26
        fwrite(/** @scrutinizer ignore-type */ $resource, $content);
Loading history...
27
        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

27
        rewind(/** @scrutinizer ignore-type */ $resource);
Loading history...
28
        return $this->createStreamFromResource($resource);
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function createStreamFromFile(string $file, string $mode = 'rb'): StreamInterface
35
    {
36
        $resource = fopen($file, $mode);
37
        return $this->createStreamFromResource($resource);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function createStreamFromResource($resource): StreamInterface
44
    {
45
        return new Stream($resource);
46
    }
47
}
48