mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
added native types to closures (phpstan-strict-rules)
This commit is contained in:
parent
fd2a7797bd
commit
fa82cb26d8
@ -62,7 +62,7 @@ function preg_quote_array(array $strings, string $delim = null) : array{
|
||||
*/
|
||||
function buildPhar(string $pharPath, string $basePath, array $includedPaths, array $metadata, string $stub, int $signatureAlgo = \Phar::SHA1, ?int $compression = null){
|
||||
$basePath = rtrim(str_replace("/", DIRECTORY_SEPARATOR, $basePath), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
$includedPaths = array_map(function($path){
|
||||
$includedPaths = array_map(function(string $path) : string{
|
||||
return rtrim(str_replace("/", DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
}, $includedPaths);
|
||||
yield "Creating output file $pharPath";
|
||||
|
@ -1051,7 +1051,7 @@ class Server{
|
||||
}
|
||||
$path = $this->getDataPath() . "worlds/" . $name . "/";
|
||||
if(!($this->getLevelByName($name) instanceof Level)){
|
||||
return is_dir($path) and count(array_filter(scandir($path, SCANDIR_SORT_NONE), function($v){
|
||||
return is_dir($path) and count(array_filter(scandir($path, SCANDIR_SORT_NONE), function(string $v) : bool{
|
||||
return $v !== ".." and $v !== ".";
|
||||
})) > 0;
|
||||
}
|
||||
@ -1284,7 +1284,7 @@ class Server{
|
||||
* @return void
|
||||
*/
|
||||
public static function microSleep(int $microseconds){
|
||||
Server::$sleeper->synchronized(function(int $ms){
|
||||
Server::$sleeper->synchronized(function(int $ms) : void{
|
||||
Server::$sleeper->wait($ms);
|
||||
}, $microseconds);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class CommandReader extends Thread{
|
||||
case self::TYPE_PIPED:
|
||||
if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF
|
||||
$this->initStdin();
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
$this->wait(200000);
|
||||
}); //prevent CPU waste if it's end of pipe
|
||||
return true; //loop back round
|
||||
|
@ -63,7 +63,7 @@ class BanListCommand extends VanillaCommand{
|
||||
}
|
||||
|
||||
$list = $list->getEntries();
|
||||
$message = implode(", ", array_map(function(BanEntry $entry){
|
||||
$message = implode(", ", array_map(function(BanEntry $entry) : string{
|
||||
return $entry->getName();
|
||||
}, $list));
|
||||
|
||||
|
@ -47,9 +47,9 @@ class ListCommand extends VanillaCommand{
|
||||
return true;
|
||||
}
|
||||
|
||||
$playerNames = array_map(function(Player $player){
|
||||
$playerNames = array_map(function(Player $player) : string{
|
||||
return $player->getName();
|
||||
}, array_filter($sender->getServer()->getOnlinePlayers(), function(Player $player) use ($sender){
|
||||
}, array_filter($sender->getServer()->getOnlinePlayers(), function(Player $player) use ($sender) : bool{
|
||||
return $player->isOnline() and (!($sender instanceof Player) or $sender->canSee($player));
|
||||
}));
|
||||
|
||||
|
@ -52,7 +52,7 @@ class TeleportCommand extends VanillaCommand{
|
||||
return true;
|
||||
}
|
||||
|
||||
$args = array_values(array_filter($args, function($arg){
|
||||
$args = array_values(array_filter($args, function(string $arg) : bool{
|
||||
return $arg !== "";
|
||||
}));
|
||||
if(count($args) < 1 or count($args) > 6){
|
||||
|
@ -51,7 +51,7 @@ class AttributeMap implements \ArrayAccess{
|
||||
* @return Attribute[]
|
||||
*/
|
||||
public function needSend() : array{
|
||||
return array_filter($this->attributes, function(Attribute $attribute){
|
||||
return array_filter($this->attributes, function(Attribute $attribute) : bool{
|
||||
return $attribute->isSyncable() and $attribute->isDesynchronized();
|
||||
});
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class BaseLang{
|
||||
$allFiles = scandir($path, SCANDIR_SORT_NONE);
|
||||
|
||||
if($allFiles !== false){
|
||||
$files = array_filter($allFiles, function($filename){
|
||||
$files = array_filter($allFiles, function(string $filename) : bool{
|
||||
return substr($filename, -4) === ".ini";
|
||||
});
|
||||
|
||||
|
@ -239,7 +239,7 @@ class McRegion extends BaseLevelProvider{
|
||||
$isValid = (file_exists($path . "/level.dat") and is_dir($path . "/region/"));
|
||||
|
||||
if($isValid){
|
||||
$files = array_filter(scandir($path . "/region/", SCANDIR_SORT_NONE), function($file){
|
||||
$files = array_filter(scandir($path . "/region/", SCANDIR_SORT_NONE), function(string $file) : bool{
|
||||
return substr($file, strrpos($file, ".") + 1, 2) === "mc"; //region file
|
||||
});
|
||||
|
||||
|
@ -413,7 +413,7 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
/** @var CommandEnum[] $enums */
|
||||
$enums = [];
|
||||
|
||||
$addEnumFn = static function(CommandEnum $enum) use (&$enums, &$enumIndexes, &$enumValueIndexes){
|
||||
$addEnumFn = static function(CommandEnum $enum) use (&$enums, &$enumIndexes, &$enumValueIndexes) : void{
|
||||
if(!isset($enumIndexes[$enum->enumName])){
|
||||
$enums[$enumIndexes[$enum->enumName] = count($enumIndexes)] = $enum;
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ class ClientCacheBlobStatusPacket extends DataPacket/* implements ServerboundPac
|
||||
*/
|
||||
public static function create(array $hitHashes, array $missHashes) : self{
|
||||
//type checks
|
||||
(static function(int ...$hashes){})(...$hitHashes);
|
||||
(static function(int ...$hashes){})(...$missHashes);
|
||||
(static function(int ...$hashes) : void{})(...$hitHashes);
|
||||
(static function(int ...$hashes) : void{})(...$missHashes);
|
||||
|
||||
$result = new self;
|
||||
$result->hitHashes = $hitHashes;
|
||||
|
@ -40,7 +40,7 @@ class ClientCacheMissResponsePacket extends DataPacket/* implements ClientboundP
|
||||
*/
|
||||
public static function create(array $blobs) : self{
|
||||
//type check
|
||||
(static function(ChunkCacheBlob ...$blobs){})(...$blobs);
|
||||
(static function(ChunkCacheBlob ...$blobs) : void{})(...$blobs);
|
||||
|
||||
$result = new self;
|
||||
$result->blobs = $blobs;
|
||||
|
@ -60,7 +60,7 @@ class LevelChunkPacket extends DataPacket/* implements ClientboundPacket*/{
|
||||
* @param int[] $usedBlobHashes
|
||||
*/
|
||||
public static function withCache(int $chunkX, int $chunkZ, int $subChunkCount, array $usedBlobHashes, string $extraPayload) : self{
|
||||
(static function(int ...$hashes){})(...$usedBlobHashes);
|
||||
(static function(int ...$hashes) : void{})(...$usedBlobHashes);
|
||||
$result = new self;
|
||||
$result->chunkX = $chunkX;
|
||||
$result->chunkZ = $chunkZ;
|
||||
|
@ -35,7 +35,7 @@ class CommandEnumConstraint{
|
||||
* @param int[] $constraints
|
||||
*/
|
||||
public function __construct(CommandEnum $enum, int $valueOffset, array $constraints){
|
||||
(static function(int ...$_){})(...$constraints);
|
||||
(static function(int ...$_) : void{})(...$constraints);
|
||||
if(!isset($enum->enumValues[$valueOffset])){
|
||||
throw new \InvalidArgumentException("Invalid enum value offset $valueOffset");
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ class RCON{
|
||||
}
|
||||
|
||||
$this->instance->response = TextFormat::clean($response->getMessage());
|
||||
$this->instance->synchronized(function(RCONInstance $thread){
|
||||
$this->instance->synchronized(function(RCONInstance $thread) : void{
|
||||
$thread->notify();
|
||||
}, $this->instance);
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ class RCONInstance extends Thread{
|
||||
}
|
||||
if($payload !== ""){
|
||||
$this->cmd = ltrim($payload);
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
$this->notifier->wakeupSleeper();
|
||||
$this->wait();
|
||||
});
|
||||
|
@ -157,7 +157,7 @@ class Sign extends Spawnable{
|
||||
|
||||
$removeFormat = $player->getRemoveFormat();
|
||||
|
||||
$ev = new SignChangeEvent($this->getBlock(), $player, array_map(function(string $line) use ($removeFormat){ return TextFormat::clean($line, $removeFormat); }, $lines));
|
||||
$ev = new SignChangeEvent($this->getBlock(), $player, array_map(function(string $line) use ($removeFormat) : string{ return TextFormat::clean($line, $removeFormat); }, $lines));
|
||||
$ev->call();
|
||||
|
||||
if(!$ev->isCancelled()){
|
||||
|
@ -329,7 +329,7 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
*/
|
||||
public function syncFlushBuffer(){
|
||||
$this->syncFlush = true;
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
$this->notify(); //write immediately
|
||||
|
||||
while($this->syncFlush){
|
||||
@ -364,7 +364,7 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
|
||||
while(!$this->shutdown){
|
||||
$this->writeLogStream($logResource);
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
$this->wait(25000);
|
||||
});
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class ServerKiller extends Thread{
|
||||
public function run(){
|
||||
$this->registerClassLoader();
|
||||
$start = time();
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
if(!$this->stopped){
|
||||
$this->wait($this->time * 1000000);
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ class Utils{
|
||||
$args = $trace[$i]["params"];
|
||||
}
|
||||
|
||||
$params = implode(", ", array_map(function($value) use($maxStringLength){
|
||||
$params = implode(", ", array_map(function($value) use($maxStringLength) : string{
|
||||
if(is_object($value)){
|
||||
return "object " . self::getNiceClassName($value);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user