PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/s3/GuzzleHttp/Psr7/BufferStream.php +24 -21 1.2.4 → 1.4.2 View file →
@@ -1,6 +1,7 @@
1 1 <?php
2 2
3 +declare (strict_types=1);
3 4 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
4 5
5 6 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
6 7 /**
@@ -9,37 +10,37 @@
9 10 *
10 11 * This stream returns a "hwm" metadata value that tells upstream consumers
11 12 * what the configured high water mark of the stream is, or the maximum
12 13 * preferred size of the buffer.
13 - *
14 - * @final
15 14 */
16 -class BufferStream implements StreamInterface
15 +final class BufferStream implements StreamInterface
17 16 {
17 + /** @var int */
18 18 private $hwm;
19 + /** @var string */
19 20 private $buffer = '';
20 21 /**
21 22 * @param int $hwm High water mark, representing the preferred maximum
22 23 * buffer size. If the size of the buffer exceeds the high
23 24 * water mark, then calls to write will continue to succeed
24 - * but will return false to inform writers to slow down
25 + * but will return 0 to inform writers to slow down
25 26 * until the buffer has been drained by reading from it.
26 27 */
27 - public function __construct($hwm = 16384)
28 + public function __construct(int $hwm = 16384)
28 29 {
29 30 $this->hwm = $hwm;
30 31 }
31 - public function __toString()
32 + public function __toString() : string
32 33 {
33 34 return $this->getContents();
34 35 }
35 - public function getContents()
36 + public function getContents() : string
36 37 {
37 38 $buffer = $this->buffer;
38 39 $this->buffer = '';
39 40 return $buffer;
40 41 }
41 - public function close()
42 + public function close() : void
42 43 {
43 44 $this->buffer = '';
44 45 }
45 46 public function detach()
@@ -46,37 +47,37 @@
46 47 {
47 48 $this->close();
48 49 return null;
49 50 }
50 - public function getSize()
51 + public function getSize() : ?int
51 52 {
52 53 return \strlen($this->buffer);
53 54 }
54 - public function isReadable()
55 + public function isReadable() : bool
55 56 {
56 57 return \true;
57 58 }
58 - public function isWritable()
59 + public function isWritable() : bool
59 60 {
60 61 return \true;
61 62 }
62 - public function isSeekable()
63 + public function isSeekable() : bool
63 64 {
64 65 return \false;
65 66 }
66 - public function rewind()
67 + public function rewind() : void
67 68 {
68 69 $this->seek(0);
69 70 }
70 - public function seek($offset, $whence = \SEEK_SET)
71 + public function seek($offset, $whence = \SEEK_SET) : void
71 72 {
72 73 throw new \RuntimeException('Cannot seek a BufferStream');
73 74 }
74 - public function eof()
75 + public function eof() : bool
75 76 {
76 77 return \strlen($this->buffer) === 0;
77 78 }
78 - public function tell()
79 + public function tell() : int
79 80 {
80 81 throw new \RuntimeException('Cannot determine the position of a BufferStream');
81 82 }
82 83 /**
@@ -81,9 +82,9 @@
81 82 }
82 83 /**
83 84 * Reads data from the buffer.
84 85 */
85 - public function read($length)
86 + public function read($length) : string
86 87 {
87 88 $currentLength = \strlen($this->buffer);
88 89 if ($length >= $currentLength) {
89 90 // No need to slice the buffer because we don't have enough data.
@@ -98,20 +99,22 @@
98 99 }
99 100 /**
100 101 * Writes data to the buffer.
101 102 */
102 - public function write($string)
103 + public function write($string) : int
103 104 {
104 105 $this->buffer .= $string;
105 - // TODO: What should happen here?
106 106 if (\strlen($this->buffer) >= $this->hwm) {
107 - return \false;
107 + return 0;
108 108 }
109 109 return \strlen($string);
110 110 }
111 + /**
112 + * @return mixed
113 + */
111 114 public function getMetadata($key = null)
112 115 {
113 - if ($key == 'hwm') {
116 + if ($key === 'hwm') {
114 117 return $this->hwm;
115 118 }
116 119 return $key ? null : [];
117 120 }