Added more missing native types according to 8.0 standards

This commit is contained in:
Dylan K. Taylor 2022-11-23 14:21:38 +00:00
parent 3b6ff3c42b
commit fdb07cdbcd
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
14 changed files with 31 additions and 108 deletions

View File

@ -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<string, int> $refCounts
* @phpstan-param-out array<string, object> $objects
* @phpstan-param-out array<string, int> $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";
}

View File

@ -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<array<string, mixed>>|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;

View File

@ -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])){

View File

@ -54,18 +54,16 @@ class PlayerCreationEvent extends Event{
}
/**
* @return string
* @phpstan-return class-string<Player>
*/
public function getBaseClass(){
public function getBaseClass() : string{
return $this->baseClass;
}
/**
* @param string $class
* @phpstan-param class-string<Player> $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<Player>
*/
public function getPlayerClass(){
public function getPlayerClass() : string{
return $this->playerClass;
}
/**
* @param string $class
* @phpstan-param class-string<Player> $class
*/
public function setPlayerClass($class) : void{
public function setPlayerClass(string $class) : void{
Utils::testValidInstance($class, $this->baseClass);
$this->playerClass = $class;
}

View File

@ -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;

View File

@ -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");
}

View File

@ -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

View File

@ -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");
}

View File

@ -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<string, mixed> $data
* @phpstan-param-out array<string, mixed> $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)){

View File

@ -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

View File

@ -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){

View File

@ -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();

View File

@ -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;

View File

@ -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();