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 | |
parent | 2e0f9fac31764ff137ff0e1a03bfc332f94e1e0f (diff) |
PHP sources updated (phpstan level MAX)
Diffstat (limited to 'src')
-rw-r--r-- | src/Diactoros/StreamFactory.php | 16 | ||||
-rw-r--r-- | src/Diactoros/UploadedFileFactory.php | 3 | ||||
-rw-r--r-- | src/HttpClient.php | 8 | ||||
-rw-r--r-- | src/Metrics.php | 32 | ||||
-rw-r--r-- | src/MetricsInterface.php | 28 | ||||
-rw-r--r-- | src/PSR7Client.php | 14 | ||||
-rw-r--r-- | src/Worker.php | 8 |
7 files changed, 52 insertions, 57 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); } } diff --git a/src/HttpClient.php b/src/HttpClient.php index 6308eabc..42c434a8 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -31,8 +31,8 @@ final class HttpClient } /** - * @return array|null Request information as ['ctx'=>[], 'body'=>string] - * or null if termination request or invalid context. + * @return mixed[]|null Request information as ['ctx'=>[], 'body'=>string] + * or null if termination request or invalid context. */ public function acceptRequest() { @@ -43,7 +43,7 @@ final class HttpClient } $ctx = json_decode($ctx, true); - if (is_null($ctx)) { + if ($ctx === null) { // invalid context return null; } @@ -69,7 +69,7 @@ final class HttpClient $this->getWorker()->send( $body, - json_encode(['status' => $status, 'headers' => $headers]) + (string) json_encode(['status' => $status, 'headers' => $headers]) ); } } diff --git a/src/Metrics.php b/src/Metrics.php index 6fe4c4f5..d6b6e1da 100644 --- a/src/Metrics.php +++ b/src/Metrics.php @@ -31,13 +31,7 @@ final class Metrics implements MetricsInterface } /** - * Add collector value. Fallback to appropriate method of related collector. - * - * @param string $name - * @param float $value - * @param array $labels - * - * @throws MetricException + * @inheritDoc */ public function add(string $name, float $value, array $labels = []): void { @@ -49,13 +43,7 @@ final class Metrics implements MetricsInterface } /** - * Subtract the collector value, only for gauge collector. - * - * @param string $name - * @param float $value - * @param array $labels - * - * @throws MetricException + * @inheritDoc */ public function sub(string $name, float $value, array $labels = []): void { @@ -67,13 +55,7 @@ final class Metrics implements MetricsInterface } /** - * Observe collector value, only for histogram and summary collectors. - * - * @param string $name - * @param float $value - * @param array $labels - * - * @throws MetricException + * @inheritDoc */ public function observe(string $name, float $value, array $labels = []): void { @@ -85,13 +67,7 @@ final class Metrics implements MetricsInterface } /** - * Set collector value, only for gauge collector. - * - * @param string $name - * @param float $value - * @param array $labels - * - * @throws MetricException + * @inheritDoc */ public function set(string $name, float $value, array $labels = []): void { diff --git a/src/MetricsInterface.php b/src/MetricsInterface.php index e0e2260a..ec2009b0 100644 --- a/src/MetricsInterface.php +++ b/src/MetricsInterface.php @@ -17,44 +17,48 @@ interface MetricsInterface /** * Add collector value. Fallback to appropriate method of related collector. * - * @param string $collector - * @param float $value - * @param array $labels + * @param string $collector + * @param float $value + * @param mixed[] $labels * * @throws MetricException + * @return void */ public function add(string $collector, float $value, array $labels = []); /** * Subtract the collector value, only for gauge collector. * - * @param string $collector - * @param float $value - * @param array $labels + * @param string $collector + * @param float $value + * @param mixed[] $labels * * @throws MetricException + * @return void */ public function sub(string $collector, float $value, array $labels = []); /** * Observe collector value, only for histogram and summary collectors. * - * @param string $collector - * @param float $value - * @param array $labels + * @param string $collector + * @param float $value + * @param mixed[] $labels * * @throws MetricException + * @return void */ public function observe(string $collector, float $value, array $labels = []); /** * Set collector value, only for gauge collector. * - * @param string $collector - * @param float $value - * @param array $labels + * @param string $collector + * @param float $value + * @param mixed[] $labels * * @throws MetricException + * @return void */ public function set(string $collector, float $value, array $labels = []); } diff --git a/src/PSR7Client.php b/src/PSR7Client.php index 7393848a..98897890 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace Spiral\RoadRunner; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\ServerRequestFactoryInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; @@ -29,12 +30,13 @@ class PSR7Client /** @var StreamFactoryInterface */ private $streamFactory; - /*** @var UploadedFileFactoryInterface */ + /** @var UploadedFileFactoryInterface */ private $uploadsFactory; + /** @var mixed[] */ private $originalServer = []; - /** @var array Valid values for HTTP protocol version */ + /** @var string[] Valid values for HTTP protocol version */ private static $allowedVersions = ['1.0', '1.1', '2',]; /** @@ -127,8 +129,8 @@ class PSR7Client * Returns altered copy of _SERVER variable. Sets ip-address, * request-time and other values. * - * @param array $ctx - * @return array + * @param mixed[] $ctx + * @return mixed[] */ protected function configureServer(array $ctx): array { @@ -156,9 +158,9 @@ class PSR7Client /** * Wraps all uploaded files with UploadedFile. * - * @param array $files + * @param array[] $files * - * @return array + * @return UploadedFileInterface[]|mixed[] */ private function wrapUploads($files): array { diff --git a/src/Worker.php b/src/Worker.php index 87dcc9ce..35294221 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -66,7 +66,7 @@ class Worker } if ($flags & Relay::PAYLOAD_ERROR) { - return new \Error($body); + return new \Error((string) $body); } return $body; @@ -83,13 +83,13 @@ class Worker */ public function send(string $payload = null, string $header = null): void { - if (is_null($header)) { - $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); + if ($header === null) { + $this->relay->send('', Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); } else { $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); } - $this->relay->send($payload, Relay::PAYLOAD_RAW); + $this->relay->send((string) $payload, Relay::PAYLOAD_RAW); } /** |