From df3a69dcb7aa4047a26267d666491f54867fa87b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 17 May 2022 22:42:18 +0100 Subject: [PATCH] Modernize private property declarations in Threaded classes I previously avoided this due to being unsure of the effects; however, it's clear that we already use typed properties on Threaded things in other places anyway, and the only known issues are with uninit properties, and arrays. --- src/network/mcpe/ChunkRequestTask.php | 3 +-- src/network/mcpe/auth/ProcessLoginTask.php | 26 +++++++------------ .../mcpe/compression/CompressBatchTask.php | 13 ++++------ .../mcpe/encryption/PrepareEncryptionTask.php | 17 +++++------- src/network/mcpe/raklib/RakLibServer.php | 7 +++-- src/scheduler/AsyncTask.php | 18 +++++-------- src/scheduler/BulkCurlTask.php | 3 +-- src/utils/ServerKiller.php | 3 +-- src/world/light/LightPopulationTask.php | 9 +++---- 9 files changed, 37 insertions(+), 62 deletions(-) diff --git a/src/network/mcpe/ChunkRequestTask.php b/src/network/mcpe/ChunkRequestTask.php index 5a8c06fa5..712283c3f 100644 --- a/src/network/mcpe/ChunkRequestTask.php +++ b/src/network/mcpe/ChunkRequestTask.php @@ -49,8 +49,7 @@ class ChunkRequestTask extends AsyncTask{ /** @var Compressor */ protected $compressor; - /** @var string */ - private $tiles = ""; + private string $tiles; /** * @phpstan-param (\Closure() : void)|null $onError diff --git a/src/network/mcpe/auth/ProcessLoginTask.php b/src/network/mcpe/auth/ProcessLoginTask.php index 940dd8bad..bfbbeaa79 100644 --- a/src/network/mcpe/auth/ProcessLoginTask.php +++ b/src/network/mcpe/auth/ProcessLoginTask.php @@ -42,39 +42,33 @@ class ProcessLoginTask extends AsyncTask{ private const CLOCK_DRIFT_MAX = 60; - /** @var string */ - private $chain; - /** @var string */ - private $clientDataJwt; + private string $chain; /** - * @var string|null * Whether the keychain signatures were validated correctly. This will be set to an error message if any link in the * keychain is invalid for whatever reason (bad signature, not in nbf-exp window, etc). If this is non-null, the * keychain might have been tampered with. The player will always be disconnected if this is non-null. */ - private $error = "Unknown"; + private ?string $error = "Unknown"; /** - * @var bool * Whether the player is logged into Xbox Live. This is true if any link in the keychain is signed with the Mojang * root public key. */ - private $authenticated = false; - /** @var bool */ - private $authRequired; - - /** @var string|null */ - private $clientPublicKey = null; + private bool $authenticated = false; + private ?string $clientPublicKey = null; /** * @param string[] $chainJwts * @phpstan-param \Closure(bool $isAuthenticated, bool $authRequired, ?string $error, ?string $clientPublicKey) : void $onCompletion */ - public function __construct(array $chainJwts, string $clientDataJwt, bool $authRequired, \Closure $onCompletion){ + public function __construct( + array $chainJwts, + private string $clientDataJwt, + private bool $authRequired, + \Closure $onCompletion + ){ $this->storeLocal(self::TLS_KEY_ON_COMPLETION, $onCompletion); $this->chain = igbinary_serialize($chainJwts); - $this->clientDataJwt = $clientDataJwt; - $this->authRequired = $authRequired; } public function onRun() : void{ diff --git a/src/network/mcpe/compression/CompressBatchTask.php b/src/network/mcpe/compression/CompressBatchTask.php index d13546b3a..e9d5efd71 100644 --- a/src/network/mcpe/compression/CompressBatchTask.php +++ b/src/network/mcpe/compression/CompressBatchTask.php @@ -29,14 +29,11 @@ class CompressBatchTask extends AsyncTask{ private const TLS_KEY_PROMISE = "promise"; - /** @var string */ - private $data; - /** @var Compressor */ - private $compressor; - - public function __construct(string $data, CompressBatchPromise $promise, Compressor $compressor){ - $this->data = $data; - $this->compressor = $compressor; + public function __construct( + private string $data, + CompressBatchPromise $promise, + private Compressor $compressor + ){ $this->storeLocal(self::TLS_KEY_PROMISE, $promise); } diff --git a/src/network/mcpe/encryption/PrepareEncryptionTask.php b/src/network/mcpe/encryption/PrepareEncryptionTask.php index 7b2bee0e8..fe1b742dd 100644 --- a/src/network/mcpe/encryption/PrepareEncryptionTask.php +++ b/src/network/mcpe/encryption/PrepareEncryptionTask.php @@ -39,20 +39,18 @@ class PrepareEncryptionTask extends AsyncTask{ private static ?\OpenSSLAsymmetricKey $SERVER_PRIVATE_KEY = null; - /** @var string */ - private $serverPrivateKey; + private string $serverPrivateKey; - /** @var string|null */ - private $aesKey = null; - /** @var string|null */ - private $handshakeJwt = null; - /** @var string */ - private $clientPub; + private ?string $aesKey = null; + private ?string $handshakeJwt = null; /** * @phpstan-param \Closure(string $encryptionKey, string $handshakeJwt) : void $onCompletion */ - public function __construct(string $clientPub, \Closure $onCompletion){ + public function __construct( + private string $clientPub, + \Closure $onCompletion + ){ if(self::$SERVER_PRIVATE_KEY === null){ $serverPrivateKey = openssl_pkey_new(["ec" => ["curve_name" => "secp384r1"]]); if($serverPrivateKey === false){ @@ -62,7 +60,6 @@ class PrepareEncryptionTask extends AsyncTask{ } $this->serverPrivateKey = igbinary_serialize(openssl_pkey_get_details(self::$SERVER_PRIVATE_KEY)); - $this->clientPub = $clientPub; $this->storeLocal(self::TLS_KEY_ON_COMPLETION, $onCompletion); } diff --git a/src/network/mcpe/raklib/RakLibServer.php b/src/network/mcpe/raklib/RakLibServer.php index e7ee44d2c..674ca9e56 100644 --- a/src/network/mcpe/raklib/RakLibServer.php +++ b/src/network/mcpe/raklib/RakLibServer.php @@ -40,8 +40,7 @@ use function register_shutdown_function; use const PTHREADS_INHERIT_NONE; class RakLibServer extends Thread{ - /** @var InternetAddress */ - private $address; + private InternetAddress $address; /** @var \ThreadedLogger */ protected $logger; @@ -63,8 +62,8 @@ class RakLibServer extends Thread{ protected $serverId; /** @var int */ protected $maxMtuSize; - /** @var int */ - private $protocolVersion; + + private int $protocolVersion; /** @var SleeperNotifier */ protected $mainThreadNotifier; diff --git a/src/scheduler/AsyncTask.php b/src/scheduler/AsyncTask.php index e27a3bcec..f3f506924 100644 --- a/src/scheduler/AsyncTask.php +++ b/src/scheduler/AsyncTask.php @@ -62,19 +62,13 @@ abstract class AsyncTask extends \Threaded{ /** @var \Threaded */ public $progressUpdates; - /** @var scalar|null */ - private $result = null; - /** @var bool */ - private $serialized = false; - /** @var bool */ - private $cancelRun = false; - /** @var bool */ - private $submitted = false; + private string|int|bool|null|float $result = null; + private bool $serialized = false; + private bool $cancelRun = false; + private bool $submitted = false; - /** @var bool */ - private $crashed = false; - /** @var bool */ - private $finished = false; + private bool $crashed = false; + private bool $finished = false; public function run() : void{ $this->result = null; diff --git a/src/scheduler/BulkCurlTask.php b/src/scheduler/BulkCurlTask.php index cd3547175..be57b662d 100644 --- a/src/scheduler/BulkCurlTask.php +++ b/src/scheduler/BulkCurlTask.php @@ -37,8 +37,7 @@ use function igbinary_unserialize; class BulkCurlTask extends AsyncTask{ private const TLS_KEY_COMPLETION_CALLBACK = "completionCallback"; - /** @var string */ - private $operations; + private string $operations; /** * BulkCurlTask constructor. diff --git a/src/utils/ServerKiller.php b/src/utils/ServerKiller.php index 24f8eb37a..67168fe87 100644 --- a/src/utils/ServerKiller.php +++ b/src/utils/ServerKiller.php @@ -31,8 +31,7 @@ class ServerKiller extends Thread{ /** @var int */ public $time; - /** @var bool */ - private $stopped = false; + private bool $stopped = false; /** * @param int $time diff --git a/src/world/light/LightPopulationTask.php b/src/world/light/LightPopulationTask.php index 97d6344ed..94c66e686 100644 --- a/src/world/light/LightPopulationTask.php +++ b/src/world/light/LightPopulationTask.php @@ -40,12 +40,9 @@ class LightPopulationTask extends AsyncTask{ /** @var string */ public $chunk; - /** @var string */ - private $resultHeightMap; - /** @var string */ - private $resultSkyLightArrays; - /** @var string */ - private $resultBlockLightArrays; + private string $resultHeightMap; + private string $resultSkyLightArrays; + private string $resultBlockLightArrays; /** * @phpstan-param \Closure(array $blockLight, array $skyLight, array $heightMap) : void $onCompletion