Skip to content

Commit

Permalink
return Command constant instead of integer
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbonnick authored and freekmurze committed Aug 28, 2023
1 parent f4a2abc commit c084f22
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/Commands/BackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BackupCommand extends BaseCommand

protected $description = 'Run the backup.';

public function handle()
public function handle(): int
{
consoleOutput()->comment($this->currentTry > 1 ? sprintf('Attempt n°%d...', $this->currentTry) : 'Starting backup...');

Expand Down Expand Up @@ -63,6 +63,8 @@ public function handle()
$backupJob->run();

consoleOutput()->comment('Backup completed!');

return static::SUCCESS;
} catch (Exception $exception) {
if ($this->shouldRetry()) {
if ($this->hasRetryDelay('backup')) {
Expand All @@ -82,7 +84,7 @@ public function handle()
event(new BackupHasFailed($exception));
}

return 1;
return static::FAILURE;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Commands/CleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(CleanupStrategy $strategy)
$this->strategy = $strategy;
}

public function handle()
public function handle(): int
{
consoleOutput()->comment($this->currentTry > 1 ? sprintf('Attempt n°%d...', $this->currentTry) : 'Starting cleanup...');

Expand All @@ -46,6 +46,8 @@ public function handle()
$cleanupJob->run();

consoleOutput()->comment('Cleanup completed!');

return static::SUCCESS;
} catch (Exception $exception) {
if ($this->shouldRetry()) {
if ($this->hasRetryDelay('cleanup')) {
Expand All @@ -61,7 +63,7 @@ public function handle()
event(new CleanupHasFailed($exception));
}

return 1;
return static::FAILURE;
}
}
}
4 changes: 3 additions & 1 deletion src/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ListCommand extends BaseCommand
/** @var string */
protected $description = 'Display a list of all backups.';

public function handle()
public function handle(): int
{
if (config()->has('backup.monitorBackups')) {
$this->warn("Warning! Your config file still uses the old monitorBackups key. Update it to monitor_backups.");
Expand All @@ -26,6 +26,8 @@ public function handle()
$statuses = BackupDestinationStatusFactory::createForMonitorConfig(config('backup.monitor_backups'));

$this->displayOverview($statuses)->displayFailures($statuses);

return static::SUCCESS;
}

protected function displayOverview(Collection $backupDestinationStatuses)
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/MonitorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MonitorCommand extends BaseCommand
/** @var string */
protected $description = 'Monitor the health of all backups.';

public function handle()
public function handle(): int
{
if (config()->has('backup.monitorBackups')) {
$this->warn("Warning! Your config file still uses the old monitorBackups key. Update it to monitor_backups.");
Expand All @@ -39,7 +39,9 @@ public function handle()
}

if ($hasError) {
return 1;
return static::FAILURE;
}

return static::SUCCESS;
}
}

0 comments on commit c084f22

Please sign in to comment.