add some phpstan array types

This commit is contained in:
Dylan K. Taylor 2020-01-30 22:06:21 +00:00
parent 4ff4434a22
commit 260ac47588
39 changed files with 177 additions and 27 deletions

View File

@ -45,6 +45,7 @@ function preg_quote_array(array $strings, string $delim = null) : array{
* @param string $stub
* @param int $signatureAlgo
* @param int|null $compression
* @phpstan-param array<string, mixed> $metadata
*
* @return \Generator|string[]
*/

View File

@ -100,7 +100,10 @@ class CrashDump{
private $fp;
/** @var int */
private $time;
/** @var mixed[] */
/**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
private $data = [];
/** @var string */
private $encodedData = "";
@ -146,6 +149,7 @@ class CrashDump{
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public function getData() : array{
return $this->data;

View File

@ -314,7 +314,10 @@ class Server{
/** @var string */
private $pluginPath;
/** @var string[] */
/**
* @var string[]
* @phpstan-var array<string, string>
*/
private $uniquePlayers = [];
/** @var QueryHandler */
@ -978,6 +981,7 @@ class Server{
*
* @param string|null $generator Class name that extends pocketmine\level\generator\Generator
* @param mixed[] $options
* @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)){
@ -1999,6 +2003,7 @@ class Server{
/**
* @param mixed[][]|null $trace
* @phpstan-param list<array<string, mixed>>|null $trace
*
* @return void
*/

View File

@ -102,6 +102,7 @@ abstract class BaseRail extends Flowable{
/**
* @param int[] $connections
* @param int[][] $lookup
* @phpstan-param array<int, list<int>> $lookup
*/
protected static function searchState(array $connections, array $lookup) : int{
$meta = array_search($connections, $lookup, true);
@ -170,6 +171,7 @@ abstract class BaseRail extends Flowable{
* @param int[] $constraints
*
* @return true[]
* @phpstan-return array<int, true>
*/
private function getPossibleConnectionDirections(array $constraints) : array{
switch(count($constraints)){
@ -197,6 +199,7 @@ abstract class BaseRail extends Flowable{
/**
* @return true[]
* @phpstan-return array<int, true>
*/
protected function getPossibleConnectionDirectionsOneConstraint(int $constraint) : array{
$opposite = Vector3::getOppositeSide($constraint & ~self::FLAG_ASCEND);

View File

@ -70,6 +70,7 @@ class Leaves extends Transparent{
/**
* @param true[] $visited reference parameter
* @phpstan-param array<string, true> $visited
*/
protected function findLog(Block $pos, array &$visited, int $distance, ?int $fromSide = null) : bool{
$index = $pos->x . "." . $pos->y . "." . $pos->z;

View File

@ -128,6 +128,7 @@ class TimingsCommand extends VanillaCommand{
/**
* @param string[] $data
* @phpstan-param array<string, string> $data
*/
public function __construct(CommandSender $sender, string $host, string $agent, array $data){
parent::__construct([

View File

@ -32,10 +32,16 @@ use function is_string;
class DataPropertyManager{
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<int, array{0: int, 1: mixed}>
*/
private $properties = [];
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<int, array{0: int, 1: mixed}>
*/
private $dirtyProperties = [];
public function __construct(){
@ -178,6 +184,7 @@ class DataPropertyManager{
* Returns all properties.
*
* @return mixed[][]
* @phpstan-return array<int, array{0: int, 1: mixed}>
*/
public function getAll() : array{
return $this->properties;
@ -187,6 +194,7 @@ class DataPropertyManager{
* Returns properties that have changed and need to be broadcasted.
*
* @return mixed[][]
* @phpstan-return array<int, array{0: int, 1: mixed}>
*/
public function getDirty() : array{
return $this->dirtyProperties;

View File

@ -319,9 +319,15 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** @var int */
public static $entityCount = 1;
/** @var string[] */
/**
* @var string[]
* @phpstan-var array<int|string, class-string<Entity>>
*/
private static $knownEntities = [];
/** @var string[][] */
/**
* @var string[][]
* @phpstan-var array<class-string<Entity>, list<string>>
*/
private static $saveNames = [];
/**
@ -2056,6 +2062,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @param Player[]|Player $player
* @param mixed[][] $data Properly formatted entity data, defaults to everything
* @phpstan-param array<int, array{0: int, 1: mixed}> $data
*/
public function sendData($player, ?array $data = null) : void{
if(!is_array($player)){

View File

@ -793,6 +793,7 @@ abstract class Living extends Entity implements Damageable{
/**
* @param true[] $transparent
* @phpstan-param array<int, true> $transparent
*
* @return Block[]
*/
@ -835,6 +836,7 @@ abstract class Living extends Entity implements Damageable{
/**
* @param true[] $transparent
* @phpstan-param array<int, true> $transparent
*/
public function getTargetBlock(int $maxDistance, array $transparent = []) : ?Block{
$line = $this->getLineOfSight($maxDistance, 1, $transparent);

View File

@ -63,7 +63,10 @@ class QueryRegenerateEvent extends ServerEvent{
/** @var string */
private $ip;
/** @var string[] */
/**
* @var string[]
* @phpstan-var array<string, string>
*/
private $extraData = [];
/** @var string|null */
@ -192,6 +195,7 @@ class QueryRegenerateEvent extends ServerEvent{
* Returns the extra Query data in key => value form
*
* @return string[]
* @phpstan-return array<string, string>
*/
public function getExtraData() : array{
return $this->extraData;
@ -199,6 +203,7 @@ class QueryRegenerateEvent extends ServerEvent{
/**
* @param string[] $extraData
* @phpstan-param array<string, string> $extraData
*/
public function setExtraData(array $extraData) : void{
$this->extraData = $extraData;

View File

@ -99,6 +99,7 @@ class Banner extends Item{
* Returns the data of a pattern with the given ID.
*
* @return mixed[]
* @phpstan-return array{Color?: int, Pattern?: string}
*/
public function getPatternData(int $patternId) : array{
if(!$this->patternExists($patternId)){

View File

@ -771,6 +771,7 @@ class Item implements ItemIds, \JsonSerializable{
* Returns an array of item stack properties that can be serialized to json.
*
* @return mixed[]
* @phpstan-return array{id: int, damage?: int, count?: int, nbt_b64?: string}
*/
final public function jsonSerialize() : array{
$data = [
@ -795,6 +796,14 @@ class Item implements ItemIds, \JsonSerializable{
/**
* Returns an Item from properties created in an array by {@link Item#jsonSerialize}
* @param mixed[] $data
* @phpstan-param array{
* id: int,
* damage?: int,
* count?: int,
* nbt?: string,
* nbt_hex?: string,
* nbt_b64?: string
* } $data
*/
final public static function jsonDeserialize(array $data) : Item{
$nbt = "";

View File

@ -45,6 +45,7 @@ class BaseLang{
/**
* @return string[]
* @phpstan-return array<string, string>
*/
public static function getLanguageList(string $path = "") : array{
if($path === ""){

View File

@ -54,6 +54,7 @@ interface LevelProvider{
* Generate the needed files in the path given
*
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*
* @return void
*/
@ -66,6 +67,7 @@ interface LevelProvider{
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public function getGeneratorOptions() : array;

View File

@ -31,7 +31,10 @@ use function strtolower;
use function trim;
abstract class LevelProviderManager{
/** @var string[] */
/**
* @var string[]
* @phpstan-var array<string, class-string<LevelProvider>>
*/
protected static $providers = [];
public static function init() : void{

View File

@ -44,13 +44,19 @@ class Flat extends Generator{
private $chunk;
/** @var Populator[] */
private $populators = [];
/** @var int[][] */
/**
* @var int[][]
* @phpstan-var array<int, array{0: int, 1: int}>
*/
private $structure;
/** @var int */
private $floorLevel;
/** @var int */
private $biome;
/** @var mixed[] */
/**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
private $options;
/** @var string */
private $preset;
@ -65,6 +71,7 @@ class Flat extends Generator{
/**
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*
* @throws InvalidGeneratorOptionsException
*/
@ -97,6 +104,8 @@ class Flat extends Generator{
/**
* @return int[][]
* @phpstan-return array<int, array{0: int, 1: int}>
*
* @throws InvalidGeneratorOptionsException
*/
public static function parseLayers(string $layers) : array{

View File

@ -58,6 +58,7 @@ abstract class Generator{
* @throws InvalidGeneratorOptionsException
*
* @param mixed[] $settings
* @phpstan-param array<string, mixed> $settings
*/
abstract public function __construct(array $settings = []);
@ -72,6 +73,7 @@ abstract class Generator{
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
abstract public function getSettings() : array;

View File

@ -30,7 +30,10 @@ use function is_subclass_of;
use function strtolower;
final class GeneratorManager{
/** @var string[] name => classname mapping */
/**
* @var string[] name => classname mapping
* @phpstan-var array<string, class-string<Generator>>
*/
private static $list = [];
/**

View File

@ -47,6 +47,7 @@ class GeneratorRegisterTask extends AsyncTask{
/**
* @param mixed[] $generatorSettings
* @phpstan-param array<string, mixed> $generatorSettings
*/
public function __construct(Level $level, string $generatorClass, array $generatorSettings = []){
$this->generatorClass = $generatorClass;

View File

@ -54,6 +54,7 @@ class Nether extends Generator{
/**
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*
* @throws InvalidGeneratorOptionsException
*/

View File

@ -62,6 +62,7 @@ class Normal extends Generator{
/**
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*
* @throws InvalidGeneratorOptionsException
*/

View File

@ -274,6 +274,7 @@ class NetworkBinaryStream extends BinaryStream{
* @param bool $types Whether to include metadata types along with values in the returned array
*
* @return mixed[]|mixed[][]
* @phpstan-return array<int, mixed>|array<int, array{0: int, 1: mixed}>
*/
public function getEntityMetadata(bool $types = true) : array{
$count = $this->getUnsignedVarInt();
@ -328,6 +329,7 @@ class NetworkBinaryStream extends BinaryStream{
* Writes entity metadata to the packet buffer.
*
* @param mixed[][] $metadata
* @phpstan-param array<int, array{0: int, 1: mixed}> $metadata
*/
public function putEntityMetadata(array $metadata) : void{
$this->putUnsignedVarInt(count($metadata));
@ -545,6 +547,7 @@ class NetworkBinaryStream extends BinaryStream{
* TODO: implement this properly
*
* @return mixed[][], members are in the structure [name => [type, value]]
* @phpstan-return array<string, array{0: int, 1: bool|int|float}>
*/
public function getGameRules() : array{
$count = $this->getUnsignedVarInt();
@ -576,6 +579,7 @@ class NetworkBinaryStream extends BinaryStream{
* TODO: implement this properly
*
* @param mixed[][] $rules
* @phpstan-param array<string, array{0: int, 1: bool|int|float}> $rules
*/
public function putGameRules(array $rules) : void{
$this->putUnsignedVarInt(count($rules));

View File

@ -163,7 +163,10 @@ class AddActorPacket extends DataPacket{
/** @var Attribute[] */
public $attributes = [];
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<int, array{0: int, 1: mixed}>
*/
public $metadata = [];
/** @var EntityLink[] */
public $links = [];

View File

@ -42,7 +42,10 @@ class AddItemActorPacket extends DataPacket{
public $position;
/** @var Vector3|null */
public $motion;
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<int, array{0: int, 1: mixed}>
*/
public $metadata = [];
/** @var bool */
public $isFromFishing = false;

View File

@ -57,7 +57,10 @@ class AddPlayerPacket extends DataPacket{
public $headYaw = null; //TODO
/** @var Item */
public $item;
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<int, array{0: int, 1: mixed}>
*/
public $metadata = [];
//TODO: adventure settings stuff

View File

@ -362,6 +362,7 @@ class AvailableCommandsPacket extends DataPacket{
/**
* @param string[] $postfixes
* @phpstan-param array<int, string> $postfixes
*/
private function argTypeToString(int $argtype, array $postfixes) : string{
if($argtype & self::ARG_FLAG_VALID){

View File

@ -30,7 +30,10 @@ use pocketmine\network\mcpe\NetworkSession;
class GameRulesChangedPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::GAME_RULES_CHANGED_PACKET;
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<string, array{0: int, 1: bool|int|float}>
*/
public $gameRules = [];
protected function decodePayload(){

View File

@ -54,11 +54,17 @@ class LoginPacket extends DataPacket{
/** @var string */
public $locale;
/** @var string[][] (the "chain" index contains one or more JWTs) */
/**
* @var string[][] (the "chain" index contains one or more JWTs)
* @phpstan-var array{chain?: list<string>}
*/
public $chainData = [];
/** @var string */
public $clientDataJwt;
/** @var mixed[] decoded payload of the clientData JWT */
/**
* @var mixed[] decoded payload of the clientData JWT
* @phpstan-var array<string, mixed>
*/
public $clientData = [];
/**

View File

@ -32,7 +32,10 @@ class SetActorDataPacket extends DataPacket{
/** @var int */
public $entityRuntimeId;
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<int, array{0: int, 1: mixed}>
*/
public $metadata;
protected function decodePayload(){

View File

@ -102,7 +102,10 @@ class StartGamePacket extends DataPacket{
public $commandsEnabled;
/** @var bool */
public $isTexturePacksRequired = true;
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<string, array{0: int, 1: bool|int|float}>
*/
public $gameRules = [ //TODO: implement this
"naturalregeneration" => [1, false] //Hack for client side regeneration
];
@ -152,7 +155,10 @@ class StartGamePacket extends DataPacket{
/** @var ListTag|null */
public $blockTable = null;
/** @var int[]|null string (name) => int16 (legacyID) */
/**
* @var int[]|null string (name) => int16 (legacyID)
* @phpstan-var array<string, int>|null
*/
public $itemTable = null;
protected function decodePayload(){
@ -301,6 +307,7 @@ class StartGamePacket extends DataPacket{
/**
* @param int[] $table
* @phpstan-param array<string, int> $table
*/
private static function serializeItemTable(array $table) : string{
$stream = new NetworkBinaryStream();

View File

@ -84,6 +84,7 @@ class Permission{
/**
* @param mixed[][] $data
* @phpstan-param array<string, array<string, mixed>> $data
*
* @return Permission[]
*/
@ -99,6 +100,7 @@ class Permission{
/**
* @param mixed[] $data
* @param Permission[] $output reference parameter
* @phpstan-param array<string, mixed> $data
*
* @throws \Exception
*/
@ -137,7 +139,10 @@ class Permission{
/** @var string */
private $description;
/** @var bool[] */
/**
* @var bool[]
* @phpstan-var array<string, bool>
*/
private $children;
/** @var string */
@ -147,6 +152,7 @@ class Permission{
* Creates a new Permission object to be attached to Permissible objects
*
* @param bool[] $children
* @phpstan-param array<string, bool> $children
*/
public function __construct(string $name, string $description = null, string $defaultValue = null, array $children = []){
$this->name = $name;
@ -163,6 +169,7 @@ class Permission{
/**
* @return bool[]
* @phpstan-return array<string, bool>
*/
public function &getChildren() : array{
return $this->children;

View File

@ -41,7 +41,10 @@ use function version_compare;
use function yaml_parse;
class PluginDescription{
/** @var mixed[] */
/**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
private $map;
/** @var string */
@ -52,7 +55,10 @@ class PluginDescription{
private $api;
/** @var int[] */
private $compatibleMcpeProtocols = [];
/** @var string[][] */
/**
* @var string[][]
* @phpstan-var array<string, list<mixed>>
*/
private $extensions = [];
/** @var string[] */
private $depend = [];
@ -62,7 +68,10 @@ class PluginDescription{
private $loadBefore = [];
/** @var string */
private $version;
/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<string, array<string, mixed>>
*/
private $commands = [];
/** @var string */
private $description = "";
@ -80,6 +89,7 @@ class PluginDescription{
/**
* @param string|mixed[] $yamlString
* @phpstan-param string|array<string, mixed> $yamlString
*/
public function __construct($yamlString){
$this->loadMap(!is_array($yamlString) ? yaml_parse($yamlString) : $yamlString);
@ -87,6 +97,7 @@ class PluginDescription{
/**
* @param mixed[] $plugin
* @phpstan-param array<string, mixed> $plugin
* @throws PluginException
*/
private function loadMap(array $plugin) : void{
@ -189,6 +200,7 @@ class PluginDescription{
/**
* @return mixed[][]
* @phpstan-return array<string, array<string, mixed>>
*/
public function getCommands() : array{
return $this->commands;
@ -196,6 +208,7 @@ class PluginDescription{
/**
* @return string[][]
* @phpstan-return array<string, list<string>>
*/
public function getRequiredExtensions() : array{
return $this->extensions;
@ -290,6 +303,7 @@ class PluginDescription{
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public function getMap() : array{
return $this->map;

View File

@ -46,6 +46,7 @@ class BulkCurlTask extends AsyncTask{
*
* @param mixed[][] $operations
* @param mixed|null $complexData
* @phpstan-param list<array{page: string, timeout?: float, extraHeaders?: list<string>, extraOpts?: array<int, mixed>}> $operations
*/
public function __construct(array $operations, $complexData = null){
$this->storeLocal($complexData);
@ -53,6 +54,7 @@ class BulkCurlTask extends AsyncTask{
}
public function onRun(){
/** @phpstan-var list<array{page: string, timeout?: float, extraHeaders?: list<string>, extraOpts?: array<int, mixed>}> $operations */
$operations = unserialize($this->operations);
$results = [];
foreach($operations as $op){

View File

@ -51,6 +51,7 @@ class SendUsageTask extends AsyncTask{
/**
* @param string[] $playerList
* @phpstan-param array<string, string> $playerList
*/
public function __construct(Server $server, int $type, array $playerList = []){
$endpoint = "http://" . $server->getProperty("anonymous-statistics.host", "stats.pocketmine.net") . "/";

View File

@ -166,6 +166,7 @@ class Banner extends Spawnable implements Nameable{
* Returns the data of a pattern with the given ID.
*
* @return mixed[]
* @phpstan-return array{Color?: int, Pattern?: string}
*/
public function getPatternData(int $patternId) : array{
if(!$this->patternExists($patternId)){

View File

@ -41,7 +41,10 @@ class AutoUpdater{
protected $server;
/** @var string */
protected $endpoint;
/** @var mixed[]|null */
/**
* @var mixed[]|null
* @phpstan-var array<string, mixed>|null
*/
protected $updateInfo = null;
/** @var VersionString|null */
protected $newVersion;
@ -59,6 +62,7 @@ class AutoUpdater{
* Callback used at the end of the update checking task
*
* @param mixed[] $updateInfo
* @phpstan-param array<string, mixed> $updateInfo
*
* @return void
*/
@ -153,6 +157,7 @@ class AutoUpdater{
* Returns the last retrieved update data.
*
* @return mixed[]|null
* @phpstan-return array<string, mixed>|null
*/
public function getUpdateInfo(){
return $this->updateInfo;

View File

@ -68,10 +68,16 @@ class Config{
public const ENUM = 5; // .txt, .list, .enum
public const ENUMERATION = Config::ENUM;
/** @var mixed[] */
/**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
private $config = [];
/** @var mixed[] */
/**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
private $nestedCache = [];
/** @var string */
@ -110,6 +116,7 @@ class Config{
* @param int $type Config type to load, -1 by default (detect)
* @param mixed[] $default Array with the default values that will be written to the file if it did not exist
* @param null $correct reference parameter, Sets correct to true if everything has been loaded correctly
* @phpstan-param array<string, mixed> $default
*/
public function __construct(string $file, int $type = Config::DETECT, array $default = [], &$correct = null){
$this->load($file, $type, $default);
@ -142,6 +149,7 @@ class Config{
/**
* @param mixed[] $default
* @phpstan-param array<string, mixed> $default
*/
public function load(string $file, int $type = Config::DETECT, array $default = []) : bool{
$this->correct = true;
@ -445,6 +453,7 @@ class Config{
/**
* @param mixed[] $v
* @phpstan-param array<string, mixed> $v
*
* @return void
*/
@ -479,6 +488,7 @@ class Config{
/**
* @return mixed[]
* @phpstan-return list<string>|array<string, mixed>
*/
public function getAll(bool $keys = false) : array{
return ($keys ? array_keys($this->config) : $this->config);
@ -486,6 +496,7 @@ class Config{
/**
* @param mixed[] $defaults
* @phpstan-param array<string, mixed> $defaults
*
* @return void
*/
@ -496,6 +507,8 @@ class Config{
/**
* @param mixed[] $default
* @param mixed[] $data reference parameter
* @phpstan-param array<string, mixed> $default
* @phpstan-param array<string, mixed> $data
*/
private function fillDefaults(array $default, &$data) : int{
$changed = 0;

View File

@ -189,6 +189,7 @@ class MainLogger extends \AttachableThreadedLogger{
/**
* @param mixed[][]|null $trace
* @phpstan-param list<array<string, mixed>>|null $trace
*
* @return void
*/

View File

@ -526,6 +526,7 @@ class Utils{
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public static function decodeJWT(string $token) : array{
list($headB64, $payloadB64, $sigB64) = explode(".", $token);
@ -574,6 +575,7 @@ class Utils{
/**
* @param mixed[][] $trace
* @phpstan-param list<array<string, mixed>> $trace
*
* @return string[]
*/
@ -608,6 +610,7 @@ class Utils{
/**
* @return mixed[][]
* @phpstan-return list<array<string, mixed>>
*/
public static function currentTrace(int $skipFrames = 0) : array{
++$skipFrames; //omit this frame from trace, in addition to other skipped frames