Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jan 23, 2024
2 parents e08c8f9 + 084523d commit 75c8a2e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
18 changes: 7 additions & 11 deletions src/Checks/Checks/BackupsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BackupsCheck extends Check
protected ?string $locatedAt = null;

protected ?Carbon $youngestShouldHaveBeenMadeBefore = null;

protected ?Carbon $oldestShouldHaveBeenMadeAfter = null;

protected int $minimumSizeInMegabytes = 0;
Expand Down Expand Up @@ -93,31 +94,28 @@ public function run(): Result
if ($this->youngestShouldHaveBeenMadeBefore) {
if ($this->youngestBackupIsToolOld($eligableBackups)) {
return Result::make()
->failed("Youngest backup was too old");
->failed('Youngest backup was too old');
}
}

if ($this->oldestShouldHaveBeenMadeAfter) {
if ($this->oldestBackupIsTooYoung($eligableBackups)) {
return Result::make()
->failed("Oldest backup was too young");
->failed('Oldest backup was too young');
}
}

return Result::make()->ok();
}


/**
* @param Collection<SymfonyFile> $backups
*
* @return bool
* @param Collection<SymfonyFile> $backups
*/
protected function youngestBackupIsToolOld(Collection $backups): bool
{
/** @var SymfonyFile|null $youngestBackup */
$youngestBackup = $backups
->sortByDesc(fn(SymfonyFile $file) => $file->getMTime())
->sortByDesc(fn (SymfonyFile $file) => $file->getMTime())
->first();

$threshold = $this->youngestShouldHaveBeenMadeBefore->getTimestamp();
Expand All @@ -126,15 +124,13 @@ protected function youngestBackupIsToolOld(Collection $backups): bool
}

/**
* @param Collection<SymfonyFile> $backups
*
* @return bool
* @param Collection<SymfonyFile> $backups
*/
protected function oldestBackupIsTooYoung(Collection $backups): bool
{
/** @var SymfonyFile|null $oldestBackup */
$oldestBackup = $backups
->sortBy(fn(SymfonyFile $file) => $file->getMTime())
->sortBy(fn (SymfonyFile $file) => $file->getMTime())
->first();

$threshold = $this->oldestShouldHaveBeenMadeAfter->getTimestamp();
Expand Down
1 change: 0 additions & 1 deletion tests/Checks/DatabaseCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Spatie\Health\Checks\Checks\DatabaseCheck;
use Spatie\Health\Enums\Status;
use function Spatie\PestPluginTestTime\testTime;

it('will determine that a working database connection is ok', function () {
$result = DatabaseCheck::new()
Expand Down
2 changes: 1 addition & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getTemporaryDirectory(string $path = ''): string
return __DIR__."/temp/{$path}";
}

function addTestFile(string $path, Carbon $date = null, int $sizeInMb = null): void
function addTestFile(string $path, ?Carbon $date = null, ?int $sizeInMb = null): void
{
$date = $date ?? now();

Expand Down

0 comments on commit 75c8a2e

Please sign in to comment.