File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55/**
66 * This object is only meant to provide a callable to `GuzzleHttp\Psr7\PumpStream`.
77 *
8- * @internal don 't use it in your project.
8+ * @internal Don 't use in your project.
99 * @see Credit https://raw.githubusercontent.com/Kevinrob/guzzle-cache-middleware/0a61532ee8bf278a0d875a86a536aeeab592da5a/src/BodyStore.php
1010 */
1111class BodyStore
1212{
13+ /**
14+ * @var string
15+ */
1316 private string $ body ;
1417
15- private $ read = 0 ;
18+ /**
19+ * @var int
20+ */
21+ private int $ read = 0 ;
1622
17- private $ toRead ;
23+ /**
24+ * @var int
25+ */
26+ private int $ toRead ;
1827
28+ /**
29+ * @param string $body
30+ */
1931 public function __construct (string $ body )
2032 {
2133 $ this ->body = $ body ;
22- $ this ->toRead = mb_strlen ($ this ->body );
34+ $ length = mb_strlen ($ body );
35+
36+ $ this ->toRead = is_int ($ length ) ? $ length : 0 ;
2337 }
2438
2539 /**
2640 * @param int $length
27- * @return false| string
41+ * @return string|bool
2842 */
29- public function __invoke (int $ length )
43+ public function __invoke (int $ length ): string | bool
3044 {
3145 if ($ this ->toRead <= 0 ) {
3246 return false ;
3347 }
3448
3549 $ length = min ($ length , $ this ->toRead );
3650
37- $ body = mb_substr (
38- $ this ->body ,
39- $ this ->read ,
40- $ length
41- );
51+ $ body = mb_substr ($ this ->body , $ this ->read , $ length );
4252
4353 $ this ->toRead -= $ length ;
4454 $ this ->read += $ length ;
You can’t perform that action at this time.
0 commit comments