From 2e1ae5b2282b8cd49fe4423bdd8a205b864c30a7 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Tue, 5 Mar 2024 19:42:36 +0000 Subject: [PATCH 1/3] Rewrote getOpenMageVersion() to be faster --- app/Mage.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/Mage.php b/app/Mage.php index 65419780fd1..98ba91c20b3 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -176,25 +176,24 @@ public static function getVersionInfo() * Gets the current OpenMage version string * @link https://openmage.github.io/supported-versions.html * @link https://semver.org/ - * - * @return string */ public static function getOpenMageVersion(): string { $info = self::getOpenMageVersionInfo(); $versionString = "{$info['major']}.{$info['minor']}.{$info['patch']}"; - if ($info['stability'] || $info['number']) { + $stability = $info['stability']; + $number = $info['number']; + + if ($stability || $number) { $versionString .= '-'; - if ($info['stability'] && $info['number']) { - $versionString .= implode('.', [$info['stability'], $info['number']]); + if ($stability && $number) { + $versionString .= "{$stability}.{$number}"; } else { - $versionString .= implode('', [$info['stability'], $info['number']]); + $versionString .= $stability . $number; } } - return trim( - $versionString, - '.-' - ); + + return trim($versionString, '.-'); } /** From 645b5084aee6cd267e8b0d3af61575d737336c84 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 6 Mar 2024 09:26:54 +0000 Subject: [PATCH 2/3] rtrim instead of trim --- app/Mage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Mage.php b/app/Mage.php index 98ba91c20b3..1bcd40d1a67 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -193,7 +193,7 @@ public static function getOpenMageVersion(): string } } - return trim($versionString, '.-'); + return rtrim($versionString, '.-'); } /** From 607d0f9adafbcaa5cfb4c1dbf7291aa50139ca00 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 6 Mar 2024 10:21:15 +0000 Subject: [PATCH 3/3] Rewrote getOpenMageVersion() to be faster --- app/Mage.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/Mage.php b/app/Mage.php index 1bcd40d1a67..e4ff5ebe541 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -181,19 +181,18 @@ public static function getOpenMageVersion(): string { $info = self::getOpenMageVersionInfo(); $versionString = "{$info['major']}.{$info['minor']}.{$info['patch']}"; - $stability = $info['stability']; - $number = $info['number']; - if ($stability || $number) { - $versionString .= '-'; - if ($stability && $number) { - $versionString .= "{$stability}.{$number}"; - } else { - $versionString .= $stability . $number; - } + if ($info['stability'] && $info['number']) { + return "{$versionString}-{$info['stability']}.{$info['number']}"; + } + if ($info['stability']) { + return "{$versionString}-{$info['stability']}"; + } + if ($info['number']) { + return "{$versionString}-{$info['number']}"; } - return rtrim($versionString, '.-'); + return $versionString; } /**