GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 5cefd1...492078 )
by Anton
04:08
created

StreamDecoratorTrait   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 127
rs 10
wmc 23

18 Methods

Rating   Name   Duplication   Size   Complexity  
A isSeekable() 0 3 1
A __toString() 0 12 3
A getContents() 0 3 1
A tell() 0 3 1
A __construct() 0 3 2
A isReadable() 0 3 1
A __call() 0 6 2
A detach() 0 3 1
A eof() 0 3 1
A getSize() 0 3 1
A close() 0 3 1
A write() 0 3 1
A isWritable() 0 3 1
A seek() 0 3 1
A __get() 0 8 2
A read() 0 3 1
A getMetadata() 0 3 1
A rewind() 0 3 1
1
<?php
2
namespace RingCentral\Psr7;
3
4
use Psr\Http\Message\StreamInterface;
5
6
/**
7
 * Stream decorator trait
8
 * @property StreamInterface stream
9
 */
10
abstract class StreamDecoratorTrait implements StreamInterface
11
{
12
    /**
13
     * @param StreamInterface $stream Stream to decorate
14
     */
15
    public function __construct(StreamInterface $stream = null)
16
    {
17
        if ($stream) $this->stream = $stream;
18
    }
19
20
    /**
21
     * Magic method used to create a new stream if streams are not added in
22
     * the constructor of a decorator (e.g., LazyOpenStream).
23
     *
24
     * @param string $name Name of the property (allows "stream" only).
25
     *
26
     * @return StreamInterface
27
     */
28
    public function __get($name)
29
    {
30
        if ($name == 'stream') {
31
            $this->stream = $this->createStream();
0 ignored issues
show
Bug introduced by
The method createStream() does not exist on RingCentral\Psr7\StreamDecoratorTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            /** @scrutinizer ignore-call */ 
32
            $this->stream = $this->createStream();
Loading history...
32
            return $this->stream;
33
        }
34
35
        throw new \UnexpectedValueException("$name not found on class");
36
    }
37
38
    public function __toString()
39
    {
40
        try {
41
            if ($this->isSeekable()) {
42
                $this->seek(0);
43
            }
44
            return $this->getContents();
45
        } catch (\Exception $e) {
46
            // Really, PHP? https://bugs.php.net/bug.php?id=53648
47
            trigger_error('StreamDecorator::__toString exception: '
48
                . (string) $e, E_USER_ERROR);
49
            return '';
50
        }
51
    }
52
53
    public function getContents()
54
    {
55
        return copy_to_string($this);
56
    }
57
58
    /**
59
     * Allow decorators to implement custom methods
60
     *
61
     * @param string $method Missing method name
62
     * @param array  $args   Method arguments
63
     *
64
     * @return mixed
65
     */
66
    public function __call($method, array $args)
67
    {
68
        $result = call_user_func_array(array($this->stream, $method), $args);
69
70
        // Always return the wrapped object if the result is a return $this
71
        return $result === $this->stream ? $this : $result;
72
    }
73
74
    public function close()
75
    {
76
        $this->stream->close();
77
    }
78
79
    public function getMetadata($key = null)
80
    {
81
        return $this->stream->getMetadata($key);
82
    }
83
84
    public function detach()
85
    {
86
        return $this->stream->detach();
87
    }
88
89
    public function getSize()
90
    {
91
        return $this->stream->getSize();
92
    }
93
94
    public function eof()
95
    {
96
        return $this->stream->eof();
97
    }
98
99
    public function tell()
100
    {
101
        return $this->stream->tell();
102
    }
103
104
    public function isReadable()
105
    {
106
        return $this->stream->isReadable();
107
    }
108
109
    public function isWritable()
110
    {
111
        return $this->stream->isWritable();
112
    }
113
114
    public function isSeekable()
115
    {
116
        return $this->stream->isSeekable();
117
    }
118
119
    public function rewind()
120
    {
121
        $this->seek(0);
122
    }
123
124
    public function seek($offset, $whence = SEEK_SET)
125
    {
126
        $this->stream->seek($offset, $whence);
127
    }
128
129
    public function read($length)
130
    {
131
        return $this->stream->read($length);
132
    }
133
134
    public function write($string)
135
    {
136
        return $this->stream->write($string);
137
    }
138
139
}
140