Refactor CheckUpdateResult logic to simplify version comparison

This commit is contained in:
crazywhalecc 2026-03-05 11:11:02 +08:00
parent 5298ee4f97
commit abdaaab6e6
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
5 changed files with 8 additions and 5 deletions

View File

@ -72,6 +72,9 @@ class zig
$index_json = default_shell()->executeCurl('https://ziglang.org/download/index.json', retries: $downloader->getRetry());
$index_json = json_decode($index_json ?: '', true);
$latest_version = null;
if (!is_array($index_json)) {
throw new DownloaderException('Failed to fetch Zig version index for update check');
}
foreach ($index_json as $version => $data) {
if ($version !== 'master') {
$latest_version = $version;
@ -84,7 +87,7 @@ class zig
return new CheckUpdateResult(
old: $old_version,
new: $latest_version,
needUpdate: $old_version === null || version_compare($latest_version, $old_version, '>'),
needUpdate: $old_version === null || $latest_version !== $old_version,
);
}

View File

@ -32,7 +32,7 @@ class FileList implements DownloadTypeInterface, CheckUpdateInterface
return new CheckUpdateResult(
old: $old_version,
new: $version,
needUpdate: $old_version === null || version_compare($version, $old_version, '>'),
needUpdate: $old_version === null || $version !== $old_version,
);
}

View File

@ -120,7 +120,7 @@ class Git implements DownloadTypeInterface, CheckUpdateInterface
return new CheckUpdateResult(
old: $old_version,
new: $version,
needUpdate: $old_version === null || version_compare($version, $old_version, '>'),
needUpdate: $old_version === null || $version !== $old_version,
);
}
throw new DownloaderException("No matching branch found for regex {$config['regex']}.");

View File

@ -22,7 +22,7 @@ class PECL implements DownloadTypeInterface, CheckUpdateInterface
return new CheckUpdateResult(
old: $old_version,
new: $version,
needUpdate: $old_version === null || version_compare($version, $old_version, '>'),
needUpdate: $old_version === null || $version !== $old_version,
);
}

View File

@ -40,7 +40,7 @@ class PIE implements DownloadTypeInterface, CheckUpdateInterface
return new CheckUpdateResult(
old: $old_version,
new: $new_version,
needUpdate: $old_version === null || version_compare($new_version, $old_version, '>'),
needUpdate: $old_version === null || $new_version !== $old_version,
);
}