Added some missing typehints

This commit is contained in:
Dylan K. Taylor 2018-06-10 17:18:55 +01:00
parent 89643ff9af
commit c4c6c58615
19 changed files with 27 additions and 27 deletions

View File

@ -2343,7 +2343,7 @@ class Server{
$p->dataPacket($pk);
}
private function checkTickUpdates($currentTick, $tickTime){
private function checkTickUpdates(int $currentTick, float $tickTime) : void{
foreach($this->players as $p){
if(!$p->loggedIn and ($tickTime - $p->creationTime) >= 10){
$p->close("", "Login timeout");

View File

@ -67,7 +67,7 @@ class Leaves extends Transparent{
}
protected function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null) : bool{
protected function findLog(Block $pos, array $visited, int $distance, &$check, ?int $fromSide = null) : bool{
++$check;
$index = $pos->x . "." . $pos->y . "." . $pos->z;
if(isset($visited[$index])){

View File

@ -38,7 +38,7 @@ class PluginCommand extends Command implements PluginIdentifiableCommand{
* @param string $name
* @param Plugin $owner
*/
public function __construct($name, Plugin $owner){
public function __construct(string $name, Plugin $owner){
parent::__construct($name);
$this->owningPlugin = $owner;
$this->executor = $owner;

View File

@ -43,7 +43,7 @@ class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{
* @param Player $player
* @param string $message
*/
public function __construct(Player $player, $message){
public function __construct(Player $player, string $message){
$this->player = $player;
$this->message = $message;
}

View File

@ -850,7 +850,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $flags
* @param bool $optimizeRebuilds
*/
public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, bool $optimizeRebuilds = false){
public function sendBlocks(array $target, array $blocks, int $flags = UpdateBlockPacket::FLAG_NONE, bool $optimizeRebuilds = false){
$packets = [];
if($optimizeRebuilds){
$chunks = [];
@ -2067,7 +2067,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Entity[]
*/
public function getChunkEntities($X, $Z) : array{
public function getChunkEntities(int $X, int $Z) : array{
return ($chunk = $this->getChunk($X, $Z)) !== null ? $chunk->getEntities() : [];
}
@ -2079,7 +2079,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Tile[]
*/
public function getChunkTiles($X, $Z) : array{
public function getChunkTiles(int $X, int $Z) : array{
return ($chunk = $this->getChunk($X, $Z)) !== null ? $chunk->getTiles() : [];
}

View File

@ -39,7 +39,7 @@ class SimpleChunkManager implements ChunkManager{
* @param int $seed
* @param int $worldHeight
*/
public function __construct($seed, int $worldHeight = Level::Y_MAX){
public function __construct(int $seed, int $worldHeight = Level::Y_MAX){
$this->seed = $seed;
$this->worldHeight = $worldHeight;
}

View File

@ -186,7 +186,7 @@ class Chunk{
*
* @return bool
*/
public function setBlock(int $x, int $y, int $z, $blockId = null, $meta = null) : bool{
public function setBlock(int $x, int $y, int $z, ?int $blockId = null, ?int $meta = null) : bool{
if($this->getSubChunk($y >> 4, true)->setBlock($x, $y & 0x0f, $z, $blockId !== null ? ($blockId & 0xff) : null, $meta !== null ? ($meta & 0x0f) : null)){
$this->hasChanged = true;
return true;

View File

@ -59,7 +59,7 @@ class EmptySubChunk implements SubChunkInterface{
return 0;
}
public function setBlock(int $x, int $y, int $z, $id = null, $data = null) : bool{
public function setBlock(int $x, int $y, int $z, ?int $id = null, ?int $data = null) : bool{
return false;
}

View File

@ -93,7 +93,7 @@ class SubChunk implements SubChunkInterface{
}
}
public function setBlock(int $x, int $y, int $z, $id = null, $data = null) : bool{
public function setBlock(int $x, int $y, int $z, ?int $id = null, ?int $data = null) : bool{
$i = ($x << 8) | ($z << 4) | $y;
$changed = false;
if($id !== null){

View File

@ -87,7 +87,7 @@ interface SubChunkInterface{
*
* @return bool
*/
public function setBlock(int $x, int $y, int $z, $id = null, $data = null) : bool;
public function setBlock(int $x, int $y, int $z, ?int $id = null, ?int $data = null) : bool;
/**
* @param int $x

View File

@ -56,12 +56,12 @@ class TallGrass extends Populator{
}
}
private function canTallGrassStay($x, $y, $z){
private function canTallGrassStay(int $x, int $y, int $z) : bool{
$b = $this->level->getBlockIdAt($x, $y, $z);
return ($b === Block::AIR or $b === Block::SNOW_LAYER) and $this->level->getBlockIdAt($x, $y - 1, $z) === Block::GRASS;
}
private function getHighestWorkableBlock($x, $z){
private function getHighestWorkableBlock(int $x, int $z) : int{
for($y = 127; $y >= 0; --$y){
$b = $this->level->getBlockIdAt($x, $y, $z);
if($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2 and $b !== Block::SNOW_LAYER){

View File

@ -63,7 +63,7 @@ class Tree extends Populator{
}
}
private function getHighestWorkableBlock($x, $z){
private function getHighestWorkableBlock(int $x, int $z) : int{
for($y = 127; $y > 0; --$y){
$b = $this->level->getBlockIdAt($x, $y, $z);
if($b === Block::DIRT or $b === Block::GRASS){

View File

@ -70,7 +70,7 @@ class QueryHandler{
$this->token = random_bytes(16);
}
public static function getTokenString($token, $salt){
public static function getTokenString(string $token, string $salt) : int{
return Binary::readInt(substr(hash("sha512", $salt . ":" . $token, true), 7, 4));
}

View File

@ -71,15 +71,15 @@ class RCONInstance extends Thread{
$this->start(PTHREADS_INHERIT_NONE);
}
private function writePacket($client, $requestID, $packetType, $payload){
$pk = Binary::writeLInt((int) $requestID)
. Binary::writeLInt((int) $packetType)
private function writePacket($client, int $requestID, int $packetType, string $payload){
$pk = Binary::writeLInt($requestID)
. Binary::writeLInt($packetType)
. $payload
. "\x00\x00"; //Terminate payload and packet
return socket_write($client, Binary::writeLInt(strlen($pk)) . $pk);
}
private function readPacket($client, &$requestID, &$packetType, &$payload){
private function readPacket($client, ?int &$requestID, ?int &$packetType, ?string &$payload){
$d = socket_read($client, 4);
if($this->stop){
return false;

View File

@ -178,7 +178,7 @@ class Permission{
*
* @return Permission|null Permission if $name is a string, null if it's a Permission
*/
public function addParent($name, $value){
public function addParent($name, bool $value){
if($name instanceof Permission){
$name->getChildren()[$this->getName()] = $value;
$name->recalculatePermissibles();

View File

@ -112,7 +112,7 @@ class PharPluginLoader 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

@ -113,7 +113,7 @@ abstract class PluginBase implements Plugin{
return $this->description;
}
final public function init(PluginLoader $loader, Server $server, PluginDescription $description, $dataFolder, $file){
final public function init(PluginLoader $loader, Server $server, PluginDescription $description, string $dataFolder, string $file){
if(!$this->initialized){
$this->initialized = true;
$this->loader = $loader;

View File

@ -110,13 +110,13 @@ abstract class Tile extends Position{
}
/**
* @param $className
* @param array $saveNames
* @param string $className
* @param array $saveNames
*
* @return bool
* @throws \ReflectionException
*/
public static function registerTile($className, array $saveNames = []) : bool{
public static function registerTile(string $className, array $saveNames = []) : bool{
$class = new \ReflectionClass($className);
if(is_a($className, Tile::class, true) and !$class->isAbstract()){
$shortName = $class->getShortName();

View File

@ -569,7 +569,7 @@ class Utils{
*
* @return int
*/
public static function getReferenceCount($value, $includeCurrent = true){
public static function getReferenceCount($value, bool $includeCurrent = true){
ob_start();
debug_zval_dump($value);
$ret = explode("\n", ob_get_contents());