Clean up entity and tile saveID handling

we only ever need the first entry, so there's no point storing all of them. In addition, the field is private, which guarantees that nothing else needs the array either.
This also fixes phpstan/phpstan@c50650c5dd.
This commit is contained in:
Dylan K. Taylor 2020-11-12 21:49:12 +00:00
parent 574b7f6343
commit e30b1ee2c7
4 changed files with 18 additions and 22 deletions

View File

@ -77,7 +77,6 @@ use function abs;
use function assert;
use function cos;
use function count;
use function current;
use function deg2rad;
use function floor;
use function fmod;
@ -334,8 +333,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*/
private static $knownEntities = [];
/**
* @var string[][]
* @phpstan-var array<class-string<Entity>, list<string>>
* @var string[]
* @phpstan-var array<class-string<Entity>, string>
*/
private static $saveNames = [];
@ -414,7 +413,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
self::$knownEntities[$name] = $className;
}
self::$saveNames[$className] = $saveNames;
self::$saveNames[$className] = reset($saveNames);
return true;
}
@ -872,8 +871,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if(!isset(self::$saveNames[static::class])){
throw new \InvalidStateException("Entity " . static::class . " is not registered");
}
reset(self::$saveNames[static::class]);
return current(self::$saveNames[static::class]);
return self::$saveNames[static::class];
}
public function saveNBT() : void{

View File

@ -39,7 +39,6 @@ use pocketmine\Player;
use pocketmine\Server;
use pocketmine\timings\Timings;
use pocketmine\timings\TimingsHandler;
use function current;
use function get_class;
use function in_array;
use function is_a;
@ -74,8 +73,8 @@ abstract class Tile extends Position{
*/
private static $knownTiles = [];
/**
* @var string[][]
* @phpstan-var array<class-string<Tile>, list<string>>
* @var string[]
* @phpstan-var array<class-string<Tile>, string>
*/
private static $saveNames = [];
@ -138,7 +137,7 @@ abstract class Tile extends Position{
self::$knownTiles[$name] = $className;
}
self::$saveNames[$className] = $saveNames;
self::$saveNames[$className] = reset($saveNames);
return true;
}
@ -154,8 +153,7 @@ abstract class Tile extends Position{
throw new \InvalidStateException("Tile is not registered");
}
reset(self::$saveNames[static::class]);
return current(self::$saveNames[static::class]);
return self::$saveNames[static::class];
}
public function __construct(Level $level, CompoundTag $nbt){

View File

@ -185,11 +185,6 @@ parameters:
count: 1
path: ../../../src/pocketmine/entity/Effect.php
-
message: "#^Method pocketmine\\\\entity\\\\Entity\\:\\:getSaveId\\(\\) should return string but returns mixed\\.$#"
count: 1
path: ../../../src/pocketmine/entity/Entity.php
-
message: "#^Cannot cast mixed to int\\.$#"
count: 2
@ -560,11 +555,6 @@ parameters:
count: 1
path: ../../../src/pocketmine/scheduler/AsyncTask.php
-
message: "#^Method pocketmine\\\\tile\\\\Tile\\:\\:getSaveId\\(\\) should return string but returns mixed\\.$#"
count: 1
path: ../../../src/pocketmine/tile/Tile.php
-
message: "#^Parameter \\#2 \\$timestamp of function date expects int, mixed given\\.$#"
count: 1

View File

@ -390,6 +390,11 @@ parameters:
count: 1
path: ../../../src/pocketmine/command/defaults/TimingsCommand.php
-
message: "#^Array \\(array\\<class\\-string\\<pocketmine\\\\entity\\\\Entity\\>, string\\>\\) does not accept string\\|false\\.$#"
count: 1
path: ../../../src/pocketmine/entity/Entity.php
-
message: "#^Parameter \\#1 \\$index of method pocketmine\\\\inventory\\\\BaseInventory\\:\\:setItem\\(\\) expects int, int\\|string given\\.$#"
count: 1
@ -985,6 +990,11 @@ parameters:
count: 3
path: ../../../src/pocketmine/tile/Spawnable.php
-
message: "#^Array \\(array\\<class\\-string\\<pocketmine\\\\tile\\\\Tile\\>, string\\>\\) does not accept string\\|false\\.$#"
count: 1
path: ../../../src/pocketmine/tile/Tile.php
-
message: "#^Parameter \\#2 \\$value of method pocketmine\\\\nbt\\\\tag\\\\CompoundTag\\:\\:setInt\\(\\) expects int, float\\|int given\\.$#"
count: 3