summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci-build.yml2
-rw-r--r--.travis.yml3
-rw-r--r--composer.json2
-rw-r--r--phpstan.neon.dist5
-rw-r--r--src/Diactoros/StreamFactory.php16
-rw-r--r--src/Diactoros/UploadedFileFactory.php3
-rw-r--r--src/HttpClient.php8
-rw-r--r--src/Metrics.php32
-rw-r--r--src/MetricsInterface.php28
-rw-r--r--src/PSR7Client.php14
-rw-r--r--src/Worker.php8
11 files changed, 61 insertions, 60 deletions
diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml
index 894d4cc2..339c841a 100644
--- a/.github/workflows/ci-build.yml
+++ b/.github/workflows/ci-build.yml
@@ -60,7 +60,7 @@ jobs:
- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-suggest # --prefer-source
- - name: Analyze PHP source
+ - name: Analyze PHP sources
run: composer analyze
- name: Install Go dependencies
diff --git a/.travis.yml b/.travis.yml
index f3955eb9..a501f7ce 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,6 +13,7 @@ install:
- php composer-setup.php
- php composer.phar install --no-interaction --prefer-source
- find src/ -name "*.php" -print0 | xargs -0 -n1 -P8 php -l
+ - composer analyze
- chmod +x bin/rr && bin/rr get-binary
script:
@@ -72,4 +73,4 @@ jobs:
- sudo add-apt-repository -y ppa:ondrej/php
- sudo apt-get update
- sudo apt-get install -y php7.4-cli php7.4-curl
- - sudo cp `which php7.4` `which php` \ No newline at end of file
+ - sudo cp `which php7.4` `which php`
diff --git a/composer.json b/composer.json
index 12fbdf28..89a837ac 100644
--- a/composer.json
+++ b/composer.json
@@ -25,7 +25,7 @@
"phpstan/phpstan": "~0.12"
},
"scripts": {
- "analyze": "@php ./vendor/bin/phpstan analyze --level max --no-progress --ansi ./src"
+ "analyze": "@php ./vendor/bin/phpstan analyze -c ./phpstan.neon.dist --no-progress --ansi"
},
"autoload": {
"psr-4": {
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
new file mode 100644
index 00000000..c9ffb648
--- /dev/null
+++ b/phpstan.neon.dist
@@ -0,0 +1,5 @@
+parameters:
+ level: 'max'
+ checkMissingIterableValueType: false
+ paths:
+ - src
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);
}
/**