Completed
Branch full-rewrite (4754d3)
by Thibaud
03:13
created

StringReader::getContents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Alchemy\Zippy\Resource\Reader;
4
5
use Alchemy\Zippy\Resource\ResourceReader;
6
7
class StringReader implements ResourceReader
8
{
9
    /**
10
     * @var string
11
     */
12
    private $contents;
13
14
    /**
15
     * @param string $contents
16
     */
17
    public function __construct($contents)
18
    {
19
        $this->contents = (string) $contents;
20
    }
21
22
    /**
23
     * @return string
24
     */
25
    public function getContents()
26
    {
27
        return $this->contents;
28
    }
29
30
    /**
31
     * @return resource
32
     */
33
    public function getContentsAsStream()
34
    {
35
        $stream = fopen('php://temp', 'rw');
36
37
        fwrite($stream, $this->contents);
38
        fseek($stream, 0);
39
40
        return $stream;
41
    }
42
}
43