mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 19:37:17 +00:00
Replace disallowed operators in src/utils/
This commit is contained in:
parent
c47dfa1fb8
commit
282b430b1f
@ -393,7 +393,7 @@ class Config{
|
||||
|
||||
while(count($vars) > 0){
|
||||
$baseKey = array_shift($vars);
|
||||
if(is_array($base) and isset($base[$baseKey])){
|
||||
if(is_array($base) && isset($base[$baseKey])){
|
||||
$base = $base[$baseKey];
|
||||
}else{
|
||||
return $default;
|
||||
@ -505,7 +505,7 @@ class Config{
|
||||
$changed = 0;
|
||||
foreach(Utils::stringifyKeys($default) as $k => $v){
|
||||
if(is_array($v)){
|
||||
if(!isset($data[$k]) or !is_array($data[$k])){
|
||||
if(!isset($data[$k]) || !is_array($data[$k])){
|
||||
$data[$k] = [];
|
||||
}
|
||||
$changed += $this->fillDefaults($v, $data[$k]);
|
||||
|
@ -81,7 +81,7 @@ final class Filesystem{
|
||||
if(is_dir($dir)){
|
||||
$objects = Utils::assumeNotFalse(scandir($dir, SCANDIR_SORT_NONE), "scandir() shouldn't return false when is_dir() returns true");
|
||||
foreach($objects as $object){
|
||||
if($object !== "." and $object !== ".."){
|
||||
if($object !== "." && $object !== ".."){
|
||||
$fullObject = Path::join($dir, $object);
|
||||
if(is_dir($fullObject)){
|
||||
self::recursiveUnlink($fullObject);
|
||||
|
@ -39,8 +39,8 @@ final class Git{
|
||||
* @param bool $dirty reference parameter, set to whether the repo has local changes
|
||||
*/
|
||||
public static function getRepositoryState(string $dir, bool &$dirty) : ?string{
|
||||
if(Process::execute("git -C \"$dir\" rev-parse HEAD", $out) === 0 and $out !== false and strlen($out = trim($out)) === 40){
|
||||
if(Process::execute("git -C \"$dir\" diff --quiet") === 1 or Process::execute("git -C \"$dir\" diff --cached --quiet") === 1){ //Locally-modified
|
||||
if(Process::execute("git -C \"$dir\" rev-parse HEAD", $out) === 0 && $out !== false && strlen($out = trim($out)) === 40){
|
||||
if(Process::execute("git -C \"$dir\" diff --quiet") === 1 || Process::execute("git -C \"$dir\" diff --cached --quiet") === 1){ //Locally-modified
|
||||
$dirty = true;
|
||||
}
|
||||
return $out;
|
||||
|
@ -80,7 +80,7 @@ class Internet{
|
||||
public static function getIP(bool $force = false){
|
||||
if(!self::$online){
|
||||
return false;
|
||||
}elseif(self::$ip !== false and !$force){
|
||||
}elseif(self::$ip !== false && !$force){
|
||||
return self::$ip;
|
||||
}
|
||||
|
||||
@ -90,22 +90,22 @@ class Internet{
|
||||
}
|
||||
|
||||
$ip = self::getURL("http://checkip.dyndns.org/");
|
||||
if($ip !== null and preg_match('#Current IP Address\: ([0-9a-fA-F\:\.]*)#', trim(strip_tags($ip->getBody())), $matches) > 0){
|
||||
if($ip !== null && preg_match('#Current IP Address\: ([0-9a-fA-F\:\.]*)#', trim(strip_tags($ip->getBody())), $matches) > 0){
|
||||
return self::$ip = $matches[1];
|
||||
}
|
||||
|
||||
$ip = self::getURL("http://www.checkip.org/");
|
||||
if($ip !== null and preg_match('#">([0-9a-fA-F\:\.]*)</span>#', $ip->getBody(), $matches) > 0){
|
||||
if($ip !== null && preg_match('#">([0-9a-fA-F\:\.]*)</span>#', $ip->getBody(), $matches) > 0){
|
||||
return self::$ip = $matches[1];
|
||||
}
|
||||
|
||||
$ip = self::getURL("http://checkmyip.org/");
|
||||
if($ip !== null and preg_match('#Your IP address is ([0-9a-fA-F\:\.]*)#', $ip->getBody(), $matches) > 0){
|
||||
if($ip !== null && preg_match('#Your IP address is ([0-9a-fA-F\:\.]*)#', $ip->getBody(), $matches) > 0){
|
||||
return self::$ip = $matches[1];
|
||||
}
|
||||
|
||||
$ip = self::getURL("http://ifconfig.me/ip");
|
||||
if($ip !== null and ($addr = trim($ip->getBody())) != ""){
|
||||
if($ip !== null && ($addr = trim($ip->getBody())) != ""){
|
||||
return self::$ip = $addr;
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
|
||||
}
|
||||
|
||||
public function debug($message, bool $force = false){
|
||||
if(!$this->logDebug and !$force){
|
||||
if(!$this->logDebug && !$force){
|
||||
return;
|
||||
}
|
||||
$this->send($message, \LogLevel::DEBUG, "DEBUG", TextFormat::GRAY);
|
||||
@ -193,7 +193,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
|
||||
$thread = \Thread::getCurrentThread();
|
||||
if($thread === null){
|
||||
$threadName = $this->mainThreadName . " thread";
|
||||
}elseif($thread instanceof Thread or $thread instanceof Worker){
|
||||
}elseif($thread instanceof Thread || $thread instanceof Worker){
|
||||
$threadName = $thread->getThreadName() . " thread";
|
||||
}else{
|
||||
$threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
|
||||
|
@ -56,7 +56,7 @@ final class Process{
|
||||
$reserved = memory_get_usage();
|
||||
$VmSize = null;
|
||||
$VmRSS = null;
|
||||
if(Utils::getOS() === Utils::OS_LINUX or Utils::getOS() === Utils::OS_ANDROID){
|
||||
if(Utils::getOS() === Utils::OS_LINUX || Utils::getOS() === Utils::OS_ANDROID){
|
||||
$status = @file_get_contents("/proc/self/status");
|
||||
if($status === false) throw new AssumptionFailedError("/proc/self/status should always be accessible");
|
||||
|
||||
@ -94,7 +94,7 @@ final class Process{
|
||||
$stack = 0;
|
||||
$heap = 0;
|
||||
|
||||
if(Utils::getOS() === Utils::OS_LINUX or Utils::getOS() === Utils::OS_ANDROID){
|
||||
if(Utils::getOS() === Utils::OS_LINUX || Utils::getOS() === Utils::OS_ANDROID){
|
||||
$mappings = @file("/proc/self/maps");
|
||||
if($mappings === false) throw new AssumptionFailedError("/proc/self/maps should always be accessible");
|
||||
foreach($mappings as $line){
|
||||
@ -112,7 +112,7 @@ final class Process{
|
||||
}
|
||||
|
||||
public static function getThreadCount() : int{
|
||||
if(Utils::getOS() === Utils::OS_LINUX or Utils::getOS() === Utils::OS_ANDROID){
|
||||
if(Utils::getOS() === Utils::OS_LINUX || Utils::getOS() === Utils::OS_ANDROID){
|
||||
$status = @file_get_contents("/proc/self/status");
|
||||
if($status === false) throw new AssumptionFailedError("/proc/self/status should always be accessible");
|
||||
if(preg_match("/Threads:[ \t]+([0-9]+)/", $status, $matches) > 0){
|
||||
|
@ -74,10 +74,10 @@ abstract class Terminal{
|
||||
$stdout = fopen("php://stdout", "w");
|
||||
if($stdout === false) throw new AssumptionFailedError("Opening php://stdout should never fail");
|
||||
$result = (
|
||||
stream_isatty($stdout) and //STDOUT isn't being piped
|
||||
stream_isatty($stdout) && //STDOUT isn't being piped
|
||||
(
|
||||
getenv('TERM') !== false or //Console says it supports colours
|
||||
(function_exists('sapi_windows_vt100_support') and sapi_windows_vt100_support($stdout)) //we're on windows and have vt100 support
|
||||
getenv('TERM') !== false || //Console says it supports colours
|
||||
(function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support($stdout)) //we're on windows and have vt100 support
|
||||
)
|
||||
);
|
||||
fclose($stdout);
|
||||
|
@ -77,7 +77,7 @@ abstract class Timezone{
|
||||
}
|
||||
}
|
||||
|
||||
if(($timezone = self::detectSystemTimezone()) !== false and date_default_timezone_set($timezone)){
|
||||
if(($timezone = self::detectSystemTimezone()) !== false && date_default_timezone_set($timezone)){
|
||||
//Success! Timezone has already been set and validated in the if statement.
|
||||
//This here is just for redundancy just in case some program wants to read timezone data from the ini.
|
||||
ini_set("date.timezone", $timezone);
|
||||
@ -85,11 +85,11 @@ abstract class Timezone{
|
||||
}
|
||||
|
||||
if(($response = Internet::getURL("http://ip-api.com/json")) !== null //If system timezone detection fails or timezone is an invalid value.
|
||||
and is_array($ip_geolocation_data = json_decode($response->getBody(), true))
|
||||
and isset($ip_geolocation_data['status'])
|
||||
and $ip_geolocation_data['status'] !== 'fail'
|
||||
and is_string($ip_geolocation_data['timezone'])
|
||||
and date_default_timezone_set($ip_geolocation_data['timezone'])
|
||||
&& is_array($ip_geolocation_data = json_decode($response->getBody(), true))
|
||||
&& isset($ip_geolocation_data['status'])
|
||||
&& $ip_geolocation_data['status'] !== 'fail'
|
||||
&& is_string($ip_geolocation_data['timezone'])
|
||||
&& date_default_timezone_set($ip_geolocation_data['timezone'])
|
||||
){
|
||||
//Again, for redundancy.
|
||||
ini_set("date.timezone", $ip_geolocation_data['timezone']);
|
||||
@ -150,7 +150,7 @@ abstract class Timezone{
|
||||
|
||||
// RHEL / CentOS
|
||||
$data = @parse_ini_file('/etc/sysconfig/clock');
|
||||
if($data !== false and isset($data['ZONE']) and is_string($data['ZONE'])){
|
||||
if($data !== false && isset($data['ZONE']) && is_string($data['ZONE'])){
|
||||
return trim($data['ZONE']);
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ abstract class Timezone{
|
||||
return self::parseOffset($offset);
|
||||
case Utils::OS_MACOS:
|
||||
$filename = @readlink('/etc/localtime');
|
||||
if($filename !== false and strpos($filename, '/usr/share/zoneinfo/') === 0){
|
||||
if($filename !== false && strpos($filename, '/usr/share/zoneinfo/') === 0){
|
||||
$timezone = substr($filename, 20);
|
||||
return trim($timezone);
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ final class Utils{
|
||||
* @param string $extra optional, additional data to identify the machine
|
||||
*/
|
||||
public static function getMachineUniqueId(string $extra = "") : UuidInterface{
|
||||
if(self::$serverUniqueId !== null and $extra === ""){
|
||||
if(self::$serverUniqueId !== null && $extra === ""){
|
||||
return self::$serverUniqueId;
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ final class Utils{
|
||||
* Other => other
|
||||
*/
|
||||
public static function getOS(bool $recalculate = false) : string{
|
||||
if(self::$os === null or $recalculate){
|
||||
if(self::$os === null || $recalculate){
|
||||
$uname = php_uname("s");
|
||||
if(stripos($uname, "Darwin") !== false){
|
||||
if(strpos(php_uname("m"), "iP") === 0){
|
||||
@ -273,7 +273,7 @@ final class Utils{
|
||||
}else{
|
||||
self::$os = self::OS_MACOS;
|
||||
}
|
||||
}elseif(stripos($uname, "Win") !== false or $uname === "Msys"){
|
||||
}elseif(stripos($uname, "Win") !== false || $uname === "Msys"){
|
||||
self::$os = self::OS_WINDOWS;
|
||||
}elseif(stripos($uname, "Linux") !== false){
|
||||
if(@file_exists("/system/build.prop")){
|
||||
@ -281,7 +281,7 @@ final class Utils{
|
||||
}else{
|
||||
self::$os = self::OS_LINUX;
|
||||
}
|
||||
}elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){
|
||||
}elseif(stripos($uname, "BSD") !== false || $uname === "DragonFly"){
|
||||
self::$os = self::OS_BSD;
|
||||
}else{
|
||||
self::$os = self::OS_UNKNOWN;
|
||||
@ -294,7 +294,7 @@ final class Utils{
|
||||
public static function getCoreCount(bool $recalculate = false) : int{
|
||||
static $processors = 0;
|
||||
|
||||
if($processors > 0 and !$recalculate){
|
||||
if($processors > 0 && !$recalculate){
|
||||
return $processors;
|
||||
}else{
|
||||
$processors = 0;
|
||||
@ -443,7 +443,7 @@ final class Utils{
|
||||
$messages = [];
|
||||
for($i = 0; isset($trace[$i]); ++$i){
|
||||
$params = "";
|
||||
if(isset($trace[$i]["args"]) or isset($trace[$i]["params"])){
|
||||
if(isset($trace[$i]["args"]) || isset($trace[$i]["params"])){
|
||||
if(isset($trace[$i]["args"])){
|
||||
$args = $trace[$i]["args"];
|
||||
}else{
|
||||
@ -466,7 +466,7 @@ final class Utils{
|
||||
return gettype($value) . " " . Utils::printable((string) $value);
|
||||
}, $args));
|
||||
}
|
||||
$messages[] = "#$i " . (isset($trace[$i]["file"]) ? Filesystem::cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")";
|
||||
$messages[] = "#$i " . (isset($trace[$i]["file"]) ? Filesystem::cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" || $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")";
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class VersionString{
|
||||
$retval = $this->baseVersion;
|
||||
if($this->development){
|
||||
$retval .= "+dev";
|
||||
if($build and $this->build > 0){
|
||||
if($build && $this->build > 0){
|
||||
$retval .= "." . $this->build;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user