mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
and more typehints
This commit is contained in:
@ -282,7 +282,7 @@ class Binary{
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function readRoundedFloat(string $str, int $accuracy){
|
||||
public static function readRoundedFloat(string $str, int $accuracy) : float{
|
||||
return round(self::readFloat($str), $accuracy);
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ class Binary{
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function readRoundedLFloat(string $str, int $accuracy){
|
||||
public static function readRoundedLFloat(string $str, int $accuracy) : float{
|
||||
return round(self::readLFloat($str), $accuracy);
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ class Binary{
|
||||
* @param float $value
|
||||
* @return string
|
||||
*/
|
||||
public static function printFloat(float $value){
|
||||
public static function printFloat(float $value) : string{
|
||||
return preg_replace("/(\\.\\d+?)0+$/", "$1", sprintf("%F", $value));
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ class Config{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function load(string $file, int $type = Config::DETECT, array $default = []){
|
||||
public function load(string $file, int $type = Config::DETECT, array $default = []) : bool{
|
||||
$this->correct = true;
|
||||
$this->file = $file;
|
||||
|
||||
@ -171,7 +171,7 @@ class Config{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function check(){
|
||||
public function check() : bool{
|
||||
return $this->correct === true;
|
||||
}
|
||||
|
||||
@ -434,7 +434,7 @@ class Config{
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll($keys = false){
|
||||
public function getAll(bool $keys = false) : array{
|
||||
return ($keys === true ? array_keys($this->config) : $this->config);
|
||||
}
|
||||
|
||||
@ -446,12 +446,12 @@ class Config{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $default
|
||||
* @param $data
|
||||
* @param array $default
|
||||
* @param array &$data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function fillDefaults($default, &$data){
|
||||
private function fillDefaults(array $default, &$data) : int{
|
||||
$changed = 0;
|
||||
foreach($default as $k => $v){
|
||||
if(is_array($v)){
|
||||
@ -484,7 +484,7 @@ class Config{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function writeProperties(){
|
||||
private function writeProperties() : string{
|
||||
$content = "#Properties Config file\r\n#" . date("D M j H:i:s T Y") . "\r\n";
|
||||
foreach($this->config as $k => $v){
|
||||
if(is_bool($v) === true){
|
||||
|
@ -86,7 +86,7 @@ class Random{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function nextInt(){
|
||||
public function nextInt() : int{
|
||||
return $this->nextSignedInt() & 0x7fffffff;
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ class Random{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function nextSignedInt(){
|
||||
public function nextSignedInt() : int{
|
||||
$t = ($this->x ^ ($this->x << 11)) & 0xffffffff;
|
||||
|
||||
$this->x = $this->y;
|
||||
@ -112,7 +112,7 @@ class Random{
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function nextFloat(){
|
||||
public function nextFloat() : float{
|
||||
return $this->nextInt() / 0x7fffffff;
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ class Random{
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function nextSignedFloat(){
|
||||
public function nextSignedFloat() : float{
|
||||
return $this->nextSignedInt() / 0x7fffffff;
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ class Random{
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function nextBoolean(){
|
||||
public function nextBoolean() : bool{
|
||||
return ($this->nextSignedInt() & 0x01) === 0;
|
||||
}
|
||||
|
||||
@ -138,15 +138,15 @@ class Random{
|
||||
* Returns a random integer between $start and $end
|
||||
*
|
||||
* @param int $start default 0
|
||||
* @param int $end default 0x7fffffff
|
||||
* @param int $end default 0x7fffffff
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function nextRange($start = 0, $end = 0x7fffffff){
|
||||
public function nextRange(int $start = 0, int $end = 0x7fffffff) : int{
|
||||
return $start + ($this->nextInt() % ($end + 1 - $start));
|
||||
}
|
||||
|
||||
public function nextBoundedInt($bound){
|
||||
public function nextBoundedInt(int $bound) : int{
|
||||
return $this->nextInt() % $bound;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ abstract class TextFormat{
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function tokenize($string){
|
||||
public static function tokenize($string) : array{
|
||||
return preg_split("/(" . TextFormat::ESCAPE . "[0123456789abcdefklmnor])/", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ abstract class TextFormat{
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function toJSON($string){
|
||||
public static function toJSON($string) : string{
|
||||
if(!is_array($string)){
|
||||
$string = self::tokenize($string);
|
||||
}
|
||||
@ -274,7 +274,7 @@ abstract class TextFormat{
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function toHTML($string){
|
||||
public static function toHTML($string) : string{
|
||||
if(!is_array($string)){
|
||||
$string = self::tokenize($string);
|
||||
}
|
||||
@ -390,7 +390,7 @@ abstract class TextFormat{
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function toANSI($string){
|
||||
public static function toANSI($string) : string{
|
||||
if(!is_array($string)){
|
||||
$string = self::tokenize($string);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class UUID{
|
||||
public function __construct(int $part1 = 0, int $part2 = 0, int $part3 = 0, int $part4 = 0, int $version = null){
|
||||
$this->parts = [$part1, $part2, $part3, $part4];
|
||||
|
||||
$this->version = $version === null ? ($this->parts[1] & 0xf000) >> 12 : $version;
|
||||
$this->version = $version ?? ($this->parts[1] & 0xf000) >> 12;
|
||||
}
|
||||
|
||||
public function getVersion() : int{
|
||||
|
@ -64,7 +64,7 @@ class Utils{
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public static function getMachineUniqueId($extra = ""){
|
||||
public static function getMachineUniqueId(string $extra = "") : UUID{
|
||||
if(self::$serverUniqueId !== null and $extra === ""){
|
||||
return self::$serverUniqueId;
|
||||
}
|
||||
@ -188,7 +188,7 @@ class Utils{
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getOS($recalculate = false){
|
||||
public static function getOS(bool $recalculate = false) : string{
|
||||
if(self::$os === null or $recalculate){
|
||||
$uname = php_uname("s");
|
||||
if(stripos($uname, "Darwin") !== false){
|
||||
@ -215,8 +215,10 @@ class Utils{
|
||||
return self::$os;
|
||||
}
|
||||
|
||||
|
||||
public static function getRealMemoryUsage(){
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public static function getRealMemoryUsage() : array{
|
||||
$stack = 0;
|
||||
$heap = 0;
|
||||
|
||||
@ -279,7 +281,11 @@ class Utils{
|
||||
return count(ThreadManager::getInstance()->getAll()) + 3; //RakLib + MainLogger + Main Thread
|
||||
}
|
||||
|
||||
public static function getCoreCount($recalculate = false){
|
||||
/**
|
||||
* @param bool $recalculate
|
||||
* @return int
|
||||
*/
|
||||
public static function getCoreCount(bool $recalculate = false) : int{
|
||||
static $processors = 0;
|
||||
|
||||
if($processors > 0 and !$recalculate){
|
||||
@ -321,7 +327,7 @@ class Utils{
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function hexdump($bin){
|
||||
public static function hexdump(string $bin) : string{
|
||||
$output = "";
|
||||
$bin = str_split($bin, 16);
|
||||
foreach($bin as $counter => $line){
|
||||
@ -337,11 +343,11 @@ class Utils{
|
||||
/**
|
||||
* Returns a string that can be printed, replaces non-printable characters
|
||||
*
|
||||
* @param $str
|
||||
* @param mixed $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function printable($str){
|
||||
public static function printable($str) : string{
|
||||
if(!is_string($str)){
|
||||
return gettype($str);
|
||||
}
|
||||
@ -476,7 +482,7 @@ class Utils{
|
||||
}
|
||||
}
|
||||
|
||||
public static function javaStringHash($string){
|
||||
public static function javaStringHash(string $string) : int{
|
||||
$hash = 0;
|
||||
for($i = 0, $len = strlen($string); $i < $len; $i++){
|
||||
$ord = ord($string{$i});
|
||||
|
Reference in New Issue
Block a user