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

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