diff --git a/src/utils/Config.php b/src/utils/Config.php index 78bd4c955..f15bfe1e5 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -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]); diff --git a/src/utils/Filesystem.php b/src/utils/Filesystem.php index 9545bad1a..56d45790e 100644 --- a/src/utils/Filesystem.php +++ b/src/utils/Filesystem.php @@ -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); diff --git a/src/utils/Git.php b/src/utils/Git.php index dd83eb033..65142330b 100644 --- a/src/utils/Git.php +++ b/src/utils/Git.php @@ -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; diff --git a/src/utils/Internet.php b/src/utils/Internet.php index 329457b26..ff0c3ca21 100644 --- a/src/utils/Internet.php +++ b/src/utils/Internet.php @@ -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\:\.]*)#', $ip->getBody(), $matches) > 0){ + if($ip !== null && preg_match('#">([0-9a-fA-F\:\.]*)#', $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; } diff --git a/src/utils/MainLogger.php b/src/utils/MainLogger.php index c7290f0d2..415f59b2c 100644 --- a/src/utils/MainLogger.php +++ b/src/utils/MainLogger.php @@ -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"; diff --git a/src/utils/Process.php b/src/utils/Process.php index 8e93f9b1c..503bba7c5 100644 --- a/src/utils/Process.php +++ b/src/utils/Process.php @@ -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){ diff --git a/src/utils/Terminal.php b/src/utils/Terminal.php index 46aeaccae..955abc660 100644 --- a/src/utils/Terminal.php +++ b/src/utils/Terminal.php @@ -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); diff --git a/src/utils/Timezone.php b/src/utils/Timezone.php index 79884751a..95358e704 100644 --- a/src/utils/Timezone.php +++ b/src/utils/Timezone.php @@ -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); } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index d3f4ae1a4..0b772ae64 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -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; } diff --git a/src/utils/VersionString.php b/src/utils/VersionString.php index 095be3c2c..0b2aed47a 100644 --- a/src/utils/VersionString.php +++ b/src/utils/VersionString.php @@ -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; } }