Completed
Push — master ( 4258f5...c7dbbb )
by Anton
20s
created

StreamFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createStream() 0 7 1
A createStreamFromFile() 0 5 1
A createStreamFromResource() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * High-performance PHP process supervisor and load balancer written in Go
6
 *
7
 * @author Wolfy-J
8
 */
9
10
namespace Spiral\RoadRunner\Diactoros;
11
12
use Psr\Http\Message\StreamFactoryInterface;
13
use Psr\Http\Message\StreamInterface;
14
use Zend\Diactoros\Stream;
15
16
final class StreamFactory implements StreamFactoryInterface
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function createStream(string $content = ''): StreamInterface
22
    {
23
        $resource = fopen('php://temp', 'r+');
24
        fwrite($resource, $content);
25
        rewind($resource);
26
        return $this->createStreamFromResource($resource);
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
33
    {
34
        $resource = fopen($file, $mode);
35
        return $this->createStreamFromResource($resource);
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function createStreamFromResource($resource): StreamInterface
42
    {
43
        return new Stream($resource);
44
    }
45
}