[web-php] master: Refactor compare_version function (#568)
| From: | Kamil Tekiela via GitHub | Date: | Tue, 28 Jun 2022 10:36:38 +0000 |
| Subject: | [web-php] master: Refactor compare_version function (#568) | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-30142@lists.php.net to get a copy of this message | ||
Author: Kamil Tekiela (kamil-tekiela)
Committer: GitHub (web-flow)
Pusher: kamil-tekiela
Date: 2022-06-28T11:30:39+01:00
Commit: https://github.com/php/web-php/commit/fa3391b9dc4545001dd7e74579c231efeaeb5797
Raw diff: https://github.com/php/web-php/commit/fa3391b9dc4545001dd7e74579c231efeaeb5797.diff
Refactor compare_version function (#568)
Changed paths:
M include/branches.inc
Diff:
diff --git a/include/branches.inc b/include/branches.inc
index cca5b8575..52d96ca3d 100644
--- a/include/branches.inc
+++ b/include/branches.inc
@@ -339,32 +339,22 @@ function get_branch_support_state($branch) {
return null;
}
-function compare_version($arrayA, $versionB)
+function compare_version(array $arrayA, string $versionB)
{
- static $sortValues = array(
- true => 1,
- false => -1,
- );
-
- $length = count($arrayA);
- $arrayB = version_array($versionB, $length);
-
- if (!is_array($arrayA) || !is_array($arrayB)) {
- return $sortValues[$arrayA > $arrayB];
- }
+ $arrayB = version_array($versionB, count($arrayA));
foreach ($arrayA as $index => $componentA) {
$componentA = $arrayA[$index];
$componentB = $arrayB[$index];
if ($componentA != $componentB) {
- return $sortValues[$componentA > $componentB];
+ return $componentA > $componentB ? 1 : -1;
}
}
return 0;
}
-function version_array($version, $length = null)
+function version_array(string $version, ?int $length = null)
{
$versionArray = array_map(
'intval',