refactor: Simplify writeJsonFile method and adjust forceCheck logic in ReplaceKey

* Removed appending functionality from writeJsonFile for cleaner implementation.
* Inverted condition for forceCheck to improve logic clarity.
This commit is contained in:
Zack Spear
2025-03-20 12:31:04 -07:00
parent bd640b1f62
commit 80869a032c

View File

@@ -147,17 +147,12 @@ class ReplaceKey
$KeyInstaller->installKey($key);
}
private function writeJsonFile($file, $data, $append = false)
private function writeJsonFile($file, $data)
{
if (!is_dir(dirname($file))) {
mkdir(dirname($file));
}
if ($append && file_exists($file)) {
$existing = json_decode(file_get_contents($file), true) ?: [];
$data = array_merge_recursive($existing, $data);
}
file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
@@ -175,7 +170,7 @@ class ReplaceKey
$isWithinWindow = ($now >= $sevenDaysBefore && $now <= $sevenDaysAfter);
if ($forceCheck || $isWithinWindow) {
if (!$forceCheck && !$isWithinWindow) {
return;
}
@@ -195,8 +190,7 @@ class ReplaceKey
[
'error' => 'Failed to retrieve latest key after getting a `hasNewerKeyfile` in the validation response.',
'ts' => time(),
],
true,
]
);
return;
}