From 1de2307d385961bc7057262520e4a846774fbc52 Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Sat, 9 Dec 2023 10:20:55 -0800 Subject: [PATCH] add explicit type declarations on class properties --- src/core/Coroutine/WaitGroup.php | 6 +++--- src/core/Database/RedisPool.php | 6 +----- src/core/FastCGI/HttpRequest.php | 2 +- src/core/FastCGI/Message.php | 9 +++------ src/core/FastCGI/Record.php | 20 +++++--------------- src/core/FastCGI/Request.php | 2 +- 6 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/core/Coroutine/WaitGroup.php b/src/core/Coroutine/WaitGroup.php index 12f99215..a03d7bc1 100644 --- a/src/core/Coroutine/WaitGroup.php +++ b/src/core/Coroutine/WaitGroup.php @@ -13,11 +13,11 @@ class WaitGroup { - protected $chan; + protected Channel $chan; - protected $count = 0; + protected int $count = 0; - protected $waiting = false; + protected bool $waiting = false; public function __construct(int $delta = 0) { diff --git a/src/core/Database/RedisPool.php b/src/core/Database/RedisPool.php index 6926830a..b965af85 100644 --- a/src/core/Database/RedisPool.php +++ b/src/core/Database/RedisPool.php @@ -20,12 +20,8 @@ */ class RedisPool extends ConnectionPool { - /** @var RedisConfig */ - protected $config; - - public function __construct(RedisConfig $config, int $size = self::DEFAULT_SIZE) + public function __construct(protected RedisConfig $config, int $size = self::DEFAULT_SIZE) { - $this->config = $config; parent::__construct(function () { $redis = new \Redis(); /* Compatible with different versions of Redis extension as much as possible */ diff --git a/src/core/FastCGI/HttpRequest.php b/src/core/FastCGI/HttpRequest.php index d653c1bc..9d821959 100644 --- a/src/core/FastCGI/HttpRequest.php +++ b/src/core/FastCGI/HttpRequest.php @@ -13,7 +13,7 @@ class HttpRequest extends Request { - protected $params = [ + protected array $params = [ 'REQUEST_SCHEME' => 'http', 'REQUEST_METHOD' => 'GET', 'DOCUMENT_ROOT' => '', diff --git a/src/core/FastCGI/Message.php b/src/core/FastCGI/Message.php index c9604c6b..745f03cb 100644 --- a/src/core/FastCGI/Message.php +++ b/src/core/FastCGI/Message.php @@ -13,14 +13,11 @@ class Message { - /** @var array */ - protected $params = []; + protected array $params = []; - /** @var string */ - protected $body = ''; + protected string $body = ''; - /** @var string */ - protected $error = ''; + protected string $error = ''; public function getParam(string $name): ?string { diff --git a/src/core/FastCGI/Record.php b/src/core/FastCGI/Record.php index f731df42..70bb9831 100644 --- a/src/core/FastCGI/Record.php +++ b/src/core/FastCGI/Record.php @@ -20,38 +20,28 @@ class Record implements \Stringable { /** * Identifies the FastCGI protocol version. - * - * @var int */ - protected $version = FastCGI::VERSION_1; + protected int $version = FastCGI::VERSION_1; /** * Identifies the FastCGI record type, i.e. the general function that the record performs. - * - * @var int */ - protected $type = FastCGI::UNKNOWN_TYPE; + protected int $type = FastCGI::UNKNOWN_TYPE; /** * Identifies the FastCGI request to which the record belongs. - * - * @var int */ - protected $requestId = FastCGI::DEFAULT_REQUEST_ID; + protected int $requestId = FastCGI::DEFAULT_REQUEST_ID; /** * Reserved byte for future proposes - * - * @var int */ - protected $reserved = 0; + protected int $reserved = 0; /** * The number of bytes in the contentData component of the record. - * - * @var int */ - private $contentLength = 0; + private int $contentLength = 0; /** * The number of bytes in the paddingData component of the record. diff --git a/src/core/FastCGI/Request.php b/src/core/FastCGI/Request.php index cc54a316..1cd273fe 100644 --- a/src/core/FastCGI/Request.php +++ b/src/core/FastCGI/Request.php @@ -18,7 +18,7 @@ class Request extends Message implements \Stringable { - protected $keepConn = false; + protected bool $keepConn = false; public function __toString(): string {