From dbb92096e418ec4994a4d2c2e8293831fef815a4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 15 Jul 2017 12:12:06 +0100 Subject: [PATCH] More typehints, documentation fixes and static analysis cleanup --- src/pocketmine/Achievement.php | 63 +++++++++++-------- src/pocketmine/CrashDump.php | 2 +- src/pocketmine/OfflinePlayer.php | 5 +- src/pocketmine/Player.php | 6 +- src/pocketmine/Server.php | 4 +- src/pocketmine/Thread.php | 2 +- src/pocketmine/command/CommandReader.php | 2 +- .../command/ConsoleCommandSender.php | 4 +- .../command/FormattedCommandAlias.php | 2 +- .../command/defaults/TimingsCommand.php | 2 +- src/pocketmine/entity/Attribute.php | 59 +++++++++-------- src/pocketmine/entity/AttributeMap.php | 2 +- src/pocketmine/entity/Entity.php | 2 +- src/pocketmine/entity/Human.php | 2 +- .../event/inventory/CraftItemEvent.php | 2 +- .../inventory/SimpleTransactionGroup.php | 1 + src/pocketmine/lang/BaseLang.php | 25 ++++++-- src/pocketmine/level/generator/Flat.php | 6 +- .../level/generator/biome/Biome.php | 6 ++ .../level/generator/biome/BiomeSelector.php | 4 +- .../level/generator/hell/Nether.php | 5 ++ .../level/generator/normal/Normal.php | 2 + .../generator/normal/biome/ForestBiome.php | 2 +- .../generator/normal/biome/SandyBiome.php | 2 +- .../generator/normal/biome/SnowyBiome.php | 2 +- .../level/generator/object/BigTree.php | 2 +- .../level/generator/object/BirchTree.php | 6 +- .../level/generator/object/OakTree.php | 2 +- src/pocketmine/level/generator/object/Ore.php | 13 ++-- .../level/generator/object/OreType.php | 21 +++++-- .../level/generator/object/Pond.php | 1 + .../level/generator/object/SpruceTree.php | 2 +- .../level/generator/object/TallGrass.php | 3 +- .../level/generator/object/Tree.php | 8 +-- .../level/generator/populator/GroundCover.php | 2 +- .../level/generator/populator/Mineshaft.php | 2 +- .../level/generator/populator/Ore.php | 7 ++- .../level/generator/populator/Pond.php | 8 +-- .../level/generator/populator/Populator.php | 11 +++- .../level/generator/populator/TallGrass.php | 2 +- .../level/generator/populator/Tree.php | 2 +- .../level/particle/FloatingTextParticle.php | 2 +- .../network/AdvancedSourceInterface.php | 4 +- src/pocketmine/network/Network.php | 21 ++++--- src/pocketmine/network/SourceInterface.php | 7 +-- .../network/mcpe/RakLibInterface.php | 10 +-- src/pocketmine/network/rcon/RCON.php | 7 +-- src/pocketmine/network/rcon/RCONInstance.php | 13 ++-- src/pocketmine/permission/Permissible.php | 2 +- src/pocketmine/permission/PermissibleBase.php | 6 +- src/pocketmine/permission/Permission.php | 18 +++--- .../permission/PermissionAttachment.php | 10 +-- .../permission/PermissionAttachmentInfo.php | 24 +++---- src/pocketmine/plugin/PluginBase.php | 2 +- src/pocketmine/plugin/PluginDescription.php | 2 +- src/pocketmine/plugin/PluginManager.php | 26 ++++---- src/pocketmine/plugin/RegisteredListener.php | 2 +- src/pocketmine/plugin/ScriptPluginLoader.php | 2 +- src/pocketmine/updater/AutoUpdater.php | 2 +- src/pocketmine/utils/Config.php | 24 +++---- src/pocketmine/utils/MainLogger.php | 2 +- src/pocketmine/utils/Random.php | 7 ++- src/pocketmine/utils/ServerKiller.php | 2 +- src/pocketmine/utils/TextFormat.php | 8 +-- src/pocketmine/utils/Utils.php | 17 +++-- src/pocketmine/utils/VersionString.php | 2 +- 66 files changed, 309 insertions(+), 219 deletions(-) diff --git a/src/pocketmine/Achievement.php b/src/pocketmine/Achievement.php index c78a4a6f7..54ce474f8 100644 --- a/src/pocketmine/Achievement.php +++ b/src/pocketmine/Achievement.php @@ -41,73 +41,79 @@ abstract class Achievement{ "mineWood" => [ "name" => "Getting Wood", "requires" => [ //"openInventory", - ], + ] ], "buildWorkBench" => [ "name" => "Benchmarking", "requires" => [ - "mineWood", - ], + "mineWood" + ] ], "buildPickaxe" => [ "name" => "Time to Mine!", "requires" => [ - "buildWorkBench", - ], + "buildWorkBench" + ] ], "buildFurnace" => [ "name" => "Hot Topic", "requires" => [ - "buildPickaxe", - ], + "buildPickaxe" + ] ], "acquireIron" => [ "name" => "Acquire hardware", "requires" => [ - "buildFurnace", - ], + "buildFurnace" + ] ], "buildHoe" => [ "name" => "Time to Farm!", "requires" => [ - "buildWorkBench", - ], + "buildWorkBench" + ] ], "makeBread" => [ "name" => "Bake Bread", "requires" => [ - "buildHoe", - ], + "buildHoe" + ] ], "bakeCake" => [ "name" => "The Lie", "requires" => [ - "buildHoe", - ], + "buildHoe" + ] ], "buildBetterPickaxe" => [ "name" => "Getting an Upgrade", "requires" => [ - "buildPickaxe", - ], + "buildPickaxe" + ] ], "buildSword" => [ "name" => "Time to Strike!", "requires" => [ - "buildWorkBench", - ], + "buildWorkBench" + ] ], "diamonds" => [ "name" => "DIAMONDS!", "requires" => [ - "acquireIron", - ], - ], + "acquireIron" + ] + ] ]; - public static function broadcast(Player $player, $achievementId){ + /** + * @param Player $player + * @param string $achievementId + * + * @return bool + */ + public static function broadcast(Player $player, string $achievementId) : bool{ if(isset(Achievement::$list[$achievementId])){ $translation = new TranslationContainer("chat.type.achievement", [$player->getDisplayName(), TextFormat::GREEN . Achievement::$list[$achievementId]["name"] . TextFormat::RESET]); if(Server::getInstance()->getConfigBoolean("announce-player-achievements", true) === true){ @@ -122,11 +128,18 @@ abstract class Achievement{ return false; } - public static function add($achievementId, $achievementName, array $requires = []){ + /** + * @param string $achievementId + * @param string $achievementName + * @param array $requires + * + * @return bool + */ + public static function add(string $achievementId, string $achievementName, array $requires = []) : bool{ if(!isset(Achievement::$list[$achievementId])){ Achievement::$list[$achievementId] = [ "name" => $achievementName, - "requires" => $requires, + "requires" => $requires ]; return true; diff --git a/src/pocketmine/CrashDump.php b/src/pocketmine/CrashDump.php index 1934030df..2aff493d3 100644 --- a/src/pocketmine/CrashDump.php +++ b/src/pocketmine/CrashDump.php @@ -164,7 +164,7 @@ class CrashDump{ E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", - E_USER_DEPRECATED => "E_USER_DEPRECATED", + E_USER_DEPRECATED => "E_USER_DEPRECATED" ]; $error["fullFile"] = $error["file"]; $error["file"] = cleanPath($error["file"]); diff --git a/src/pocketmine/OfflinePlayer.php b/src/pocketmine/OfflinePlayer.php index 462c489e8..4f7b4105e 100644 --- a/src/pocketmine/OfflinePlayer.php +++ b/src/pocketmine/OfflinePlayer.php @@ -30,15 +30,18 @@ use pocketmine\plugin\Plugin; class OfflinePlayer implements IPlayer, Metadatable{ + /** @var string */ private $name; + /** @var Server */ private $server; + /** @var CompoundTag|null */ private $namedtag; /** * @param Server $server * @param string $name */ - public function __construct(Server $server, $name){ + public function __construct(Server $server, string $name){ $this->server = $server; $this->name = $name; if(file_exists($this->server->getDataPath() . "players/" . strtolower($this->getName()) . ".dat")){ diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4c0bba5a0..30279d847 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -563,11 +563,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** * @param Plugin $plugin * @param string $name - * @param bool $value + * @param bool $value * - * @return permission\PermissionAttachment + * @return PermissionAttachment */ - public function addAttachment(Plugin $plugin, $name = null, $value = null){ + public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{ return $this->perm->addAttachment($plugin, $name, $value); } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index a40c0828f..e79e3d650 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -775,7 +775,7 @@ class Server{ new ShortTag("Air", 300), new ByteTag("OnGround", 1), new ByteTag("Invulnerable", 0), - new StringTag("NameTag", $name), + new StringTag("NameTag", $name) ]); $nbt->Pos->setTagType(NBT::TAG_Double); $nbt->Inventory->setTagType(NBT::TAG_Compound); @@ -1633,7 +1633,7 @@ class Server{ $generator = Generator::getGenerator(array_shift($options)); if(count($options) > 0){ $options = [ - "preset" => implode(":", $options), + "preset" => implode(":", $options) ]; }else{ $options = []; diff --git a/src/pocketmine/Thread.php b/src/pocketmine/Thread.php index f6a6d93a1..0213dcc58 100644 --- a/src/pocketmine/Thread.php +++ b/src/pocketmine/Thread.php @@ -83,7 +83,7 @@ abstract class Thread extends \Thread{ ThreadManager::getInstance()->remove($this); } - public function getThreadName(){ + public function getThreadName() : string{ return (new \ReflectionClass($this))->getShortName(); } } diff --git a/src/pocketmine/command/CommandReader.php b/src/pocketmine/command/CommandReader.php index f8ab76903..d0c201569 100644 --- a/src/pocketmine/command/CommandReader.php +++ b/src/pocketmine/command/CommandReader.php @@ -180,7 +180,7 @@ class CommandReader extends Thread{ } - public function getThreadName(){ + public function getThreadName() : string{ return "Console"; } } diff --git a/src/pocketmine/command/ConsoleCommandSender.php b/src/pocketmine/command/ConsoleCommandSender.php index b7c085b90..ac78a69f3 100644 --- a/src/pocketmine/command/ConsoleCommandSender.php +++ b/src/pocketmine/command/ConsoleCommandSender.php @@ -64,11 +64,11 @@ class ConsoleCommandSender implements CommandSender{ /** * @param Plugin $plugin * @param string $name - * @param bool $value + * @param bool $value * * @return PermissionAttachment */ - public function addAttachment(Plugin $plugin, $name = null, $value = null){ + public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{ return $this->perm->addAttachment($plugin, $name, $value); } diff --git a/src/pocketmine/command/FormattedCommandAlias.php b/src/pocketmine/command/FormattedCommandAlias.php index 7d728af82..30fbfc320 100644 --- a/src/pocketmine/command/FormattedCommandAlias.php +++ b/src/pocketmine/command/FormattedCommandAlias.php @@ -101,7 +101,7 @@ class FormattedCommandAlias extends Command{ throw new \InvalidArgumentException("Invalid replacement token"); } - $position = (int) (substr($formatString, $argStart, $index)); + $position = (int) substr($formatString, $argStart, $index); if($position === 0){ throw new \InvalidArgumentException("Invalid replacement token"); diff --git a/src/pocketmine/command/defaults/TimingsCommand.php b/src/pocketmine/command/defaults/TimingsCommand.php index ec4315d2b..584740a27 100644 --- a/src/pocketmine/command/defaults/TimingsCommand.php +++ b/src/pocketmine/command/defaults/TimingsCommand.php @@ -111,7 +111,7 @@ class TimingsCommand extends VanillaCommand{ ["page" => "http://paste.ubuntu.com", "extraOpts" => [ CURLOPT_HTTPHEADER => ["User-Agent: " . $sender->getServer()->getName() . " " . $sender->getServer()->getPocketMineVersion()], CURLOPT_POST => 1, - CURLOPT_POSTFIELDS => $data, + CURLOPT_POSTFIELDS => $data ]] ], $sender) extends BulkCurlTask{ public function onCompletion(Server $server){ diff --git a/src/pocketmine/entity/Attribute.php b/src/pocketmine/entity/Attribute.php index bc8988376..9fe208506 100644 --- a/src/pocketmine/entity/Attribute.php +++ b/src/pocketmine/entity/Attribute.php @@ -79,29 +79,29 @@ class Attribute{ * * @throws \InvalidArgumentException */ - public static function addAttribute($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend = true){ + public static function addAttribute(int $id, string $name, float $minValue, float $maxValue, float $defaultValue, bool $shouldSend = true) : Attribute{ if($minValue > $maxValue or $defaultValue > $maxValue or $defaultValue < $minValue){ throw new \InvalidArgumentException("Invalid ranges: min value: $minValue, max value: $maxValue, $defaultValue: $defaultValue"); } - return self::$attributes[(int) $id] = new Attribute($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend); + return self::$attributes[$id] = new Attribute($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend); } /** - * @param $id + * @param int $id * - * @return null|Attribute + * @return Attribute|null */ - public static function getAttribute($id){ + public static function getAttribute(int $id){ return isset(self::$attributes[$id]) ? clone self::$attributes[$id] : null; } /** - * @param $name + * @param string $name * - * @return null|Attribute + * @return Attribute|null */ - public static function getAttributeByName($name){ + public static function getAttributeByName(string $name){ foreach(self::$attributes as $a){ if($a->getName() === $name){ return clone $a; @@ -111,22 +111,22 @@ class Attribute{ return null; } - private function __construct($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend = true){ - $this->id = (int) $id; - $this->name = (string) $name; - $this->minValue = (float) $minValue; - $this->maxValue = (float) $maxValue; - $this->defaultValue = (float) $defaultValue; - $this->shouldSend = (bool) $shouldSend; + private function __construct(int $id, string $name, float $minValue, float $maxValue, float $defaultValue, bool $shouldSend = true){ + $this->id = $id; + $this->name = $name; + $this->minValue = $minValue; + $this->maxValue = $maxValue; + $this->defaultValue = $defaultValue; + $this->shouldSend = $shouldSend; $this->currentValue = $this->defaultValue; } - public function getMinValue(){ + public function getMinValue() : float{ return $this->minValue; } - public function setMinValue($minValue){ + public function setMinValue(float $minValue){ if($minValue > $this->getMaxValue()){ throw new \InvalidArgumentException("Value $minValue is bigger than the maxValue!"); } @@ -138,11 +138,11 @@ class Attribute{ return $this; } - public function getMaxValue(){ + public function getMaxValue() : float{ return $this->maxValue; } - public function setMaxValue($maxValue){ + public function setMaxValue(float $maxValue){ if($maxValue < $this->getMinValue()){ throw new \InvalidArgumentException("Value $maxValue is bigger than the minValue!"); } @@ -154,11 +154,11 @@ class Attribute{ return $this; } - public function getDefaultValue(){ + public function getDefaultValue() : float{ return $this->defaultValue; } - public function setDefaultValue($defaultValue){ + public function setDefaultValue(float $defaultValue){ if($defaultValue > $this->getMaxValue() or $defaultValue < $this->getMinValue()){ throw new \InvalidArgumentException("Value $defaultValue exceeds the range!"); } @@ -174,11 +174,18 @@ class Attribute{ $this->setValue($this->getDefaultValue()); } - public function getValue(){ + public function getValue() : float{ return $this->currentValue; } - public function setValue($value, $fit = false, bool $forceSend = false){ + /** + * @param float $value + * @param bool $fit + * @param bool $forceSend + * + * @return $this + */ + public function setValue(float $value, bool $fit = false, bool $forceSend = false){ if($value > $this->getMaxValue() or $value < $this->getMinValue()){ if(!$fit){ throw new \InvalidArgumentException("Value $value exceeds the range!"); @@ -196,15 +203,15 @@ class Attribute{ return $this; } - public function getName(){ + public function getName() : string{ return $this->name; } - public function getId(){ + public function getId() : int{ return $this->id; } - public function isSyncable(){ + public function isSyncable() : bool{ return $this->shouldSend; } diff --git a/src/pocketmine/entity/AttributeMap.php b/src/pocketmine/entity/AttributeMap.php index 7544df2ef..1c1c85276 100644 --- a/src/pocketmine/entity/AttributeMap.php +++ b/src/pocketmine/entity/AttributeMap.php @@ -43,7 +43,7 @@ class AttributeMap implements \ArrayAccess{ /** * @return Attribute[] */ - public function getAll(): array{ + public function getAll() : array{ return $this->attributes; } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 65d283087..a4f44193b 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -651,7 +651,7 @@ abstract class Entity extends Location implements Metadatable{ if(isset($this->effects[$effect->getId()])){ $oldEffect = $this->effects[$effect->getId()]; if( - abs($effect->getAmplifier()) < ($oldEffect->getAmplifier()) + abs($effect->getAmplifier()) < $oldEffect->getAmplifier() or (abs($effect->getAmplifier()) === abs($oldEffect->getAmplifier()) and $effect->getDuration() < $oldEffect->getDuration()) ){ diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 916121c26..231dff00e 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -464,7 +464,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ new ShortTag("Damage", 0), new ByteTag("Slot", $slot), new ByteTag("TrueSlot", -1), - new ShortTag("id", 0), + new ShortTag("id", 0) ]); } diff --git a/src/pocketmine/event/inventory/CraftItemEvent.php b/src/pocketmine/event/inventory/CraftItemEvent.php index 0fddc1a15..e0c9c5bc7 100644 --- a/src/pocketmine/event/inventory/CraftItemEvent.php +++ b/src/pocketmine/event/inventory/CraftItemEvent.php @@ -33,7 +33,7 @@ class CraftItemEvent extends Event implements Cancellable{ public static $handlerList = null; /** @var Item[] */ - private $input = []; + private $input; /** @var Recipe */ private $recipe; /** @var Player */ diff --git a/src/pocketmine/inventory/SimpleTransactionGroup.php b/src/pocketmine/inventory/SimpleTransactionGroup.php index 5b9e7a032..fd7a4d221 100644 --- a/src/pocketmine/inventory/SimpleTransactionGroup.php +++ b/src/pocketmine/inventory/SimpleTransactionGroup.php @@ -32,6 +32,7 @@ use pocketmine\Server; * This TransactionGroup only allows doing Transaction between one / two inventories */ class SimpleTransactionGroup implements TransactionGroup{ + /** @var float */ private $creationTime; protected $hasExecuted = false; /** @var Player */ diff --git a/src/pocketmine/lang/BaseLang.php b/src/pocketmine/lang/BaseLang.php index dad757689..72d04db8c 100644 --- a/src/pocketmine/lang/BaseLang.php +++ b/src/pocketmine/lang/BaseLang.php @@ -61,12 +61,15 @@ class BaseLang{ return []; } + /** @var string */ protected $langName; + /** @var string[] */ protected $lang = []; + /** @var string[] */ protected $fallbackLang = []; - public function __construct($lang, $path = null, $fallback = self::FALLBACK_LANGUAGE){ + public function __construct(string $lang, string $path = null, string $fallback = self::FALLBACK_LANGUAGE){ $this->langName = strtolower($lang); @@ -82,15 +85,15 @@ class BaseLang{ } } - public function getName(){ + public function getName() : string{ return $this->get("language.name"); } - public function getLang(){ + public function getLang() : string{ return $this->langName; } - protected static function loadLang($path, array &$d){ + protected static function loadLang(string $path, array &$d){ if(file_exists($path)){ $d = parse_ini_file($path, false, INI_SCANNER_RAW); return true; @@ -132,7 +135,12 @@ class BaseLang{ return $baseText; } - public function internalGet($id){ + /** + * @param string $id + * + * @return string|null + */ + public function internalGet(string $id){ if(isset($this->lang[$id])){ return $this->lang[$id]; }elseif(isset($this->fallbackLang[$id])){ @@ -142,7 +150,12 @@ class BaseLang{ return null; } - public function get($id){ + /** + * @param string $id + * + * @return string + */ + public function get(string $id) : string{ if(isset($this->lang[$id])){ return $this->lang[$id]; }elseif(isset($this->fallbackLang[$id])){ diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index 938c1fa91..2f91422df 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -74,8 +74,8 @@ class Flat extends Generator{ new object\OreType(new GoldOre(), 2, 8, 0, 32), new object\OreType(new DiamondOre(), 1, 7, 0, 16), new object\OreType(new Dirt(), 20, 32, 0, 128), - new object\OreType(new Gravel(), 10, 16, 0, 128), - ]); + new object\OreType(new Gravel(), 10, 16, 0, 128) + ]); $this->populators[] = $ores; } @@ -90,7 +90,7 @@ class Flat extends Generator{ $y = 0; foreach($matches[3] as $i => $b){ $b = Item::fromString($b . $matches[4][$i]); - $cnt = $matches[2][$i] === "" ? 1 : (int) ($matches[2][$i]); + $cnt = $matches[2][$i] === "" ? 1 : (int) $matches[2][$i]; for($cY = $y, $y += $cnt; $cY < $y; ++$cY){ $result[$cY] = [$b->getId(), $b->getDamage()]; } diff --git a/src/pocketmine/level/generator/biome/Biome.php b/src/pocketmine/level/generator/biome/Biome.php index d43485387..901aada0a 100644 --- a/src/pocketmine/level/generator/biome/Biome.php +++ b/src/pocketmine/level/generator/biome/Biome.php @@ -65,8 +65,11 @@ abstract class Biome{ /** @var Biome[] */ private static $biomes = []; + /** @var int */ private $id; + /** @var bool */ private $registered = false; + /** @var Populator[] */ private $populators = []; @@ -75,9 +78,12 @@ abstract class Biome{ /** @var int */ private $maxElevation; + /** @var Block[] */ private $groundCover = []; + /** @var float */ protected $rainfall = 0.5; + /** @var float */ protected $temperature = 0.5; protected static function register(int $id, Biome $biome){ diff --git a/src/pocketmine/level/generator/biome/BiomeSelector.php b/src/pocketmine/level/generator/biome/BiomeSelector.php index c3af5ed61..387160cb8 100644 --- a/src/pocketmine/level/generator/biome/BiomeSelector.php +++ b/src/pocketmine/level/generator/biome/BiomeSelector.php @@ -39,8 +39,10 @@ class BiomeSelector{ /** @var Biome[] */ private $biomes = []; - private $map = []; + /** @var \SplFixedArray */ + private $map = null; + /** @var callable */ private $lookup; public function __construct(Random $random, callable $lookup, Biome $fallback){ diff --git a/src/pocketmine/level/generator/hell/Nether.php b/src/pocketmine/level/generator/hell/Nether.php index e2c499026..4323302f5 100644 --- a/src/pocketmine/level/generator/hell/Nether.php +++ b/src/pocketmine/level/generator/hell/Nether.php @@ -41,10 +41,15 @@ class Nether extends Generator{ private $level; /** @var Random */ private $random; + /** @var int */ private $waterHeight = 32; + /** @var int */ private $emptyHeight = 64; + /** @var int */ private $emptyAmplitude = 1; + /** @var float */ private $density = 0.5; + /** @var int */ private $bedrockDepth = 5; /** @var Populator[] */ diff --git a/src/pocketmine/level/generator/normal/Normal.php b/src/pocketmine/level/generator/normal/Normal.php index 9f1ef24da..6e940a207 100644 --- a/src/pocketmine/level/generator/normal/Normal.php +++ b/src/pocketmine/level/generator/normal/Normal.php @@ -53,7 +53,9 @@ class Normal extends Generator{ private $level; /** @var Random */ private $random; + /** @var int */ private $waterHeight = 62; + /** @var int */ private $bedrockDepth = 5; /** @var Populator[] */ diff --git a/src/pocketmine/level/generator/normal/biome/ForestBiome.php b/src/pocketmine/level/generator/normal/biome/ForestBiome.php index 8f1faeaac..b476e3962 100644 --- a/src/pocketmine/level/generator/normal/biome/ForestBiome.php +++ b/src/pocketmine/level/generator/normal/biome/ForestBiome.php @@ -34,7 +34,7 @@ class ForestBiome extends GrassyBiome{ public $type; - public function __construct($type = self::TYPE_NORMAL){ + public function __construct(int $type = self::TYPE_NORMAL){ parent::__construct(); $this->type = $type; diff --git a/src/pocketmine/level/generator/normal/biome/SandyBiome.php b/src/pocketmine/level/generator/normal/biome/SandyBiome.php index 336bb2fde..4d905da7e 100644 --- a/src/pocketmine/level/generator/normal/biome/SandyBiome.php +++ b/src/pocketmine/level/generator/normal/biome/SandyBiome.php @@ -33,7 +33,7 @@ abstract class SandyBiome extends NormalBiome{ Block::get(Block::SAND, 0), Block::get(Block::SANDSTONE, 0), Block::get(Block::SANDSTONE, 0), - Block::get(Block::SANDSTONE, 0), + Block::get(Block::SANDSTONE, 0) ]); } } \ No newline at end of file diff --git a/src/pocketmine/level/generator/normal/biome/SnowyBiome.php b/src/pocketmine/level/generator/normal/biome/SnowyBiome.php index 48b446812..78118ce06 100644 --- a/src/pocketmine/level/generator/normal/biome/SnowyBiome.php +++ b/src/pocketmine/level/generator/normal/biome/SnowyBiome.php @@ -33,7 +33,7 @@ abstract class SnowyBiome extends NormalBiome{ Block::get(Block::GRASS, 0), Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0), - Block::get(Block::DIRT, 0), + Block::get(Block::DIRT, 0) ]); } } \ No newline at end of file diff --git a/src/pocketmine/level/generator/object/BigTree.php b/src/pocketmine/level/generator/object/BigTree.php index 0ea41571f..341c68f07 100644 --- a/src/pocketmine/level/generator/object/BigTree.php +++ b/src/pocketmine/level/generator/object/BigTree.php @@ -45,7 +45,7 @@ class BigTree extends Tree{ return false; } - public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){ + public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){ /*$this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier); $leaves = $this->getLeafGroupPoints($level, $pos); diff --git a/src/pocketmine/level/generator/object/BirchTree.php b/src/pocketmine/level/generator/object/BirchTree.php index a5488c1d5..9cb4c3c06 100644 --- a/src/pocketmine/level/generator/object/BirchTree.php +++ b/src/pocketmine/level/generator/object/BirchTree.php @@ -32,14 +32,14 @@ class BirchTree extends Tree{ protected $superBirch = false; - public function __construct($superBirch = false){ + public function __construct(bool $superBirch = false){ $this->trunkBlock = Block::LOG; $this->leafBlock = Block::LEAVES; $this->type = Wood::BIRCH; - $this->superBirch = (bool) $superBirch; + $this->superBirch = $superBirch; } - public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){ + public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){ $this->treeHeight = $random->nextBoundedInt(3) + 5; if($this->superBirch){ $this->treeHeight += 5; diff --git a/src/pocketmine/level/generator/object/OakTree.php b/src/pocketmine/level/generator/object/OakTree.php index d3ff93e91..5ed91b8a6 100644 --- a/src/pocketmine/level/generator/object/OakTree.php +++ b/src/pocketmine/level/generator/object/OakTree.php @@ -36,7 +36,7 @@ class OakTree extends Tree{ $this->type = Wood::OAK; } - public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){ + public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){ $this->treeHeight = $random->nextBoundedInt(3) + 4; parent::placeObject($level, $x, $y, $z, $random); } diff --git a/src/pocketmine/level/generator/object/Ore.php b/src/pocketmine/level/generator/object/Ore.php index 5633c6dfc..e63373a83 100644 --- a/src/pocketmine/level/generator/object/Ore.php +++ b/src/pocketmine/level/generator/object/Ore.php @@ -23,12 +23,15 @@ declare(strict_types=1); namespace pocketmine\level\generator\object; +use pocketmine\block\Block; use pocketmine\level\ChunkManager; use pocketmine\math\VectorMath; use pocketmine\utils\Random; class Ore{ + /** @var Random */ private $random; + /** @var OreType */ public $type; public function __construct(Random $random, OreType $type){ @@ -36,16 +39,16 @@ class Ore{ $this->random = $random; } - public function getType(){ + public function getType() : OreType{ return $this->type; } - public function canPlaceObject(ChunkManager $level, $x, $y, $z){ - return ($level->getBlockIdAt($x, $y, $z) === 1); + public function canPlaceObject(ChunkManager $level, int $x, int $y, int $z) : bool{ + return $level->getBlockIdAt($x, $y, $z) === Block::STONE; } - public function placeObject(ChunkManager $level, $x, $y, $z){ - $clusterSize = (int) $this->type->clusterSize; + public function placeObject(ChunkManager $level, int $x, int $y, int $z){ + $clusterSize = $this->type->clusterSize; $angle = $this->random->nextFloat() * M_PI; $offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8); $x1 = $x + 8 + $offset->x; diff --git a/src/pocketmine/level/generator/object/OreType.php b/src/pocketmine/level/generator/object/OreType.php index 8c4794fea..7b45ac676 100644 --- a/src/pocketmine/level/generator/object/OreType.php +++ b/src/pocketmine/level/generator/object/OreType.php @@ -26,13 +26,22 @@ namespace pocketmine\level\generator\object; use pocketmine\block\Block; class OreType{ - public $material, $clusterCount, $clusterSize, $maxHeight, $minHeight; + /** @var Block */ + public $material; + /** @var int */ + public $clusterCount; + /** @var int */ + public $clusterSize; + /** @var int */ + public $maxHeight; + /** @var int */ + public $minHeight; - public function __construct(Block $material, $clusterCount, $clusterSize, $minHeight, $maxHeight){ + public function __construct(Block $material, int $clusterCount, int $clusterSize, int $minHeight, int $maxHeight){ $this->material = $material; - $this->clusterCount = (int) $clusterCount; - $this->clusterSize = (int) $clusterSize; - $this->maxHeight = (int) $maxHeight; - $this->minHeight = (int) $minHeight; + $this->clusterCount = $clusterCount; + $this->clusterSize = $clusterSize; + $this->maxHeight = $maxHeight; + $this->minHeight = $minHeight; } } \ No newline at end of file diff --git a/src/pocketmine/level/generator/object/Pond.php b/src/pocketmine/level/generator/object/Pond.php index e1198bdb3..91fc7675a 100644 --- a/src/pocketmine/level/generator/object/Pond.php +++ b/src/pocketmine/level/generator/object/Pond.php @@ -42,6 +42,7 @@ class Pond{ } public function placeObject(ChunkManager $level, Vector3 $pos){ + } } \ No newline at end of file diff --git a/src/pocketmine/level/generator/object/SpruceTree.php b/src/pocketmine/level/generator/object/SpruceTree.php index d7b273048..cf6d28bab 100644 --- a/src/pocketmine/level/generator/object/SpruceTree.php +++ b/src/pocketmine/level/generator/object/SpruceTree.php @@ -37,7 +37,7 @@ class SpruceTree extends Tree{ $this->treeHeight = 10; } - public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){ + public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){ $this->treeHeight = $random->nextBoundedInt(4) + 6; $topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2)); diff --git a/src/pocketmine/level/generator/object/TallGrass.php b/src/pocketmine/level/generator/object/TallGrass.php index 1c8cd9abb..6e307277f 100644 --- a/src/pocketmine/level/generator/object/TallGrass.php +++ b/src/pocketmine/level/generator/object/TallGrass.php @@ -29,7 +29,8 @@ use pocketmine\math\Vector3; use pocketmine\utils\Random; class TallGrass{ - public static function growGrass(ChunkManager $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){ + + public static function growGrass(ChunkManager $level, Vector3 $pos, Random $random, int $count = 15, int $radius = 10){ $arr = [ [Block::DANDELION, 0], [Block::POPPY, 0], diff --git a/src/pocketmine/level/generator/object/Tree.php b/src/pocketmine/level/generator/object/Tree.php index b2b8b77e7..9f089bf1f 100644 --- a/src/pocketmine/level/generator/object/Tree.php +++ b/src/pocketmine/level/generator/object/Tree.php @@ -44,7 +44,7 @@ abstract class Tree{ public $leafBlock = Block::LEAVES; public $treeHeight = 7; - public static function growTree(ChunkManager $level, $x, $y, $z, Random $random, $type = 0){ + public static function growTree(ChunkManager $level, int $x, int $y, int $z, Random $random, int $type = 0){ switch($type){ case Sapling::SPRUCE: $tree = new SpruceTree(); @@ -78,7 +78,7 @@ abstract class Tree{ public function canPlaceObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : bool{ $radiusToCheck = 0; for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){ - if($yy == 1 or $yy === $this->treeHeight){ + if($yy === 1 or $yy === $this->treeHeight){ ++$radiusToCheck; } for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){ @@ -93,7 +93,7 @@ abstract class Tree{ return true; } - public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){ + public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){ $this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - 1); @@ -116,7 +116,7 @@ abstract class Tree{ } } - protected function placeTrunk(ChunkManager $level, $x, $y, $z, Random $random, $trunkHeight){ + protected function placeTrunk(ChunkManager $level, int $x, int $y, int $z, Random $random, int $trunkHeight){ // The base dirt block $level->setBlockIdAt($x, $y - 1, $z, Block::DIRT); diff --git a/src/pocketmine/level/generator/populator/GroundCover.php b/src/pocketmine/level/generator/populator/GroundCover.php index 7c0967dae..ba378a88d 100644 --- a/src/pocketmine/level/generator/populator/GroundCover.php +++ b/src/pocketmine/level/generator/populator/GroundCover.php @@ -30,7 +30,7 @@ use pocketmine\utils\Random; class GroundCover extends Populator{ - public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){ + public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){ $chunk = $level->getChunk($chunkX, $chunkZ); for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ diff --git a/src/pocketmine/level/generator/populator/Mineshaft.php b/src/pocketmine/level/generator/populator/Mineshaft.php index eeee874a1..9bec1206d 100644 --- a/src/pocketmine/level/generator/populator/Mineshaft.php +++ b/src/pocketmine/level/generator/populator/Mineshaft.php @@ -33,7 +33,7 @@ class Mineshaft extends Populator{ private static $BASE_Y = 35; private static $RAND_Y = 11; - public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){ + public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){ if($random->nextRange(0, self::$ODD) === 0){ //$mineshaft = new Mineshaft($random); } diff --git a/src/pocketmine/level/generator/populator/Ore.php b/src/pocketmine/level/generator/populator/Ore.php index 0af14c8cf..d306ffd3c 100644 --- a/src/pocketmine/level/generator/populator/Ore.php +++ b/src/pocketmine/level/generator/populator/Ore.php @@ -25,12 +25,14 @@ namespace pocketmine\level\generator\populator; use pocketmine\level\ChunkManager; use pocketmine\level\generator\object\Ore as ObjectOre; +use pocketmine\level\generator\object\OreType; use pocketmine\utils\Random; class Ore extends Populator{ + /** @var OreType[] */ private $oreTypes = []; - public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){ + public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){ foreach($this->oreTypes as $type){ $ore = new ObjectOre($random, $type); for($i = 0; $i < $ore->type->clusterCount; ++$i){ @@ -44,6 +46,9 @@ class Ore extends Populator{ } } + /** + * @param OreType[] $types + */ public function setOreTypes(array $types){ $this->oreTypes = $types; } diff --git a/src/pocketmine/level/generator/populator/Pond.php b/src/pocketmine/level/generator/populator/Pond.php index a949a029e..9c1a2f88c 100644 --- a/src/pocketmine/level/generator/populator/Pond.php +++ b/src/pocketmine/level/generator/populator/Pond.php @@ -33,7 +33,7 @@ class Pond extends Populator{ private $lavaOdd = 4; private $lavaSurfaceOdd = 4; - public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){ + public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){ if($random->nextRange(0, $this->waterOdd) === 0){ $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16); $y = $random->nextBoundedInt(128); @@ -45,15 +45,15 @@ class Pond extends Populator{ } } - public function setWaterOdd($waterOdd){ + public function setWaterOdd(int $waterOdd){ $this->waterOdd = $waterOdd; } - public function setLavaOdd($lavaOdd){ + public function setLavaOdd(int $lavaOdd){ $this->lavaOdd = $lavaOdd; } - public function setLavaSurfaceOdd($lavaSurfaceOdd){ + public function setLavaSurfaceOdd(int $lavaSurfaceOdd){ $this->lavaSurfaceOdd = $lavaSurfaceOdd; } } \ No newline at end of file diff --git a/src/pocketmine/level/generator/populator/Populator.php b/src/pocketmine/level/generator/populator/Populator.php index 42dddbe96..17d2444e7 100644 --- a/src/pocketmine/level/generator/populator/Populator.php +++ b/src/pocketmine/level/generator/populator/Populator.php @@ -30,5 +30,14 @@ use pocketmine\level\ChunkManager; use pocketmine\utils\Random; abstract class Populator{ - abstract public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random); + + /** + * @param ChunkManager $level + * @param int $chunkX + * @param int $chunkZ + * @param Random $random + * + * @return mixed + */ + abstract public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random); } \ No newline at end of file diff --git a/src/pocketmine/level/generator/populator/TallGrass.php b/src/pocketmine/level/generator/populator/TallGrass.php index 499fc6a40..aba98de5b 100644 --- a/src/pocketmine/level/generator/populator/TallGrass.php +++ b/src/pocketmine/level/generator/populator/TallGrass.php @@ -41,7 +41,7 @@ class TallGrass extends Populator{ $this->baseAmount = $amount; } - public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){ + public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){ $this->level = $level; $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; for($i = 0; $i < $amount; ++$i){ diff --git a/src/pocketmine/level/generator/populator/Tree.php b/src/pocketmine/level/generator/populator/Tree.php index e653384c2..28db1f65c 100644 --- a/src/pocketmine/level/generator/populator/Tree.php +++ b/src/pocketmine/level/generator/populator/Tree.php @@ -49,7 +49,7 @@ class Tree extends Populator{ $this->baseAmount = $amount; } - public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){ + public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){ $this->level = $level; $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; for($i = 0; $i < $amount; ++$i){ diff --git a/src/pocketmine/level/particle/FloatingTextParticle.php b/src/pocketmine/level/particle/FloatingTextParticle.php index bbd5f940d..1951151f2 100644 --- a/src/pocketmine/level/particle/FloatingTextParticle.php +++ b/src/pocketmine/level/particle/FloatingTextParticle.php @@ -96,7 +96,7 @@ class FloatingTextParticle extends Particle{ ); $pk->metadata = [ Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, $flags], - Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $this->title . ($this->text !== "" ? "\n" . $this->text : "")], + Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $this->title . ($this->text !== "" ? "\n" . $this->text : "")] ]; $p[] = $pk; diff --git a/src/pocketmine/network/AdvancedSourceInterface.php b/src/pocketmine/network/AdvancedSourceInterface.php index 56184b3b7..b85ff8b99 100644 --- a/src/pocketmine/network/AdvancedSourceInterface.php +++ b/src/pocketmine/network/AdvancedSourceInterface.php @@ -32,7 +32,7 @@ interface AdvancedSourceInterface extends SourceInterface{ * @param string $address * @param int $timeout Seconds */ - public function blockAddress($address, $timeout = 300); + public function blockAddress(string $address, int $timeout = 300); /** * @param Network $network @@ -44,6 +44,6 @@ interface AdvancedSourceInterface extends SourceInterface{ * @param int $port * @param string $payload */ - public function sendRawPacket($address, $port, $payload); + public function sendRawPacket(string $address, int $port, string $payload); } \ No newline at end of file diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 83d3ac6f7..6b60ddd80 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -45,6 +45,7 @@ class Network{ private $upload = 0; private $download = 0; + /** @var string */ private $name; public function __construct(Server $server){ @@ -75,7 +76,7 @@ class Network{ /** * @return SourceInterface[] */ - public function getInterfaces(){ + public function getInterfaces() : array{ return $this->interfaces; } @@ -121,14 +122,17 @@ class Network{ * * @param string $name */ - public function setName($name){ - $this->name = (string) $name; + public function setName(string $name){ + $this->name = $name; foreach($this->interfaces as $interface){ $interface->setName($this->name); } } - public function getName(){ + /** + * @return string + */ + public function getName() : string{ return $this->name; } @@ -138,7 +142,10 @@ class Network{ } } - public function getServer(){ + /** + * @return Server + */ + public function getServer() : Server{ return $this->server; } @@ -147,7 +154,7 @@ class Network{ * @param int $port * @param string $payload */ - public function sendPacket($address, $port, $payload){ + public function sendPacket(string $address, int $port, string $payload){ foreach($this->advancedInterfaces as $interface){ $interface->sendRawPacket($address, $port, $payload); } @@ -159,7 +166,7 @@ class Network{ * @param string $address * @param int $timeout */ - public function blockAddress($address, $timeout = 300){ + public function blockAddress(string $address, int $timeout = 300){ foreach($this->advancedInterfaces as $interface){ $interface->blockAddress($address, $timeout); } diff --git a/src/pocketmine/network/SourceInterface.php b/src/pocketmine/network/SourceInterface.php index 832c39a88..0b08e394d 100644 --- a/src/pocketmine/network/SourceInterface.php +++ b/src/pocketmine/network/SourceInterface.php @@ -44,16 +44,15 @@ interface SourceInterface{ * * @return int|null */ - public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = true); + public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true); /** * Terminates the connection * * @param Player $player * @param string $reason - * */ - public function close(Player $player, $reason = "unknown reason"); + public function close(Player $player, string $reason = "unknown reason"); /** * @param string $name @@ -63,7 +62,7 @@ interface SourceInterface{ /** * @return bool */ - public function process(); + public function process() : bool; public function shutdown(); diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 882819992..863caaf14 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -75,7 +75,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $this->network = $network; } - public function process(){ + public function process() : bool{ $work = false; if($this->interface->handlePacket()){ $work = true; @@ -102,7 +102,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ } } - public function close(Player $player, $reason = "unknown reason"){ + public function close(Player $player, string $reason = "unknown reason"){ if(isset($this->identifiers[$h = spl_object_hash($player)])){ unset($this->players[$this->identifiers[$h]]); unset($this->identifiersACK[$this->identifiers[$h]]); @@ -148,7 +148,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ } } - public function blockAddress($address, $timeout = 300){ + public function blockAddress(string $address, int $timeout = 300){ $this->interface->blockAddress($address, $timeout); } @@ -156,7 +156,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $this->server->handlePacket($address, $port, $payload); } - public function sendRawPacket($address, $port, $payload){ + public function sendRawPacket(string $address, int $port, string $payload){ $this->interface->sendRaw($address, $port, $payload); } @@ -193,7 +193,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ } } - public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = false){ + public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true){ if(isset($this->identifiers[$h = spl_object_hash($player)])){ $identifier = $this->identifiers[$h]; if(!$packet->isEncoded){ diff --git a/src/pocketmine/network/rcon/RCON.php b/src/pocketmine/network/rcon/RCON.php index 9f90ca11a..991d76482 100644 --- a/src/pocketmine/network/rcon/RCON.php +++ b/src/pocketmine/network/rcon/RCON.php @@ -41,10 +41,9 @@ class RCON{ private $workers = []; private $clientsPerThread; - public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){ + public function __construct(Server $server, string $password, int $port = 19132, string $interface = "0.0.0.0", int $threads = 1, int $clientsPerThread = 50){ $this->server = $server; - $this->workers = []; - $this->password = (string) $password; + $this->password = $password; $this->server->getLogger()->info("Starting remote control listener"); if($this->password === ""){ throw new \InvalidArgumentException("Empty password"); @@ -54,7 +53,7 @@ class RCON{ $this->clientsPerThread = (int) max(1, $clientsPerThread); $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if($this->socket === false or !@socket_bind($this->socket, $interface, (int) $port) or !@socket_listen($this->socket)){ + if($this->socket === false or !@socket_bind($this->socket, $interface, $port) or !@socket_listen($this->socket)){ throw new \RuntimeException(trim(socket_strerror(socket_last_error()))); } diff --git a/src/pocketmine/network/rcon/RCONInstance.php b/src/pocketmine/network/rcon/RCONInstance.php index adc384504..470bdf68e 100644 --- a/src/pocketmine/network/rcon/RCONInstance.php +++ b/src/pocketmine/network/rcon/RCONInstance.php @@ -30,6 +30,7 @@ class RCONInstance extends Thread{ public $stop; public $cmd; public $response; + /** @var resource */ private $socket; private $password; private $maxClients; @@ -39,14 +40,18 @@ class RCONInstance extends Thread{ return $this->waiting === true; } - - public function __construct($socket, $password, $maxClients = 50){ + /** + * @param resource $socket + * @param string $password + * @param int $maxClients + */ + public function __construct($socket, string $password, int $maxClients = 50){ $this->stop = false; $this->cmd = ""; $this->response = ""; $this->socket = $socket; $this->password = $password; - $this->maxClients = (int) $maxClients; + $this->maxClients = $maxClients; for($n = 0; $n < $this->maxClients; ++$n){ $this->{"client" . $n} = null; $this->{"status" . $n} = 0; @@ -192,7 +197,7 @@ class RCONInstance extends Thread{ exit(0); } - public function getThreadName(){ + public function getThreadName() : string{ return "RCON"; } } \ No newline at end of file diff --git a/src/pocketmine/permission/Permissible.php b/src/pocketmine/permission/Permissible.php index 065d66fc7..c977182d3 100644 --- a/src/pocketmine/permission/Permissible.php +++ b/src/pocketmine/permission/Permissible.php @@ -52,7 +52,7 @@ interface Permissible extends ServerOperator{ * * @return PermissionAttachment */ - public function addAttachment(Plugin $plugin, $name = null, $value = null); + public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment; /** * @param PermissionAttachment $attachment diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index d8bd09148..aa0d7836a 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -122,13 +122,11 @@ class PermissibleBase implements Permissible{ * * @param Plugin $plugin * @param string $name - * @param bool $value + * @param bool $value * * @return PermissionAttachment - * - * @throws PluginException */ - public function addAttachment(Plugin $plugin, $name = null, $value = null){ + public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{ if(!$plugin->isEnabled()){ throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } diff --git a/src/pocketmine/permission/Permission.php b/src/pocketmine/permission/Permission.php index 1ffbd60f8..2fb0a10a1 100644 --- a/src/pocketmine/permission/Permission.php +++ b/src/pocketmine/permission/Permission.php @@ -40,11 +40,11 @@ class Permission{ public static $DEFAULT_PERMISSION = self::DEFAULT_OP; /** - * @param $value + * @param bool|string $value * * @return string */ - public static function getByName($value){ + public static function getByName($value) : string{ if(is_bool($value)){ if($value === true){ return "true"; @@ -86,7 +86,7 @@ class Permission{ /** * @var string[] */ - private $children = []; + private $children; /** @var string */ private $defaultValue; @@ -99,7 +99,7 @@ class Permission{ * @param string $defaultValue * @param Permission[] $children */ - public function __construct($name, $description = null, $defaultValue = null, array $children = []){ + public function __construct(string $name, string $description = null, string $defaultValue = null, array $children = []){ $this->name = $name; $this->description = $description ?? ""; $this->defaultValue = $defaultValue ?? self::$DEFAULT_PERMISSION; @@ -149,7 +149,7 @@ class Permission{ /** * @param string $value */ - public function setDescription($value){ + public function setDescription(string $value){ $this->description = $value; } @@ -196,12 +196,12 @@ class Permission{ } /** - * @param array $data - * @param $default + * @param array $data + * @param string $default * * @return Permission[] */ - public static function loadPermissions(array $data, $default = self::DEFAULT_OP) : array{ + public static function loadPermissions(array $data, string $default = self::DEFAULT_OP) : array{ $result = []; foreach($data as $key => $entry){ $result[] = self::loadPermission($key, $entry, $default, $result); @@ -220,7 +220,7 @@ class Permission{ * * @throws \Exception */ - public static function loadPermission($name, array $data, $default = self::DEFAULT_OP, &$output = []){ + public static function loadPermission(string $name, array $data, string $default = self::DEFAULT_OP, array &$output = []) : Permission{ $desc = null; $children = []; if(isset($data["default"])){ diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index dae4c3ffb..48cdee88e 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -59,7 +59,7 @@ class PermissionAttachment{ /** * @return Plugin */ - public function getPlugin(){ + public function getPlugin() : Plugin{ return $this->plugin; } @@ -71,7 +71,7 @@ class PermissionAttachment{ } /** - * @return PermissionRemovedExecutor + * @return PermissionRemovedExecutor|null */ public function getRemovalCallback(){ return $this->removed; @@ -80,14 +80,14 @@ class PermissionAttachment{ /** * @return Permissible */ - public function getPermissible(){ + public function getPermissible() : Permissible{ return $this->permissible; } /** * @return bool[] */ - public function getPermissions(){ + public function getPermissions() : array{ return $this->permissions; } @@ -120,7 +120,7 @@ class PermissionAttachment{ * @param string|Permission $name * @param bool $value */ - public function setPermission($name, $value){ + public function setPermission($name, bool $value){ $name = $name instanceof Permission ? $name->getName() : $name; if(isset($this->permissions[$name])){ if($this->permissions[$name] === $value){ diff --git a/src/pocketmine/permission/PermissionAttachmentInfo.php b/src/pocketmine/permission/PermissionAttachmentInfo.php index 56cea0120..4eee81d2c 100644 --- a/src/pocketmine/permission/PermissionAttachmentInfo.php +++ b/src/pocketmine/permission/PermissionAttachmentInfo.php @@ -31,25 +31,21 @@ class PermissionAttachmentInfo{ /** @var string */ private $permission; - /** @var PermissionAttachment */ + /** @var PermissionAttachment|null */ private $attachment; /** @var bool */ private $value; /** - * @param Permissible $permissible - * @param string $permission - * @param PermissionAttachment $attachment - * @param bool $value + * @param Permissible $permissible + * @param string $permission + * @param PermissionAttachment|null $attachment + * @param bool $value * * @throws \InvalidStateException */ - public function __construct(Permissible $permissible, $permission, $attachment, $value){ - if($permission === null){ - throw new \InvalidStateException("Permission may not be null"); - } - + public function __construct(Permissible $permissible, string $permission, PermissionAttachment $attachment = null, bool $value){ $this->permissible = $permissible; $this->permission = $permission; $this->attachment = $attachment; @@ -59,19 +55,19 @@ class PermissionAttachmentInfo{ /** * @return Permissible */ - public function getPermissible(){ + public function getPermissible() : Permissible{ return $this->permissible; } /** * @return string */ - public function getPermission(){ + public function getPermission() : string{ return $this->permission; } /** - * @return PermissionAttachment + * @return PermissionAttachment|null */ public function getAttachment(){ return $this->attachment; @@ -80,7 +76,7 @@ class PermissionAttachmentInfo{ /** * @return bool */ - public function getValue(){ + public function getValue() : bool{ return $this->value; } } \ No newline at end of file diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index a0a5e3301..887059b8b 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -141,7 +141,7 @@ abstract class PluginBase implements Plugin{ * * @return Command|PluginIdentifiableCommand|null */ - public function getCommand($name){ + public function getCommand(string $name){ $command = $this->getServer()->getPluginCommand($name); if($command === null or $command->getPlugin() !== $this){ $command = $this->getServer()->getPluginCommand(strtolower($this->description->getName()) . ":" . $name); diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index 5f0309119..a53b5b27d 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -264,7 +264,7 @@ class PluginDescription{ /** * @return array */ - public function getSoftDepend(){ + public function getSoftDepend() : array{ return $this->softDepend; } diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index 088a8cc05..c53dab85c 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -106,7 +106,7 @@ class PluginManager{ * * @return null|Plugin */ - public function getPlugin($name){ + public function getPlugin(string $name){ if(isset($this->plugins[$name])){ return $this->plugins[$name]; } @@ -144,7 +144,7 @@ class PluginManager{ * * @return Plugin|null */ - public function loadPlugin($path, $loaders = null){ + public function loadPlugin(string $path, array $loaders = null){ foreach($loaders ?? $this->fileAssociations as $loader){ if(preg_match($loader->getPluginFilters(), basename($path)) > 0){ $description = $loader->getPluginDescription($path); @@ -185,7 +185,7 @@ class PluginManager{ * * @return Plugin[] */ - public function loadPlugins($directory, $newLoaders = null){ + public function loadPlugins(string $directory, array $newLoaders = null){ if(is_dir($directory)){ $plugins = []; @@ -359,7 +359,7 @@ class PluginManager{ * * @return null|Permission */ - public function getPermission($name){ + public function getPermission(string $name){ if(isset($this->permissions[$name])){ return $this->permissions[$name]; } @@ -399,7 +399,7 @@ class PluginManager{ * * @return Permission[] */ - public function getDefaultPermissions($op){ + public function getDefaultPermissions(bool $op) : array{ if($op === true){ return $this->defaultPermsOp; }else{ @@ -438,7 +438,7 @@ class PluginManager{ /** * @param bool $op */ - private function dirtyPermissibles($op){ + private function dirtyPermissibles(bool $op){ foreach($this->getDefaultPermSubscriptions($op) as $p){ $p->recalculatePermissions(); } @@ -448,7 +448,7 @@ class PluginManager{ * @param string $permission * @param Permissible $permissible */ - public function subscribeToPermission($permission, Permissible $permissible){ + public function subscribeToPermission(string $permission, Permissible $permissible){ if(!isset($this->permSubs[$permission])){ $this->permSubs[$permission] = []; } @@ -459,7 +459,7 @@ class PluginManager{ * @param string $permission * @param Permissible $permissible */ - public function unsubscribeFromPermission($permission, Permissible $permissible){ + public function unsubscribeFromPermission(string $permission, Permissible $permissible){ if(isset($this->permSubs[$permission])){ unset($this->permSubs[$permission][spl_object_hash($permissible)]); if(count($this->permSubs[$permission]) === 0){ @@ -497,7 +497,7 @@ class PluginManager{ * @param bool $op * @param Permissible $permissible */ - public function subscribeToDefaultPerms($op, Permissible $permissible){ + public function subscribeToDefaultPerms(bool $op, Permissible $permissible){ if($op === true){ $this->defSubsOp[spl_object_hash($permissible)] = $permissible; }else{ @@ -509,7 +509,7 @@ class PluginManager{ * @param bool $op * @param Permissible $permissible */ - public function unsubscribeFromDefaultPerms($op, Permissible $permissible){ + public function unsubscribeFromDefaultPerms(bool $op, Permissible $permissible){ if($op === true){ unset($this->defSubsOp[spl_object_hash($permissible)]); }else{ @@ -564,7 +564,7 @@ class PluginManager{ * * @return bool */ - public function isPluginEnabled(Plugin $plugin){ + public function isPluginEnabled(Plugin $plugin) : bool{ if($plugin instanceof Plugin and isset($this->plugins[$plugin->getDescription()->getName()])){ return $plugin->isEnabled(); }else{ @@ -766,7 +766,7 @@ class PluginManager{ * * @throws PluginException */ - public function registerEvent($event, Listener $listener, $priority, EventExecutor $executor, Plugin $plugin, $ignoreCancelled = false){ + public function registerEvent(string $event, Listener $listener, int $priority, EventExecutor $executor, Plugin $plugin, bool $ignoreCancelled = false){ if(!is_subclass_of($event, Event::class)){ throw new PluginException($event . " is not an Event"); } @@ -799,7 +799,7 @@ class PluginManager{ * * @return HandlerList */ - private function getEventListeners($event) : HandlerList{ + private function getEventListeners(string $event) : HandlerList{ if($event::$handlerList === null){ $event::$handlerList = new HandlerList(); } diff --git a/src/pocketmine/plugin/RegisteredListener.php b/src/pocketmine/plugin/RegisteredListener.php index 03befa4d9..5b2962ef0 100644 --- a/src/pocketmine/plugin/RegisteredListener.php +++ b/src/pocketmine/plugin/RegisteredListener.php @@ -57,7 +57,7 @@ class RegisteredListener{ * @param bool $ignoreCancelled * @param TimingsHandler $timings */ - public function __construct(Listener $listener, EventExecutor $executor, $priority, Plugin $plugin, $ignoreCancelled, TimingsHandler $timings){ + public function __construct(Listener $listener, EventExecutor $executor, int $priority, Plugin $plugin, bool $ignoreCancelled, TimingsHandler $timings){ $this->listener = $listener; $this->priority = $priority; $this->plugin = $plugin; diff --git a/src/pocketmine/plugin/ScriptPluginLoader.php b/src/pocketmine/plugin/ScriptPluginLoader.php index d6c949707..31d852e61 100644 --- a/src/pocketmine/plugin/ScriptPluginLoader.php +++ b/src/pocketmine/plugin/ScriptPluginLoader.php @@ -130,7 +130,7 @@ class ScriptPluginLoader implements PluginLoader{ * @param string $dataFolder * @param string $file */ - private function initPlugin(PluginBase $plugin, PluginDescription $description, $dataFolder, $file){ + private function initPlugin(PluginBase $plugin, PluginDescription $description, string $dataFolder, string $file){ $plugin->init($this, $this->server, $description, $dataFolder, $file); $plugin->onLoad(); } diff --git a/src/pocketmine/updater/AutoUpdater.php b/src/pocketmine/updater/AutoUpdater.php index c75b5b12d..50208de1c 100644 --- a/src/pocketmine/updater/AutoUpdater.php +++ b/src/pocketmine/updater/AutoUpdater.php @@ -44,7 +44,7 @@ class AutoUpdater{ * @param Server $server * @param string $endpoint */ - public function __construct(Server $server, $endpoint){ + public function __construct(Server $server, string $endpoint){ $this->server = $server; $this->endpoint = "http://$endpoint/api/"; diff --git a/src/pocketmine/utils/Config.php b/src/pocketmine/utils/Config.php index 2dccf3dfb..9831e7465 100644 --- a/src/pocketmine/utils/Config.php +++ b/src/pocketmine/utils/Config.php @@ -70,7 +70,7 @@ class Config{ "serialize" => Config::SERIALIZED, "txt" => Config::ENUM, "list" => Config::ENUM, - "enum" => Config::ENUM, + "enum" => Config::ENUM ]; /** @@ -79,7 +79,7 @@ class Config{ * @param array $default Array with the default values that will be written to the file if it did not exist * @param null &$correct Sets correct to true if everything has been loaded correctly */ - public function __construct($file, $type = Config::DETECT, $default = [], &$correct = null){ + public function __construct(string $file, int $type = Config::DETECT, array $default = [], &$correct = null){ $this->load($file, $type, $default); $correct = $this->correct; } @@ -95,11 +95,11 @@ class Config{ } /** - * @param $str + * @param string $str * - * @return mixed + * @return string */ - public static function fixYAMLIndexes($str){ + public static function fixYAMLIndexes(string $str) : string{ return preg_replace("#^([ ]*)([a-zA-Z_]{1}[ ]*)\\:$#m", "$1\"$2\":", $str); } @@ -180,7 +180,7 @@ class Config{ * * @return bool */ - public function save($async = false){ + public function save(bool $async = false) : bool{ if($this->correct === true){ try{ $content = null; @@ -402,7 +402,7 @@ class Config{ /** * @param array $v */ - public function setAll($v){ + public function setAll(array $v){ $this->config = $v; } @@ -412,7 +412,7 @@ class Config{ * * @return bool */ - public function exists($k, $lowercase = false){ + public function exists($k, bool $lowercase = false) : bool{ if($lowercase === true){ $k = strtolower($k); //Convert requested key to lower $array = array_change_key_case($this->config, CASE_LOWER); //Change all keys in array to lower @@ -469,9 +469,9 @@ class Config{ } /** - * @param $content + * @param string $content */ - private function parseList($content){ + private function parseList(string $content){ foreach(explode("\n", trim(str_replace("\r\n", "\n", $content))) as $v){ $v = trim($v); if($v == ""){ @@ -499,9 +499,9 @@ class Config{ } /** - * @param $content + * @param string $content */ - private function parseProperties($content){ + private function parseProperties(string $content){ if(preg_match_all('/([a-zA-Z0-9\-_\.]*)=([^\r\n]*)/u', $content, $matches) > 0){ //false or 0 matches foreach($matches[1] as $i => $k){ $v = trim($matches[2][$i]); diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index 818e7976a..eb92bde8d 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -139,7 +139,7 @@ class MainLogger extends \AttachableThreadedLogger{ E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", - E_USER_DEPRECATED => "E_USER_DEPRECATED", + E_USER_DEPRECATED => "E_USER_DEPRECATED" ]; if($errno === 0){ $type = LogLevel::CRITICAL; diff --git a/src/pocketmine/utils/Random.php b/src/pocketmine/utils/Random.php index 2e918bc57..f7994bd34 100644 --- a/src/pocketmine/utils/Random.php +++ b/src/pocketmine/utils/Random.php @@ -53,12 +53,13 @@ class Random{ */ private $w; + /** @var int */ protected $seed; /** * @param int $seed Integer to be used as seed. */ - public function __construct($seed = -1){ + public function __construct(int $seed = -1){ if($seed === -1){ $seed = time(); } @@ -69,7 +70,7 @@ class Random{ /** * @param int $seed Integer to be used as seed. */ - public function setSeed($seed){ + public function setSeed(int $seed){ $this->seed = $seed; $this->x = self::X ^ $seed; $this->y = self::Y ^ ($seed << 17) | (($seed >> 15) & 0x7fffffff) & 0xffffffff; @@ -77,7 +78,7 @@ class Random{ $this->w = self::W ^ ($seed << 18) | (($seed >> 14) & 0x7fffffff) & 0xffffffff; } - public function getSeed(){ + public function getSeed() : int{ return $this->seed; } diff --git a/src/pocketmine/utils/ServerKiller.php b/src/pocketmine/utils/ServerKiller.php index 3bfa5d68a..40298911b 100644 --- a/src/pocketmine/utils/ServerKiller.php +++ b/src/pocketmine/utils/ServerKiller.php @@ -44,7 +44,7 @@ class ServerKiller extends Thread{ } } - public function getThreadName(){ + public function getThreadName() : string{ return "Server Killer"; } } diff --git a/src/pocketmine/utils/TextFormat.php b/src/pocketmine/utils/TextFormat.php index e49c6aa2e..34e1be68a 100644 --- a/src/pocketmine/utils/TextFormat.php +++ b/src/pocketmine/utils/TextFormat.php @@ -60,7 +60,7 @@ abstract class TextFormat{ * * @return array */ - public static function tokenize($string) : array{ + public static function tokenize(string $string) : array{ return preg_split("/(" . TextFormat::ESCAPE . "[0123456789abcdefklmnor])/", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); } @@ -70,9 +70,9 @@ abstract class TextFormat{ * @param string $string * @param bool $removeFormat * - * @return mixed + * @return string */ - public static function clean($string, $removeFormat = true){ + public static function clean(string $string, bool $removeFormat = true) : string{ if($removeFormat){ return str_replace(TextFormat::ESCAPE, "", preg_replace(["/" . TextFormat::ESCAPE . "[0123456789abcdefklmnor]/", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string)); } @@ -386,7 +386,7 @@ abstract class TextFormat{ /** * Returns a string with colorized ANSI Escape codes * - * @param $string + * @param string|array $string * * @return string */ diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index a57a7125b..3083156b9 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -129,7 +129,7 @@ class Utils{ * * @return string|bool */ - public static function getIP($force = false){ + public static function getIP(bool $force = false){ if(Utils::$online === false){ return false; }elseif(Utils::$ip !== false and $force !== true){ @@ -238,7 +238,12 @@ class Utils{ return [$heap, $stack]; } - public static function getMemoryUsage($advanced = false){ + /** + * @param bool $advanced + * + * @return int[]|int + */ + public static function getMemoryUsage(bool $advanced = false){ $reserved = memory_get_usage(); $VmSize = null; $VmRSS = null; @@ -270,7 +275,7 @@ class Utils{ return [$reserved, $VmRSS, $VmSize]; } - public static function getThreadCount(){ + public static function getThreadCount() : int{ if(Utils::getOS() === "linux" or Utils::getOS() === "android"){ if(preg_match("/Threads:[ \t]+([0-9]+)/", file_get_contents("/proc/self/status"), $matches) > 0){ return (int) $matches[1]; @@ -371,7 +376,7 @@ class Utils{ * GETs an URL using cURL * NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread. * - * @param $page + * @param string $page * @param int $timeout default 10 * @param array $extraHeaders * @param string &$err Will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. @@ -380,7 +385,7 @@ class Utils{ * * @return bool|mixed false if an error occurred, mixed data if successful. */ - public static function getURL($page, $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ + public static function getURL(string $page, int $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ try{ list($ret, $headers, $httpCode) = self::simpleCurl($page, $timeout, $extraHeaders); return $ret; @@ -404,7 +409,7 @@ class Utils{ * * @return bool|mixed false if an error occurred, mixed data if successful. */ - public static function postURL($page, $args, $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ + public static function postURL(string $page, $args, int $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ try{ list($ret, $headers, $httpCode) = self::simpleCurl($page, $timeout, $extraHeaders, [ CURLOPT_POST => 1, diff --git a/src/pocketmine/utils/VersionString.php b/src/pocketmine/utils/VersionString.php index 3d74b41e4..acb282da6 100644 --- a/src/pocketmine/utils/VersionString.php +++ b/src/pocketmine/utils/VersionString.php @@ -50,7 +50,7 @@ class VersionString{ $this->minor = (int) ($version[4] ?? 0); //0-31 $this->development = $version[5] === "dev"; if($version[6] !== ""){ - $this->build = (int) (substr($version[6], 1)); + $this->build = (int) substr($version[6], 1); }else{ $this->build = 0; }