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

Stream   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
rs 10
c 3
b 0
f 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setContents() 0 4 1
A save() 0 6 1
A getContents() 0 8 2
A __toString() 0 8 2
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
}