More typehints, documentation fixes and static analysis cleanup

This commit is contained in:
Dylan K. Taylor
2017-07-15 12:12:06 +01:00
parent 24bdf330d5
commit dbb92096e4
66 changed files with 309 additions and 219 deletions

View File

@ -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;

View File

@ -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"]);

View File

@ -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")){

View File

@ -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);
}

View File

@ -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 = [];

View File

@ -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();
}
}

View File

@ -180,7 +180,7 @@ class CommandReader extends Thread{
}
public function getThreadName(){
public function getThreadName() : string{
return "Console";
}
}

View File

@ -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);
}

View File

@ -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");

View File

@ -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){

View File

@ -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;
}

View File

@ -43,7 +43,7 @@ class AttributeMap implements \ArrayAccess{
/**
* @return Attribute[]
*/
public function getAll(): array{
public function getAll() : array{
return $this->attributes;
}

View File

@ -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())
){

View File

@ -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)
]);
}

View File

@ -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 */

View File

@ -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 */

View File

@ -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])){

View File

@ -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()];
}

View File

@ -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){

View File

@ -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){

View File

@ -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[] */

View File

@ -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[] */

View File

@ -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;

View File

@ -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)
]);
}
}

View File

@ -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)
]);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -42,6 +42,7 @@ class Pond{
}
public function placeObject(ChunkManager $level, Vector3 $pos){
}
}

View File

@ -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));

View File

@ -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],

View File

@ -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);

View File

@ -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){

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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){

View File

@ -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){

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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();

View File

@ -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){

View File

@ -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())));
}

View File

@ -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";
}
}

View File

@ -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

View File

@ -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");
}

View File

@ -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"])){

View File

@ -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){

View File

@ -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;
}
}

View File

@ -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);

View File

@ -264,7 +264,7 @@ class PluginDescription{
/**
* @return array
*/
public function getSoftDepend(){
public function getSoftDepend() : array{
return $this->softDepend;
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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/";

View File

@ -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]);

View File

@ -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;

View File

@ -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;
}

View File

@ -44,7 +44,7 @@ class ServerKiller extends Thread{
}
}
public function getThreadName(){
public function getThreadName() : string{
return "Server Killer";
}
}

View File

@ -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
*/

View File

@ -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,

View File

@ -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;
}