Promote some constructors

This commit is contained in:
Dylan K. Taylor
2022-05-17 22:34:58 +01:00
parent 8e767da29e
commit d4b7f66e15
30 changed files with 144 additions and 218 deletions

View File

@ -28,13 +28,12 @@ namespace pocketmine\world\format\io;
*/
class ReadOnlyWorldProviderManagerEntry extends WorldProviderManagerEntry{
/** @phpstan-var FromPath */
private \Closure $fromPath;
/** @phpstan-param FromPath $fromPath */
public function __construct(\Closure $isValid, \Closure $fromPath){
public function __construct(
\Closure $isValid,
private \Closure $fromPath
){
parent::__construct($isValid);
$this->fromPath = $fromPath;
}
public function fromPath(string $path) : WorldProvider{ return ($this->fromPath)($path); }

View File

@ -31,13 +31,10 @@ use pocketmine\world\format\io\exception\UnsupportedWorldFormatException;
*/
abstract class WorldProviderManagerEntry{
/** @phpstan-var IsValid */
protected \Closure $isValid;
/** @phpstan-param IsValid $isValid */
protected function __construct(\Closure $isValid){
$this->isValid = $isValid;
}
protected function __construct(
protected \Closure $isValid
){}
/**
* Tells if the path is a valid world.

View File

@ -30,19 +30,17 @@ use pocketmine\world\WorldCreationOptions;
* @phpstan-type Generate \Closure(string $path, string $name, WorldCreationOptions $options) : void
*/
final class WritableWorldProviderManagerEntry extends WorldProviderManagerEntry{
/** @phpstan-var FromPath */
private \Closure $fromPath;
/** @phpstan-var Generate */
private \Closure $generate;
/**
* @phpstan-param FromPath $fromPath
* @phpstan-param Generate $generate
*/
public function __construct(\Closure $isValid, \Closure $fromPath, \Closure $generate){
public function __construct(
\Closure $isValid,
private \Closure $fromPath,
private \Closure $generate
){
parent::__construct($isValid);
$this->fromPath = $fromPath;
$this->generate = $generate;
}
public function fromPath(string $path) : WritableWorldProvider{

View File

@ -26,13 +26,10 @@ namespace pocketmine\world\generator;
use function exp;
final class Gaussian{
public int $smoothSize;
/** @var float[][] */
public array $kernel = [];
public function __construct(int $smoothSize){
$this->smoothSize = $smoothSize;
public function __construct(public int $smoothSize){
$bellSize = 1 / $this->smoothSize;
$bellHeight = 2 * $this->smoothSize;

View File

@ -41,10 +41,6 @@ use function igbinary_unserialize;
class PopulationTask extends AsyncTask{
private const TLS_KEY_ON_COMPLETION = "onCompletion";
private int $worldId;
private int $chunkX;
private int $chunkZ;
private ?string $chunk;
private string $adjacentChunks;
@ -54,10 +50,14 @@ class PopulationTask extends AsyncTask{
* @phpstan-param array<int, Chunk|null> $adjacentChunks
* @phpstan-param OnCompletion $onCompletion
*/
public function __construct(int $worldId, int $chunkX, int $chunkZ, ?Chunk $chunk, array $adjacentChunks, \Closure $onCompletion){
$this->worldId = $worldId;
$this->chunkX = $chunkX;
$this->chunkZ = $chunkZ;
public function __construct(
private int $worldId,
private int $chunkX,
private int $chunkZ,
?Chunk $chunk,
array $adjacentChunks,
\Closure $onCompletion
){
$this->chunk = $chunk !== null ? FastChunkSerializer::serializeTerrain($chunk) : null;
$this->adjacentChunks = igbinary_serialize(array_map(