make use of phpstan class-string in some areas

This commit is contained in:
Dylan K. Taylor 2020-01-30 22:11:31 +00:00
parent 260ac47588
commit 799183e13e
6 changed files with 27 additions and 9 deletions

View File

@ -980,8 +980,8 @@ class Server{
* Generates a new level if it does not exist
*
* @param string|null $generator Class name that extends pocketmine\level\generator\Generator
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
* @phpstan-param class-string<Generator> $generator
* @phpstan-param array<string, mixed> $options
*/
public function generateLevel(string $name, int $seed = null, $generator = null, array $options = []) : bool{
if(trim($name) === "" or $this->isLevelGenerated($name)){

View File

@ -382,13 +382,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param string $className Class that extends Entity
* @param bool $force Force registration even if the entity does not have a valid network ID
* @param string[] $saveNames An array of save names which this entity might be saved under. Defaults to the short name of the class itself if empty.
* @phpstan-param class-string<Entity> $className
*
* NOTE: The first save name in the $saveNames array will be used when saving the entity to disk. The reflection
* name of the class will be appended to the end and only used if no other save names are specified.
*/
public static function registerEntity(string $className, bool $force = false, array $saveNames = []) : bool{
/** @var Entity $className */
$class = new \ReflectionClass($className);
if(is_a($className, Entity::class, true) and !$class->isAbstract()){
if($className::NETWORK_ID !== -1){

View File

@ -45,6 +45,8 @@ abstract class LevelProviderManager{
}
/**
* @phpstan-param class-string<LevelProvider> $class
*
* @return void
* @throws \InvalidArgumentException
*/
@ -69,10 +71,11 @@ abstract class LevelProviderManager{
* Returns a LevelProvider class for this path, or null
*
* @return string|null
* @phpstan-return class-string<LevelProvider>|null
*/
public static function getProvider(string $path){
foreach(self::$providers as $provider){
/** @var $provider LevelProvider */
/** @phpstan-var class-string<LevelProvider> $provider */
if($provider::isValid($path)){
return $provider;
}
@ -85,6 +88,7 @@ abstract class LevelProviderManager{
* Returns a LevelProvider by name, or null if not found
*
* @return string|null
* @phpstan-return class-string<LevelProvider>|null
*/
public static function getProviderByName(string $name){
return self::$providers[trim(strtolower($name))] ?? null;

View File

@ -51,6 +51,7 @@ final class GeneratorManager{
* @param string $class Fully qualified name of class that extends \pocketmine\level\generator\Generator
* @param string $name Alias for this generator type that can be written in configs
* @param bool $overwrite Whether to force overwriting any existing registered generator with the same name
* @phpstan-param class-string<Generator> $class
*/
public static function addGenerator(string $class, string $name, bool $overwrite = false) : void{
if(!is_subclass_of($class, Generator::class)){
@ -78,7 +79,9 @@ final class GeneratorManager{
*
* @param bool $throwOnMissing @deprecated this is for backwards compatibility only
*
* @return string|Generator Name of class that extends Generator (not an actual Generator object)
* @return string Name of class that extends Generator
* @phpstan-return class-string<Generator>
*
* @throws \InvalidArgumentException if the generator type isn't registered
*/
public static function getGenerator(string $name, bool $throwOnMissing = false){
@ -96,6 +99,7 @@ final class GeneratorManager{
* Returns the registered name of the given Generator class.
*
* @param string $class Fully qualified name of class that extends \pocketmine\level\generator\Generator
* @phpstan-param class-string<Generator> $class
*/
public static function getGeneratorName(string $class) : string{
foreach(self::$list as $name => $c){

View File

@ -82,7 +82,10 @@ class PluginManager{
/** @var Plugin[] */
protected $enabledPlugins = [];
/** @var PluginLoader[] */
/**
* @var PluginLoader[]
* @phpstan-var array<class-string<PluginLoader>, PluginLoader>
*/
protected $fileAssociations = [];
/** @var string|null */
@ -197,6 +200,7 @@ class PluginManager{
/**
* @param string[]|null $newLoaders
* @phpstan-param list<class-string<PluginLoader>> $newLoaders
*
* @return Plugin[]
*/

View File

@ -68,9 +68,15 @@ abstract class Tile extends Position{
/** @var int */
public static $tileCount = 1;
/** @var string[] classes that extend Tile */
/**
* @var string[] classes that extend Tile
* @phpstan-var array<string, class-string<Tile>>
*/
private static $knownTiles = [];
/** @var string[][] */
/**
* @var string[][]
* @phpstan-var array<class-string<Tile>, list<string>>
*/
private static $saveNames = [];
/** @var string */
@ -116,6 +122,7 @@ abstract class Tile extends Position{
/**
* @param string[] $saveNames
* @phpstan-param class-string<Tile> $className
*
* @throws \ReflectionException
*/