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

StreamFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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