TextStream::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of slick/http
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Slick\Http\Message\Stream;
13
14
use Psr\Http\Message\StreamInterface;
15
use Slick\Http\Message\Exception\InvalidArgumentException;
16
17
/**
18
 * TextStream
19
 *
20
 * @package Slick\Http\Message\Stream
21
*/
22
class TextStream extends AbstractStream implements StreamInterface
23
{
24
    /**
25
     * Creates a Text Stream
26
     *
27
     * @param string $content
28
     */
29
    public function __construct($content)
30
    {
31
        $stream = fopen('php://memory', 'rw+');
32
        if (\is_resource($stream)) {
33
            fputs($stream, $content);
34
            $this->stream = $stream;
35
            return;
36
        }
37
38
        throw new InvalidArgumentException(
39
            "Could not create stream from content: $content"
40
        );
41
    }
42
}
43