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', -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php