Modernize property type declarations

This commit is contained in:
Dylan K. Taylor
2022-06-04 18:16:32 +01:00
parent 23695fb900
commit 083a35f970
114 changed files with 431 additions and 863 deletions

View File

@ -48,35 +48,27 @@ use function sqrt;
class Explosion{
private int $rays = 16;
/** @var World */
public $world;
/** @var Position */
public $source;
/** @var float */
public $size;
public World $world;
/** @var Block[] */
public $affectedBlocks = [];
/** @var float */
public $stepLen = 0.3;
private Entity|Block|null $what;
public array $affectedBlocks = [];
public float $stepLen = 0.3;
private SubChunkExplorer $subChunkExplorer;
public function __construct(Position $center, float $size, Entity|Block|null $what = null){
if(!$center->isValid()){
public function __construct(
public Position $source,
public float $size,
private Entity|Block|null $what = null
){
if(!$this->source->isValid()){
throw new \InvalidArgumentException("Position does not have a valid world");
}
$this->source = $center;
$this->world = $center->getWorld();
$this->world = $this->source->getWorld();
if($size <= 0){
throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $size");
}
$this->size = $size;
$this->what = $what;
$this->subChunkExplorer = new SubChunkExplorer($this->world);
}

View File

@ -32,7 +32,7 @@ use pocketmine\world\format\Chunk;
class SimpleChunkManager implements ChunkManager{
/** @var Chunk[] */
protected $chunks = [];
protected array $chunks = [];
public function __construct(
private int $minY,

View File

@ -170,7 +170,7 @@ class World implements ChunkManager{
private array $entitiesByChunk = [];
/** @var Entity[] */
public $updateEntities = [];
public array $updateEntities = [];
/** @var Block[][] */
private array $blockCache = [];
@ -202,8 +202,7 @@ class World implements ChunkManager{
private array $unloadQueue = [];
private int $time;
/** @var bool */
public $stopTime = false;
public bool $stopTime = false;
private float $sunAnglePercentage = 0.0;
private int $skyLightReduction = 0;
@ -261,11 +260,9 @@ class World implements ChunkManager{
/** @var bool[] */
private array $randomTickBlocks = [];
/** @var WorldTimings */
public $timings;
public WorldTimings $timings;
/** @var float */
public $tickRateTime = 0;
public float $tickRateTime = 0;
private bool $doingTick = false;

View File

@ -44,10 +44,8 @@ abstract class Biome{
/** @var Block[] */
private array $groundCover = [];
/** @var float */
protected $rainfall = 0.5;
/** @var float */
protected $temperature = 0.5;
protected float $rainfall = 0.5;
protected float $temperature = 0.5;
public function clearPopulators() : void{
$this->populators = [];

View File

@ -45,25 +45,21 @@ class Chunk{
private int $terrainDirtyFlags = 0;
/** @var bool|null */
protected $lightPopulated = false;
/** @var bool */
protected $terrainPopulated = false;
protected ?bool $lightPopulated = false;
protected bool $terrainPopulated = false;
/**
* @var \SplFixedArray|SubChunk[]
* @phpstan-var \SplFixedArray<SubChunk>
*/
protected $subChunks;
protected \SplFixedArray $subChunks;
/** @var Tile[] */
protected $tiles = [];
protected array $tiles = [];
/** @var HeightArray */
protected $heightMap;
protected HeightArray $heightMap;
/** @var BiomeArray */
protected $biomeIds;
protected BiomeArray $biomeIds;
/**
* @param SubChunk[] $subChunks

View File

@ -29,17 +29,15 @@ use pocketmine\world\WorldException;
use function file_exists;
abstract class BaseWorldProvider implements WorldProvider{
/** @var string */
protected $path;
/** @var WorldData */
protected $worldData;
protected WorldData $worldData;
public function __construct(string $path){
public function __construct(
protected string $path
){
if(!file_exists($path)){
throw new WorldException("World does not exist");
}
$this->path = $path;
$this->worldData = $this->loadLevelData();
}

View File

@ -36,7 +36,7 @@ final class WorldProviderManager{
* @var WorldProviderManagerEntry[]
* @phpstan-var array<string, WorldProviderManagerEntry>
*/
protected $providers = [];
protected array $providers = [];
private WritableWorldProviderManagerEntry $default;

View File

@ -32,20 +32,15 @@ use pocketmine\world\format\io\WorldData;
use function file_exists;
abstract class BaseNbtWorldData implements WorldData{
/** @var string */
protected $dataPath;
/** @var CompoundTag */
protected $compoundTag;
protected CompoundTag $compoundTag;
/**
* @throws CorruptedWorldException
* @throws UnsupportedWorldFormatException
*/
public function __construct(string $dataPath){
$this->dataPath = $dataPath;
public function __construct(
protected string $dataPath
){
if(!file_exists($this->dataPath)){
throw new CorruptedWorldException("World data not found at $dataPath");
}

View File

@ -96,8 +96,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
protected const CURRENT_LEVEL_CHUNK_VERSION = ChunkVersion::v1_2_0; //yes, I know this is wrong, but it ensures vanilla auto-fixes stuff we currently don't
protected const CURRENT_LEVEL_SUBCHUNK_VERSION = SubChunkVersion::PALETTED_MULTI;
/** @var \LevelDB */
protected $db;
protected \LevelDB $db;
private static function checkForLevelDBExtension() : void{
if(!extension_loaded('leveldb')){

View File

@ -64,24 +64,20 @@ class RegionLoader{
public const FIRST_SECTOR = 2; //location table occupies 0 and 1
/** @var string */
protected $filePath;
/** @var resource */
protected $filePointer;
/** @var int */
protected $nextSector = self::FIRST_SECTOR;
protected int $nextSector = self::FIRST_SECTOR;
/** @var RegionLocationTableEntry[]|null[] */
protected $locationTable = [];
/** @var RegionGarbageMap */
protected $garbageTable;
/** @var int */
public $lastUsed = 0;
protected array $locationTable = [];
protected RegionGarbageMap $garbageTable;
public int $lastUsed;
/**
* @throws CorruptedRegionException
*/
private function __construct(string $filePath){
$this->filePath = $filePath;
private function __construct(
protected string $filePath
){
$this->garbageTable = new RegionGarbageMap([]);
$this->lastUsed = time();

View File

@ -73,7 +73,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
}
/** @var RegionLoader[] */
protected $regions = [];
protected array $regions = [];
protected function loadLevelData() : WorldData{
return new JavaWorldData(Path::join($this->getPath(), "level.dat"));

View File

@ -48,17 +48,12 @@ abstract class Generator{
return $convertedSeed;
}
/** @var int */
protected $seed;
protected Random $random;
protected string $preset;
/** @var Random */
protected $random;
public function __construct(int $seed, string $preset){
$this->seed = $seed;
$this->preset = $preset;
public function __construct(
protected int $seed,
protected string $preset
){
$this->random = new Random($seed);
}

View File

@ -27,29 +27,19 @@ use pocketmine\scheduler\AsyncTask;
use pocketmine\world\World;
class GeneratorRegisterTask extends AsyncTask{
/**
* @var string
* @phpstan-var class-string<Generator>
*/
public $generatorClass;
/** @var string */
public $settings;
/** @var int */
public $seed;
/** @var int */
public $worldId;
/** @var int */
public $worldMinY;
/** @var int */
public $worldMaxY;
public int $seed;
public int $worldId;
public int $worldMinY;
public int $worldMaxY;
/**
* @phpstan-param class-string<Generator> $generatorClass
*/
public function __construct(World $world, string $generatorClass, string $generatorSettings){
$this->generatorClass = $generatorClass;
$this->settings = $generatorSettings;
public function __construct(
World $world,
public string $generatorClass,
public string $generatorSettings
){
$this->seed = $world->getSeed();
$this->worldId = $world->getId();
$this->worldMinY = $world->getMinY();
@ -61,7 +51,7 @@ class GeneratorRegisterTask extends AsyncTask{
* @var Generator $generator
* @see Generator::__construct()
*/
$generator = new $this->generatorClass($this->seed, $this->settings);
$generator = new $this->generatorClass($this->seed, $this->generatorSettings);
ThreadLocalGeneratorContext::register(new ThreadLocalGeneratorContext($generator, $this->worldMinY, $this->worldMaxY), $this->worldId);
}
}

View File

@ -27,9 +27,7 @@ use pocketmine\scheduler\AsyncTask;
use pocketmine\world\World;
class GeneratorUnregisterTask extends AsyncTask{
/** @var int */
public $worldId;
public int $worldId;
public function __construct(World $world){
$this->worldId = $world->getId();

View File

@ -111,18 +111,11 @@ abstract class Noise{
);
}
/** @var float */
protected $persistence;
/** @var float */
protected $expansion;
/** @var int */
protected $octaves;
public function __construct(int $octaves, float $persistence, float $expansion){
$this->octaves = $octaves;
$this->persistence = $persistence;
$this->expansion = $expansion;
}
public function __construct(
protected int $octaves,
protected float $persistence,
protected float $expansion
){}
/**
* @param float $x

View File

@ -46,14 +46,11 @@ class Simplex extends Noise{
protected const F3 = 1.0 / 3.0;
protected const G3 = 1.0 / 6.0;
/** @var float */
protected $offsetX;
/** @var float */
protected $offsetZ;
/** @var float */
protected $offsetY;
protected float $offsetX;
protected float $offsetZ;
protected float $offsetY;
/** @var int[] */
protected $perm = [];
protected array $perm = [];
public function __construct(Random $random, int $octaves, float $persistence, float $expansion){
parent::__construct($octaves, $persistence, $expansion);

View File

@ -29,12 +29,10 @@ use pocketmine\world\BlockTransaction;
use pocketmine\world\ChunkManager;
class BirchTree extends Tree{
/** @var bool */
protected $superBirch = false;
public function __construct(bool $superBirch = false){
public function __construct(
protected bool $superBirch = false
){
parent::__construct(VanillaBlocks::BIRCH_LOG(), VanillaBlocks::BIRCH_LEAVES());
$this->superBirch = $superBirch;
}
public function getBlockTransaction(ChunkManager $world, int $x, int $y, int $z, Random $random) : ?BlockTransaction{

View File

@ -30,14 +30,10 @@ use function sin;
use const M_PI;
class Ore{
private Random $random;
/** @var OreType */
public $type;
public function __construct(Random $random, OreType $type){
$this->type = $type;
$this->random = $random;
}
public function __construct(
private Random $random,
public OreType $type
){}
public function getType() : OreType{
return $this->type;

View File

@ -33,20 +33,11 @@ use pocketmine\world\ChunkManager;
use function abs;
abstract class Tree{
/** @var Block */
protected $trunkBlock;
/** @var Block */
protected $leafBlock;
/** @var int */
protected $treeHeight;
public function __construct(Block $trunkBlock, Block $leafBlock, int $treeHeight = 7){
$this->trunkBlock = $trunkBlock;
$this->leafBlock = $leafBlock;
$this->treeHeight = $treeHeight;
}
public function __construct(
protected Block $trunkBlock,
protected Block $leafBlock,
protected int $treeHeight = 7
){}
public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : bool{
$radiusToCheck = 0;

View File

@ -37,8 +37,7 @@ use function igbinary_unserialize;
class LightPopulationTask extends AsyncTask{
private const TLS_KEY_COMPLETION_CALLBACK = "onCompletion";
/** @var string */
public $chunk;
public string $chunk;
private string $resultHeightMap;
private string $resultSkyLightArrays;

View File

@ -25,27 +25,21 @@ namespace pocketmine\world\light;
final class LightPropagationContext{
/**
* @var \SplQueue
* @phpstan-var \SplQueue<array{int, int, int}>
*/
public $spreadQueue;
/** @phpstan-var \SplQueue<array{int, int, int}> */
public \SplQueue $spreadQueue;
/**
* @var true[]
* @phpstan-var array<int, true>
*/
public $spreadVisited = [];
public array $spreadVisited = [];
/**
* @var \SplQueue
* @phpstan-var \SplQueue<array{int, int, int, int}>
*/
public $removalQueue;
/** @phpstan-var \SplQueue<array{int, int, int, int}> */
public \SplQueue $removalQueue;
/**
* @var true[]
* @phpstan-var array<int, true>
*/
public $removalVisited = [];
public array $removalVisited = [];
public function __construct(){
$this->removalQueue = new \SplQueue();

View File

@ -41,30 +41,20 @@ abstract class LightUpdate{
[ 0, 0, -1]
];
/**
* @var \SplFixedArray|int[]
* @phpstan-var \SplFixedArray<int>
*/
protected $lightFilters;
/**
* @var int[][] blockhash => [x, y, z, new light level]
* @phpstan-var array<int, array{int, int, int, int}>
*/
protected $updateNodes = [];
/** @var SubChunkExplorer */
protected $subChunkExplorer;
protected array $updateNodes = [];
/**
* @param \SplFixedArray|int[] $lightFilters
* @phpstan-param \SplFixedArray<int> $lightFilters
*/
public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters){
$this->lightFilters = $lightFilters;
$this->subChunkExplorer = $subChunkExplorer;
}
public function __construct(
protected SubChunkExplorer $subChunkExplorer,
protected \SplFixedArray $lightFilters
){}
abstract protected function getCurrentLightArray() : LightArray;

View File

@ -46,19 +46,13 @@ use function str_repeat;
class FloatingTextParticle implements Particle{
//TODO: HACK!
/** @var string */
protected $text;
/** @var string */
protected $title;
/** @var int|null */
protected $entityId = null;
/** @var bool */
protected $invisible = false;
protected ?int $entityId = null;
protected bool $invisible = false;
public function __construct(string $text, string $title = ""){
$this->text = $text;
$this->title = $title;
}
public function __construct(
protected string $text,
protected string $title = ""
){}
public function getText() : string{
return $this->text;

View File

@ -28,15 +28,11 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class MobSpawnParticle implements Particle{
/** @var int */
protected $width;
/** @var int */
protected $height;
public function __construct(int $width = 0, int $height = 0){
public function __construct(
protected int $width = 0,
protected int $height = 0
){
//TODO: bounds checks
$this->width = $width;
$this->height = $height;
}
public function encode(Vector3 $pos) : array{

View File

@ -28,24 +28,16 @@ use pocketmine\world\format\Chunk;
use pocketmine\world\format\SubChunk;
class SubChunkExplorer{
/** @var ChunkManager */
protected $world;
public ?Chunk $currentChunk;
public ?SubChunk $currentSubChunk;
/** @var Chunk|null */
public $currentChunk;
/** @var SubChunk|null */
public $currentSubChunk;
protected int $currentX;
protected int $currentY;
protected int $currentZ;
/** @var int */
protected $currentX;
/** @var int */
protected $currentY;
/** @var int */
protected $currentZ;
public function __construct(ChunkManager $world){
$this->world = $world;
}
public function __construct(
protected ChunkManager $world
){}
/**
* @phpstan-return SubChunkExplorerStatus::*