Completed
Push — master ( e94e29...811d9a )
by Gabriel
06:51 queued 03:51
created

Stream::setContents()   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
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Junty
4
 *
5
 * @author Gabriel Jacinto aka. GabrielJMJ <[email protected]>
6
 * @license MIT License
7
 */
8
 
9
namespace Junty\Stream;
10
11
use GuzzleHttp\Psr7\Stream as GuzzleStream;
12
13
class Stream extends GuzzleStream
14
{
15
    private $contents;
16
17
    /**
18
     * Sets stream contents
19
     *
20
     * @param string $contents
21
     */
22
    public function setContents($contents)
23
    {
24
        $this->contents = $contents;
25
    }
26
27
    /**
28
     * Updates the stream contents
29
     */
30
    public function save()
31
    {
32
        $stream = new self(fopen($this->getMetaData('uri'), 'w'));
33
        $stream->write($this->contents);
34
        $stream->close();
35
    }
36
37
    /**
38
     * If the contents is setted, return it
39
     *
40
     * @return string
41
     */
42
    public function getContents()
43
    {
44
        if (null !== $this->contents) {
45
            return $this->contents;
46
        }
47
48
        return parent::getContents();
49
    }
50
51
    public function __toString()
52
    {
53
        if (null !== $this->contents) {
54
            return $this->contents;
55
        }
56
57
        return parent::__toString();
58
    }
59
}