Passed
Push — master ( bd20ef...9d3ba6 )
by Thomas Mauro
15:32 queued 13:44
created

StreamFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createStream() 0 7 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\HTTPlugModule\Adapter;
6
7
use Http\Message\StreamFactory as HttpStreamFactory;
8
use Psr\Http\Message\StreamFactoryInterface;
9
use Psr\Http\Message\StreamInterface;
10
11
class StreamFactory implements HttpStreamFactory
12
{
13
    /** @var StreamFactoryInterface */
14
    private $streamFactory;
15
16
    /**
17
     * StreamFactoryDecorator constructor.
18
     *
19
     * @param StreamFactoryInterface $streamFactory
20
     */
21 5
    public function __construct(StreamFactoryInterface $streamFactory)
22
    {
23 5
        $this->streamFactory = $streamFactory;
24 5
    }
25
26
    /**
27
     * Creates a new PSR-7 stream.
28
     *
29
     * @param string|resource|StreamInterface|null $body
30
     *
31
     * @throws \InvalidArgumentException if the stream body is invalid
32
     * @throws \RuntimeException         if creating the stream from $body fails
33
     *
34
     * @return StreamInterface
35
     */
36 3
    public function createStream($body = null)
37
    {
38 3
        if (\is_resource($body)) {
39 1
            return $this->streamFactory->createStreamFromResource($body);
40
        }
41
42 2
        return $this->streamFactory->createStream((string) ($body ?: ''));
43
    }
44
}
45