1 | <?php |
||
13 | class AppendStream implements StreamInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var StreamInterface[] Streams being decorated |
||
17 | */ |
||
18 | private $streams; |
||
19 | |||
20 | /** |
||
21 | * @var bool |
||
22 | */ |
||
23 | private $seekable; |
||
24 | |||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | private $current; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | private $pos; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $detached; |
||
39 | |||
40 | /** |
||
41 | * @param StreamInterface[] $streams Streams to decorate. Each stream must |
||
42 | * be readable. |
||
43 | */ |
||
44 | 23 | public function __construct(array $streams = []) |
|
56 | |||
57 | 5 | public function __toString() |
|
66 | |||
67 | /** |
||
68 | * Add a stream to the AppendStream |
||
69 | * |
||
70 | * @param StreamInterface $stream Stream to append. Must be readable. |
||
71 | * |
||
72 | * @return $this |
||
73 | * @throws \InvalidArgumentException if the stream is not readable |
||
74 | */ |
||
75 | 17 | public function addStream(StreamInterface $stream) : self |
|
90 | |||
91 | 5 | public function getContents() |
|
95 | |||
96 | /** |
||
97 | * Closes each attached stream. |
||
98 | * |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 3 | public function close() |
|
111 | |||
112 | /** |
||
113 | * Detaches each attached stream |
||
114 | * |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | 2 | public function detach() |
|
123 | |||
124 | 2 | public function tell() |
|
128 | |||
129 | /** |
||
130 | * Tries to calculate the size by adding the size of each stream. |
||
131 | * |
||
132 | * If any of the streams do not return a valid number, then the size of the |
||
133 | * append stream cannot be determined and null is returned. |
||
134 | * |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 3 | public function getSize() |
|
153 | |||
154 | 11 | public function eof() : bool |
|
159 | |||
160 | 5 | public function rewind() |
|
164 | |||
165 | /** |
||
166 | * Attempts to seek to the given position. Only supports SEEK_SET. |
||
167 | * |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | 12 | public function seek($offset, $whence = SEEK_SET) |
|
202 | |||
203 | /** |
||
204 | * Reads from all of the appended streams until the length is met or EOF. |
||
205 | * |
||
206 | * {@inheritdoc} |
||
207 | */ |
||
208 | 9 | public function read($length) |
|
244 | |||
245 | 1 | public function isReadable() : bool |
|
249 | |||
250 | 1 | public function isWritable() : bool |
|
254 | |||
255 | 5 | public function isSeekable() : bool |
|
259 | |||
260 | 1 | public function write($string) |
|
264 | |||
265 | 1 | public function getMetadata($key = null) |
|
269 | } |
||
270 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.