From a012e7ccc017ec8a1768b6976ac9685318551613 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Aug 2021 16:37:36 +0100 Subject: [PATCH] VersionInfo: make static methods more constant-like if we could have class constants declared at runtime, these would be constant. --- build/make-release.php | 2 +- src/CrashDump.php | 6 +++--- src/PocketMine.php | 2 +- src/Server.php | 4 ++-- src/VersionInfo.php | 4 ++-- src/command/defaults/VersionCommand.php | 4 ++-- src/network/mcpe/handler/PreSpawnPacketHandler.php | 2 +- src/stats/SendUsageTask.php | 2 +- src/updater/AutoUpdater.php | 2 +- src/utils/Internet.php | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build/make-release.php b/build/make-release.php index ff669f3934..aa31f8097f 100644 --- a/build/make-release.php +++ b/build/make-release.php @@ -60,7 +60,7 @@ function main(array $argv) : void{ if(isset($argv[1])){ $currentVer = new VersionString($argv[1]); }else{ - $currentVer = VersionInfo::getVersionObj(); + $currentVer = VersionInfo::VERSION(); } $nextVer = new VersionString(sprintf( "%u.%u.%u", diff --git a/src/CrashDump.php b/src/CrashDump.php index e6f72de5f7..983ecd4a89 100644 --- a/src/CrashDump.php +++ b/src/CrashDump.php @@ -328,7 +328,7 @@ class CrashDump{ } private function generalData() : void{ - $version = VersionInfo::getVersionObj(); + $version = VersionInfo::VERSION(); $composerLibraries = []; foreach(InstalledVersions::getInstalledPackages() as $package){ $composerLibraries[$package] = sprintf( @@ -344,7 +344,7 @@ class CrashDump{ $this->data["general"]["build"] = VersionInfo::BUILD_NUMBER; $this->data["general"]["is_dev"] = VersionInfo::IS_DEVELOPMENT_BUILD; $this->data["general"]["protocol"] = ProtocolInfo::CURRENT_PROTOCOL; - $this->data["general"]["git"] = VersionInfo::getGitHash(); + $this->data["general"]["git"] = VersionInfo::GIT_HASH(); $this->data["general"]["uname"] = php_uname("a"); $this->data["general"]["php"] = phpversion(); $this->data["general"]["zend"] = zend_version(); @@ -352,7 +352,7 @@ class CrashDump{ $this->data["general"]["os"] = Utils::getOS(); $this->data["general"]["composer_libraries"] = $composerLibraries; $this->addLine($this->server->getName() . " version: " . $version->getFullVersion(true) . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "]"); - $this->addLine("Git commit: " . VersionInfo::getGitHash()); + $this->addLine("Git commit: " . VersionInfo::GIT_HASH()); $this->addLine("uname -a: " . php_uname("a")); $this->addLine("PHP Version: " . phpversion()); $this->addLine("Zend version: " . zend_version()); diff --git a/src/PocketMine.php b/src/PocketMine.php index c96cd8060d..f345cacf95 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -229,7 +229,7 @@ JIT_WARNING $composerGitHash = InstalledVersions::getReference('pocketmine/pocketmine-mp'); if($composerGitHash !== null){ //we can't verify dependency versions if we were installed without using git - $currentGitHash = explode("-", VersionInfo::getGitHash())[0]; + $currentGitHash = explode("-", VersionInfo::GIT_HASH())[0]; if($currentGitHash !== $composerGitHash){ critical_error("Composer dependencies and/or autoloader are out of sync."); critical_error("- Current revision is $currentGitHash"); diff --git a/src/Server.php b/src/Server.php index 6f243532a6..d290ebdaa3 100644 --- a/src/Server.php +++ b/src/Server.php @@ -260,7 +260,7 @@ class Server{ } public function getPocketMineVersion() : string{ - return VersionInfo::getVersionObj()->getFullVersion(true); + return VersionInfo::VERSION()->getFullVersion(true); } public function getVersion() : string{ @@ -1452,7 +1452,7 @@ class Server{ $report = false; } - if(strrpos(VersionInfo::getGitHash(), "-dirty") !== false or VersionInfo::getGitHash() === str_repeat("00", 20)){ + if(strrpos(VersionInfo::GIT_HASH(), "-dirty") !== false or VersionInfo::GIT_HASH() === str_repeat("00", 20)){ $this->logger->debug("Not sending crashdump due to locally modified"); $report = false; //Don't send crashdumps for locally modified builds } diff --git a/src/VersionInfo.php b/src/VersionInfo.php index e4daaf30f1..3b74e3708e 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -40,7 +40,7 @@ final class VersionInfo{ /** @var string|null */ private static $gitHash = null; - public static function getGitHash() : string{ + public static function GIT_HASH() : string{ if(self::$gitHash === null){ $gitHash = str_repeat("00", 20); @@ -63,7 +63,7 @@ final class VersionInfo{ /** @var VersionString|null */ private static $fullVersion = null; - public static function getVersionObj() : VersionString{ + public static function VERSION() : VersionString{ if(self::$fullVersion === null){ self::$fullVersion = new VersionString(self::BASE_VERSION, self::IS_DEVELOPMENT_BUILD, self::BUILD_NUMBER); } diff --git a/src/command/defaults/VersionCommand.php b/src/command/defaults/VersionCommand.php index daecc625f0..17e4c858ca 100644 --- a/src/command/defaults/VersionCommand.php +++ b/src/command/defaults/VersionCommand.php @@ -63,8 +63,8 @@ class VersionCommand extends VanillaCommand{ VersionInfo::NAME )); $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_serverSoftwareVersion( - VersionInfo::getVersionObj()->getFullVersion(), - VersionInfo::getGitHash() + VersionInfo::VERSION()->getFullVersion(), + VersionInfo::GIT_HASH() )); $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_minecraftVersion( ProtocolInfo::MINECRAFT_VERSION_NETWORK, diff --git a/src/network/mcpe/handler/PreSpawnPacketHandler.php b/src/network/mcpe/handler/PreSpawnPacketHandler.php index 82996ac66a..59d204d68f 100644 --- a/src/network/mcpe/handler/PreSpawnPacketHandler.php +++ b/src/network/mcpe/handler/PreSpawnPacketHandler.php @@ -95,7 +95,7 @@ class PreSpawnPacketHandler extends PacketHandler{ $pk->worldName = $this->server->getMotd(); $pk->itemTable = GlobalItemTypeDictionary::getInstance()->getDictionary()->getEntries(); //TODO: check if this is actually needed $pk->playerMovementSettings = new PlayerMovementSettings(PlayerMovementType::LEGACY, 0, false); - $pk->serverSoftwareVersion = sprintf("%s %s", VersionInfo::NAME, VersionInfo::getVersionObj()->getFullVersion(true)); + $pk->serverSoftwareVersion = sprintf("%s %s", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true)); $this->session->sendDataPacket($pk); $this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers()); diff --git a/src/stats/SendUsageTask.php b/src/stats/SendUsageTask.php index 7516797326..d108ca94a7 100644 --- a/src/stats/SendUsageTask.php +++ b/src/stats/SendUsageTask.php @@ -71,7 +71,7 @@ class SendUsageTask extends AsyncTask{ case self::TYPE_OPEN: $data["event"] = "open"; - $version = VersionInfo::getVersionObj(); + $version = VersionInfo::VERSION(); $data["server"] = [ "port" => $server->getPort(), diff --git a/src/updater/AutoUpdater.php b/src/updater/AutoUpdater.php index b20db07671..61b2aa7a3c 100644 --- a/src/updater/AutoUpdater.php +++ b/src/updater/AutoUpdater.php @@ -150,7 +150,7 @@ class AutoUpdater{ if($this->updateInfo === null){ return; } - $currentVersion = VersionInfo::getVersionObj(); + $currentVersion = VersionInfo::VERSION(); try{ $newVersion = new VersionString($this->updateInfo->base_version, $this->updateInfo->is_dev, $this->updateInfo->build); }catch(\InvalidArgumentException $e){ diff --git a/src/utils/Internet.php b/src/utils/Internet.php index d7f602cb6e..36dc96fc24 100644 --- a/src/utils/Internet.php +++ b/src/utils/Internet.php @@ -209,7 +209,7 @@ class Internet{ CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT_MS => (int) ($timeout * 1000), CURLOPT_TIMEOUT_MS => (int) ($timeout * 1000), - CURLOPT_HTTPHEADER => array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 " . VersionInfo::NAME . "/" . VersionInfo::getVersionObj()->getFullVersion(true)], $extraHeaders), + CURLOPT_HTTPHEADER => array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 " . VersionInfo::NAME . "/" . VersionInfo::VERSION()->getFullVersion(true)], $extraHeaders), CURLOPT_HEADER => true ]); try{