From 219cf2126b7c5e19e024084f8d49e062304fc2ee Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 7 Dec 2020 19:04:52 +0000 Subject: [PATCH] RegionWorldProvider: make loadRegion() return RegionLoader, fix 3 PHPStan null-reference errors --- .../format/io/region/RegionWorldProvider.php | 13 +++++-------- tests/phpstan/configs/l8-baseline.neon | 15 --------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/world/format/io/region/RegionWorldProvider.php b/src/world/format/io/region/RegionWorldProvider.php index e993498e4..ebb0f8088 100644 --- a/src/world/format/io/region/RegionWorldProvider.php +++ b/src/world/format/io/region/RegionWorldProvider.php @@ -130,7 +130,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ return $this->path . "/region/r.$regionX.$regionZ." . static::getRegionFileExtension(); } - protected function loadRegion(int $regionX, int $regionZ) : void{ + protected function loadRegion(int $regionX, int $regionZ) : RegionLoader{ if(!isset($this->regions[$index = morton2d_encode($regionX, $regionZ)])){ $path = $this->pathToRegion($regionX, $regionZ); @@ -153,6 +153,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ $this->regions[$index] = $region; } + return $this->regions[$index]; } protected function unloadRegion(int $regionX, int $regionZ) : void{ @@ -221,9 +222,8 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ if(!file_exists($this->pathToRegion($regionX, $regionZ))){ return null; } - $this->loadRegion($regionX, $regionZ); - $chunkData = $this->getRegion($regionX, $regionZ)->readChunk($chunkX & 0x1f, $chunkZ & 0x1f); + $chunkData = $this->loadRegion($regionX, $regionZ)->readChunk($chunkX & 0x1f, $chunkZ & 0x1f); if($chunkData !== null){ return $this->deserializeChunk($chunkData); } @@ -233,9 +233,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ protected function writeChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{ self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); - $this->loadRegion($regionX, $regionZ); - - $this->getRegion($regionX, $regionZ)->writeChunk($chunkX & 0x1f, $chunkZ & 0x1f, $this->serializeChunk($chunk)); + $this->loadRegion($regionX, $regionZ)->writeChunk($chunkX & 0x1f, $chunkZ & 0x1f, $this->serializeChunk($chunk)); } private function createRegionIterator() : \RegexIterator{ @@ -285,8 +283,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ foreach($this->createRegionIterator() as $region){ $regionX = ((int) $region[1]); $regionZ = ((int) $region[2]); - $this->loadRegion($regionX, $regionZ); - $count += $this->getRegion($regionX, $regionZ)->calculateChunkCount(); + $count += $this->loadRegion($regionX, $regionZ)->calculateChunkCount(); $this->unloadRegion($regionX, $regionZ); } return $count; diff --git a/tests/phpstan/configs/l8-baseline.neon b/tests/phpstan/configs/l8-baseline.neon index f0d357372..ebd29eff5 100644 --- a/tests/phpstan/configs/l8-baseline.neon +++ b/tests/phpstan/configs/l8-baseline.neon @@ -500,21 +500,6 @@ parameters: count: 1 path: ../../../src/world/format/HeightArray.php - - - message: "#^Cannot call method readChunk\\(\\) on pocketmine\\\\world\\\\format\\\\io\\\\region\\\\RegionLoader\\|null\\.$#" - count: 1 - path: ../../../src/world/format/io/region/RegionWorldProvider.php - - - - message: "#^Cannot call method writeChunk\\(\\) on pocketmine\\\\world\\\\format\\\\io\\\\region\\\\RegionLoader\\|null\\.$#" - count: 1 - path: ../../../src/world/format/io/region/RegionWorldProvider.php - - - - message: "#^Cannot call method calculateChunkCount\\(\\) on pocketmine\\\\world\\\\format\\\\io\\\\region\\\\RegionLoader\\|null\\.$#" - count: 1 - path: ../../../src/world/format/io/region/RegionWorldProvider.php - - message: "#^Cannot call method setDirtyFlag\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" count: 4