From fdb07cdbcd35225b0c062fc0109bd74e43b74962 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 23 Nov 2022 14:21:38 +0000 Subject: [PATCH] Added more missing native types according to 8.0 standards --- src/MemoryManager.php | 9 ++---- src/Server.php | 7 ++--- src/ServerConfigGroup.php | 7 +---- src/event/player/PlayerCreationEvent.php | 12 +++---- src/player/Player.php | 5 +-- src/promise/PromiseResolver.php | 3 +- src/scheduler/AsyncTask.php | 11 ++----- src/scheduler/AsyncWorker.php | 8 ++--- src/utils/Config.php | 40 +++++------------------- src/utils/Filesystem.php | 7 +---- src/utils/Internet.php | 4 +-- src/utils/MainLogger.php | 8 +---- src/utils/Timezone.php | 9 ++---- src/utils/Utils.php | 9 ++---- 14 files changed, 31 insertions(+), 108 deletions(-) diff --git a/src/MemoryManager.php b/src/MemoryManager.php index 70e5d8a77..9b35c952f 100644 --- a/src/MemoryManager.php +++ b/src/MemoryManager.php @@ -285,10 +285,8 @@ class MemoryManager{ /** * Static memory dumper accessible from any thread. - * - * @param mixed $startingObject */ - public static function dumpMemory($startingObject, string $outputFolder, int $maxNesting, int $maxStringSize, \Logger $logger) : void{ + public static function dumpMemory(mixed $startingObject, string $outputFolder, int $maxNesting, int $maxStringSize, \Logger $logger) : void{ $hardLimit = Utils::assumeNotFalse(ini_get('memory_limit'), "memory_limit INI directive should always exist"); ini_set('memory_limit', '-1'); gc_disable(); @@ -479,7 +477,6 @@ class MemoryManager{ } /** - * @param mixed $from * @param object[] $objects reference parameter * @param int[] $refCounts reference parameter * @@ -487,10 +484,8 @@ class MemoryManager{ * @phpstan-param array $refCounts * @phpstan-param-out array $objects * @phpstan-param-out array $refCounts - * - * @return mixed */ - private static function continueDump($from, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize){ + private static function continueDump(mixed $from, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize) : mixed{ if($maxNesting <= 0){ return "(error) NESTING LIMIT REACHED"; } diff --git a/src/Server.php b/src/Server.php index e0eb84c1f..4c4f25348 100644 --- a/src/Server.php +++ b/src/Server.php @@ -470,10 +470,7 @@ class Server{ return $this->configGroup->getPropertyBool("player.save-player-data", true); } - /** - * @return OfflinePlayer|Player - */ - public function getOfflinePlayer(string $name){ + public function getOfflinePlayer(string $name) : Player|OfflinePlayer|null{ $name = strtolower($name); $result = $this->getPlayerExact($name); @@ -1538,7 +1535,7 @@ class Server{ * @param mixed[][]|null $trace * @phpstan-param list>|null $trace */ - public function exceptionHandler(\Throwable $e, $trace = null) : void{ + public function exceptionHandler(\Throwable $e, ?array $trace = null) : void{ while(@ob_end_flush()){} global $lastError; diff --git a/src/ServerConfigGroup.php b/src/ServerConfigGroup.php index 0a3b09c87..b4a3a9087 100644 --- a/src/ServerConfigGroup.php +++ b/src/ServerConfigGroup.php @@ -43,12 +43,7 @@ final class ServerConfigGroup{ private Config $serverProperties ){} - /** - * @param mixed $defaultValue - * - * @return mixed - */ - public function getProperty(string $variable, $defaultValue = null){ + public function getProperty(string $variable, mixed $defaultValue = null) : mixed{ if(!array_key_exists($variable, $this->propertyCache)){ $v = getopt("", ["$variable::"]); if(isset($v[$variable])){ diff --git a/src/event/player/PlayerCreationEvent.php b/src/event/player/PlayerCreationEvent.php index 7e7e2cfaa..7f76f5f52 100644 --- a/src/event/player/PlayerCreationEvent.php +++ b/src/event/player/PlayerCreationEvent.php @@ -54,18 +54,16 @@ class PlayerCreationEvent extends Event{ } /** - * @return string * @phpstan-return class-string */ - public function getBaseClass(){ + public function getBaseClass() : string{ return $this->baseClass; } /** - * @param string $class * @phpstan-param class-string $class */ - public function setBaseClass($class) : void{ + public function setBaseClass(string $class) : void{ if(!is_a($class, $this->baseClass, true)){ throw new \RuntimeException("Base class $class must extend " . $this->baseClass); } @@ -74,18 +72,16 @@ class PlayerCreationEvent extends Event{ } /** - * @return string * @phpstan-return class-string */ - public function getPlayerClass(){ + public function getPlayerClass() : string{ return $this->playerClass; } /** - * @param string $class * @phpstan-param class-string $class */ - public function setPlayerClass($class) : void{ + public function setPlayerClass(string $class) : void{ Utils::testValidInstance($class, $this->baseClass); $this->playerClass = $class; } diff --git a/src/player/Player.php b/src/player/Player.php index 6c045836f..4f99c93a4 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2054,10 +2054,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ } } - /** - * @param mixed $responseData - */ - public function onFormSubmit(int $formId, $responseData) : bool{ + public function onFormSubmit(int $formId, mixed $responseData) : bool{ if(!isset($this->forms[$formId])){ $this->logger->debug("Got unexpected response for form $formId"); return false; diff --git a/src/promise/PromiseResolver.php b/src/promise/PromiseResolver.php index 30a60e0cd..97b181d0b 100644 --- a/src/promise/PromiseResolver.php +++ b/src/promise/PromiseResolver.php @@ -38,10 +38,9 @@ final class PromiseResolver{ } /** - * @param mixed $value * @phpstan-param TValue $value */ - public function resolve($value) : void{ + public function resolve(mixed $value) : void{ if($this->shared->resolved){ throw new \LogicException("Promise has already been resolved/rejected"); } diff --git a/src/scheduler/AsyncTask.php b/src/scheduler/AsyncTask.php index 65591d4d9..13a4f5781 100644 --- a/src/scheduler/AsyncTask.php +++ b/src/scheduler/AsyncTask.php @@ -124,10 +124,7 @@ abstract class AsyncTask extends \Threaded{ return $this->result; } - /** - * @param mixed $result - */ - public function setResult($result) : void{ + public function setResult(mixed $result) : void{ $this->result = ($this->serialized = !is_scalar($result)) ? igbinary_serialize($result) : $result; } @@ -166,7 +163,7 @@ abstract class AsyncTask extends \Threaded{ * * @param mixed $progress A value that can be safely serialize()'ed. */ - public function publishProgress($progress) : void{ + public function publishProgress(mixed $progress) : void{ $this->progressUpdates[] = igbinary_serialize($progress); } @@ -213,10 +210,8 @@ abstract class AsyncTask extends \Threaded{ * * Objects stored in this storage can be retrieved using fetchLocal() on the same thread that this method was called * from. - * - * @param mixed $complexData the data to store */ - protected function storeLocal(string $key, $complexData) : void{ + protected function storeLocal(string $key, mixed $complexData) : void{ if(self::$threadLocalStorage === null){ /* * It's necessary to use an object (not array) here because pthreads is stupid. Non-default array statics diff --git a/src/scheduler/AsyncWorker.php b/src/scheduler/AsyncWorker.php index af1ec2ad6..0b7087571 100644 --- a/src/scheduler/AsyncWorker.php +++ b/src/scheduler/AsyncWorker.php @@ -76,10 +76,8 @@ class AsyncWorker extends Worker{ /** * Saves mixed data into the worker's thread-local object store. This can be used to store objects which you * want to use on this worker thread from multiple AsyncTasks. - * - * @param mixed $value */ - public function saveToThreadStore(string $identifier, $value) : void{ + public function saveToThreadStore(string $identifier, mixed $value) : void{ if(\Thread::getCurrentThread() !== $this){ throw new \LogicException("Thread-local data can only be stored in the thread context"); } @@ -93,10 +91,8 @@ class AsyncWorker extends Worker{ * account for the possibility that what you're trying to retrieve might not exist. * * Objects stored in this storage may ONLY be retrieved while the task is running. - * - * @return mixed */ - public function getFromThreadStore(string $identifier){ + public function getFromThreadStore(string $identifier) : mixed{ if(\Thread::getCurrentThread() !== $this){ throw new \LogicException("Thread-local data can only be fetched in the thread context"); } diff --git a/src/utils/Config.php b/src/utils/Config.php index eab5174e9..cee137e32 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -341,11 +341,7 @@ class Config{ $this->remove($k); } - /** - * @param string $key - * @param mixed $value - */ - public function setNested($key, $value) : void{ + public function setNested(string $key, mixed $value) : void{ $vars = explode(".", $key); $base = array_shift($vars); @@ -368,13 +364,7 @@ class Config{ $this->changed = true; } - /** - * @param string $key - * @param mixed $default - * - * @return mixed - */ - public function getNested($key, $default = null){ + public function getNested(string $key, mixed $default = null) : mixed{ if(isset($this->nestedCache[$key])){ return $this->nestedCache[$key]; } @@ -420,21 +410,11 @@ class Config{ } } - /** - * @param string $k - * @param mixed $default - * - * @return bool|mixed - */ - public function get($k, $default = false){ + public function get(string $k, mixed $default = false) : mixed{ return $this->config[$k] ?? $default; } - /** - * @param string $k key to be set - * @param mixed $v value to set key - */ - public function set($k, $v = true) : void{ + public function set(string $k, mixed $v = true) : void{ $this->config[$k] = $v; $this->changed = true; foreach(Utils::stringifyKeys($this->nestedCache) as $nestedKey => $nvalue){ @@ -454,10 +434,9 @@ class Config{ } /** - * @param string $k - * @param bool $lowercase If set, searches Config in single-case / lowercase. + * @param bool $lowercase If set, searches Config in single-case / lowercase. */ - public function exists($k, bool $lowercase = false) : bool{ + public function exists(string $k, bool $lowercase = false) : bool{ if($lowercase){ $k = strtolower($k); //Convert requested key to lower $array = array_change_key_case($this->config, CASE_LOWER); //Change all keys in array to lower @@ -467,10 +446,7 @@ class Config{ } } - /** - * @param string $k - */ - public function remove($k) : void{ + public function remove(string $k) : void{ unset($this->config[$k]); $this->changed = true; } @@ -498,7 +474,7 @@ class Config{ * @phpstan-param array $data * @phpstan-param-out array $data */ - private function fillDefaults(array $default, &$data) : int{ + private function fillDefaults(array $default, array &$data) : int{ $changed = 0; foreach(Utils::stringifyKeys($default) as $k => $v){ if(is_array($v)){ diff --git a/src/utils/Filesystem.php b/src/utils/Filesystem.php index a4c1ff236..762d39c3b 100644 --- a/src/utils/Filesystem.php +++ b/src/utils/Filesystem.php @@ -159,12 +159,7 @@ final class Filesystem{ */ public static function getCleanedPaths() : array{ return self::$cleanedPaths; } - /** - * @param string $path - * - * @return string - */ - public static function cleanPath($path){ + public static function cleanPath(string $path) : string{ $result = str_replace([DIRECTORY_SEPARATOR, ".php", "phar://"], ["/", "", ""], $path); //remove relative paths diff --git a/src/utils/Internet.php b/src/utils/Internet.php index 8744ebd96..87a90f488 100644 --- a/src/utils/Internet.php +++ b/src/utils/Internet.php @@ -71,10 +71,8 @@ class Internet{ * Lazily gets the External IP using an external service and caches the result * * @param bool $force default false, force IP check even when cached - * - * @return string|false */ - public static function getIP(bool $force = false){ + public static function getIP(bool $force = false) : string|false{ if(!self::$online){ return false; }elseif(self::$ip !== false && !$force){ diff --git a/src/utils/MainLogger.php b/src/utils/MainLogger.php index 641233a26..6f65303bf 100644 --- a/src/utils/MainLogger.php +++ b/src/utils/MainLogger.php @@ -172,13 +172,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{ } } - /** - * @param string $message - * @param string $level - * @param string $prefix - * @param string $color - */ - protected function send($message, $level, $prefix, $color) : void{ + protected function send(string $message, string $level, string $prefix, string $color) : void{ $time = new \DateTime('now', new \DateTimeZone($this->timezone)); $thread = \Thread::getCurrentThread(); diff --git a/src/utils/Timezone.php b/src/utils/Timezone.php index 3cf3a19df..8564bd85c 100644 --- a/src/utils/Timezone.php +++ b/src/utils/Timezone.php @@ -101,10 +101,7 @@ abstract class Timezone{ \GlobalLogger::get()->warning("Timezone could not be automatically determined or was set to an invalid value. An incorrect timezone will result in incorrect timestamps on console logs. It has been set to \"UTC\" by default. You can change it on the php.ini file."); } - /** - * @return string|false - */ - public static function detectSystemTimezone(){ + public static function detectSystemTimezone() : string|false{ switch(Utils::getOS()){ case Utils::OS_WINDOWS: $regex = '/(UTC)(\+*\-*\d*\d*\:*\d*\d*)/'; @@ -178,10 +175,8 @@ abstract class Timezone{ /** * @param string $offset In the format of +09:00, +02:00, -04:00 etc. - * - * @return string|false */ - private static function parseOffset($offset){ + private static function parseOffset(string $offset) : string|false{ //Make signed offsets unsigned for date_parse if(strpos($offset, '-') !== false){ $negative_offset = true; diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 3e8e420b7..4f3f6d577 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -345,10 +345,8 @@ final class Utils{ /** * Returns a string that can be printed, replaces non-printable characters - * - * @param mixed $str */ - public static function printable($str) : string{ + public static function printable(mixed $str) : string{ if(!is_string($str)){ return gettype($str); } @@ -369,10 +367,7 @@ final class Utils{ return $hash; } - /** - * @param object $value - */ - public static function getReferenceCount($value, bool $includeCurrent = true) : int{ + public static function getReferenceCount(object $value, bool $includeCurrent = true) : int{ ob_start(); debug_zval_dump($value); $contents = ob_get_contents();