@@ -40,8 +40,8 @@ class MultipartStreamBuilder
40
40
41
41
/**
42
42
* @var int Bytes of unallocated memory to use for stream buffer.
43
- * To have MultipartStreamBuilder manage it automatically, set to -1.
44
- * Default: -1
43
+ * To have MultipartStreamBuilder manage it automatically, set to -1.
44
+ * Default: -1
45
45
*/
46
46
private $ bufferMaxMemory = -1 ;
47
47
@@ -80,12 +80,10 @@ public function __construct($streamFactory = null)
80
80
}
81
81
82
82
/**
83
- * Add a resource to the Multipart Stream
83
+ * Add a resource to the Multipart Stream.
84
84
*
85
- * @param string|resource|\Psr\Http\Message\StreamInterface $resource
86
- * The filepath, resource or StreamInterface of the data.
87
- * @param array $headers
88
- * Additional headers array: ['header-name' => 'header-value'].
85
+ * @param string|resource|\Psr\Http\Message\StreamInterface $resource The filepath, resource or StreamInterface of the data.
86
+ * @param array $headers Additional headers array: ['header-name' => 'header-value'].
89
87
*
90
88
* @return MultipartStreamBuilder
91
89
*/
@@ -151,7 +149,7 @@ public function build()
151
149
// Open a temporary read-write stream as buffer.
152
150
// If the size is less than predefined limit, things will stay in memory.
153
151
// If the size is more than that, things will be stored in temp file.
154
- $ buffer = fopen ('php://temp/maxmemory: ' . $ maxmemory , 'r+ ' );
152
+ $ buffer = fopen ('php://temp/maxmemory: ' . $ maxmemory , 'r+ ' );
155
153
foreach ($ this ->data as $ data ) {
156
154
// Add start and headers
157
155
fwrite ($ buffer , "-- {$ this ->getBoundary ()}\r\n" .
@@ -379,11 +377,8 @@ private function createStream($resource)
379
377
* in memory if the size of the stream is smaller than this size.
380
378
* Otherwise, PHP will store the stream data in a temporary file.
381
379
*
382
- * @param integer $size
383
- * Size of stream data buffered (in bytes) until using temporary
384
- * file to buffer.
385
- *
386
- * @return MultipartStreamBuilder
380
+ * @param int $size Size of stream data buffered (in bytes)
381
+ * until using temporary file to buffer.
387
382
*/
388
383
public function setBufferMaxMemory (int $ size ): MultipartStreamBuilder
389
384
{
@@ -395,26 +390,23 @@ public function setBufferMaxMemory(int $size): MultipartStreamBuilder
395
390
/**
396
391
* Get and parse memory_limit into bytes integer.
397
392
*
398
- * @return integer
399
- *
400
- * @throws \Exception
401
- * If the ini format does not match expectation.
393
+ * @throws \Exception If the ini format does not match expectation.
402
394
*/
403
395
protected static function getAvailableMemory (): int
404
396
{
405
397
$ memory_limit = ini_get ('memory_limit ' );
406
- if ($ memory_limit === ' -1 ' ) {
398
+ if (' -1 ' === $ memory_limit ) {
407
399
// If there is no memory limit, return 100MB by default.
408
400
return 100 * 1024 * 1024 ;
409
401
}
410
402
if (!preg_match ('/^(\d+)(G|M|K|)$/ ' , $ memory_limit , $ matches )) {
411
403
throw new \Exception ("Unknown memory_limit format: {$ memory_limit }" );
412
404
}
413
- if ($ matches [2 ] == ' G ' ) {
405
+ if (' G ' === $ matches [2 ]) {
414
406
$ memory_limit = $ matches [1 ] * 1024 * 1024 * 1024 ; // nnnG -> nnn GB
415
- } else if ( $ matches [2 ] == ' M ' ) {
407
+ } elseif ( ' M ' === $ matches [2 ]) {
416
408
$ memory_limit = $ matches [1 ] * 1024 * 1024 ; // nnnM -> nnn MB
417
- } else if ( $ matches [2 ] == ' K ' ) {
409
+ } elseif ( ' K ' === $ matches [2 ]) {
418
410
$ memory_limit = $ matches [1 ] * 1024 ; // nnnK -> nnn KB
419
411
}
420
412
return (int ) $ memory_limit - \memory_get_usage ();
0 commit comments