Completed
Push — master ( a33fba...4cd8af )
by Gabriel
05:33
created

Stream::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 4
nc 1
nop 0
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')));
0 ignored issues
show
Unused Code introduced by
The call to Stream::getMetadata() has too many arguments starting with 'w'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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
}