diff options
author | Paramtamtam <[email protected]> | 2019-12-25 23:00:22 +0500 |
---|---|---|
committer | Paramtamtam <[email protected]> | 2019-12-25 23:00:22 +0500 |
commit | 4016bdf2d53faca43408dd28b0809a45d508d338 (patch) | |
tree | 2eda37a4a0c4b5b65ad9a0df067f466be9778707 /src/Diactoros | |
parent | 2e0f9fac31764ff137ff0e1a03bfc332f94e1e0f (diff) |
PHP sources updated (phpstan level MAX)
Diffstat (limited to 'src/Diactoros')
-rw-r--r-- | src/Diactoros/StreamFactory.php | 16 | ||||
-rw-r--r-- | src/Diactoros/UploadedFileFactory.php | 3 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/Diactoros/StreamFactory.php b/src/Diactoros/StreamFactory.php index da0d52ec..cc0a5306 100644 --- a/src/Diactoros/StreamFactory.php +++ b/src/Diactoros/StreamFactory.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace Spiral\RoadRunner\Diactoros; +use RuntimeException; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\StreamInterface; use Zend\Diactoros\Stream; @@ -17,10 +18,16 @@ final class StreamFactory implements StreamFactoryInterface { /** * @inheritdoc + * @throws RuntimeException */ public function createStream(string $content = ''): StreamInterface { - $resource = fopen('php://temp', 'r+'); + $resource = fopen('php://temp', 'rb+'); + + if (! \is_resource($resource)) { + throw new RuntimeException('Cannot create stream'); + } + fwrite($resource, $content); rewind($resource); return $this->createStreamFromResource($resource); @@ -29,9 +36,14 @@ final class StreamFactory implements StreamFactoryInterface /** * @inheritdoc */ - public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface + public function createStreamFromFile(string $file, string $mode = 'rb'): StreamInterface { $resource = fopen($file, $mode); + + if (! \is_resource($resource)) { + throw new RuntimeException('Cannot create stream'); + } + return $this->createStreamFromResource($resource); } diff --git a/src/Diactoros/UploadedFileFactory.php b/src/Diactoros/UploadedFileFactory.php index 4f09fb23..45773287 100644 --- a/src/Diactoros/UploadedFileFactory.php +++ b/src/Diactoros/UploadedFileFactory.php @@ -27,9 +27,10 @@ final class UploadedFileFactory implements UploadedFileFactoryInterface string $clientMediaType = null ): UploadedFileInterface { if ($size === null) { - $size = $stream->getSize(); + $size = (int) $stream->getSize(); } + /** @var resource $stream */ return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); } } |