Passed
Pull Request — master (#653)
by Aleksei
07:43
created

StreamFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3
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\Http\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', 'r+');
26
        fwrite($resource, $content);
27
        rewind($resource);
28
        return $this->createStreamFromResource($resource);
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function createStreamFromFile(string $file, string $mode = 'r'): 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