Skip to content

Commit

Permalink
add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jun 7, 2024
1 parent 1b1fa88 commit 0243c5a
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 21 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"spatie/laravel-signal-aware-command": "^1.2|^2.0",
"spatie/temporary-directory": "^2.0",
"symfony/console": "^6.0|^7.0",
"symfony/finder": "^6.0|^7.0"
"symfony/finder": "^6.0|^7.0",
"ext-pcntl": "*"
},
"require-dev": {
"ext-pcntl": "*",
"composer-runtime-api": "^2.0",
"larastan/larastan": "^2.7.0",
"laravel/slack-notification-channel": "^2.5|^3.0",
Expand Down
1 change: 1 addition & 0 deletions src/BackupDestination/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function sizeInBytes(): float
return $this->size;
}

/** @return resource */
public function stream()
{
return throw_unless(
Expand Down
2 changes: 2 additions & 0 deletions src/BackupDestination/BackupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Illuminate\Support\Collection;
use Spatie\Backup\Helpers\File;

/** @extends Collection<int,Backup> */
class BackupCollection extends Collection
{
protected ?float $sizeCache = null;

/** @param array<string> $files */
public static function createFromFiles(?FileSystem $disk, array $files): self
{
return (new static($files))
Expand Down
2 changes: 2 additions & 0 deletions src/BackupDestination/BackupDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ public function connectionError(): Exception
return $this->connectionError;
}

/** @return array<string, string> */
public function getDiskOptions(): array
{
ray(config("filesystems.disks.{$this->diskName()}.backup_options") ?? []);
return config("filesystems.disks.{$this->diskName()}.backup_options") ?? [];
}

Expand Down
4 changes: 4 additions & 0 deletions src/BackupDestination/BackupDestinationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

class BackupDestinationFactory
{
/**
* @param array<string, mixed> $config
* @return Collection<int, BackupDestination>
*/
public static function createFromArray(array $config): Collection
{
return collect($config['destination']['disks'])
Expand Down
2 changes: 1 addition & 1 deletion src/BackupServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function packageRegistered(): void
$this->registerDiscordChannel();
}

protected function registerDiscordChannel()
protected function registerDiscordChannel(): void
{
Notification::resolved(function (ChannelManager $service) {
$service->extend('discord', function ($app) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/BackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function handle(): int
}
}

protected function guardAgainstInvalidOptions()
protected function guardAgainstInvalidOptions(): void
{
if (! $this->option('only-db')) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

abstract class BaseCommand extends SignalAwareCommand
{
/** @var array<int> */
protected array $handlesSignals = [];

public function __construct()
Expand All @@ -33,6 +34,7 @@ protected function runningInConsole(): bool
return in_array(PHP_SAPI, ['cli', 'phpdbg']);
}

/** @return array<int> */
public function getSubscribedSignals(): array
{
return $this->handlesSignals;
Expand Down
11 changes: 8 additions & 3 deletions src/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public function handle(): int
return static::SUCCESS;
}

protected function displayOverview(Collection $backupDestinationStatuses)
/**
* @param Collection<int, BackupDestinationStatus> $backupDestinationStatuses
*/
protected function displayOverview(Collection $backupDestinationStatuses): static
{
$headers = ['Name', 'Disk', 'Reachable', 'Healthy', '# of backups', 'Newest backup', 'Used storage'];

Expand All @@ -46,6 +49,7 @@ protected function displayOverview(Collection $backupDestinationStatuses)
return $this;
}

/** @return array{0: string, 1: string, 2: string, disk: string, amount: integer, newest: string, usedStorage: string} */
public function convertToRow(BackupDestinationStatus $backupDestinationStatus): array
{
$destination = $backupDestinationStatus->backupDestination();
Expand Down Expand Up @@ -73,7 +77,8 @@ public function convertToRow(BackupDestinationStatus $backupDestinationStatus):
return $row;
}

protected function displayFailures(Collection $backupDestinationStatuses)
/** @param Collection<int, BackupDestinationStatus> $backupDestinationStatuses */
protected function displayFailures(Collection $backupDestinationStatuses): static
{
$failed = $backupDestinationStatuses
->filter(function (BackupDestinationStatus $backupDestinationStatus) {
Expand All @@ -98,7 +103,7 @@ protected function displayFailures(Collection $backupDestinationStatuses)
return $this;
}

protected function getFormattedBackupDate(?Backup $backup = null)
protected function getFormattedBackupDate(?Backup $backup = null): string
{
return is_null($backup)
? 'No backups present'
Expand Down
8 changes: 5 additions & 3 deletions src/Exceptions/CannotCreateDbDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

class CannotCreateDbDumper extends Exception
{
public static function unsupportedDriver(string $driver): self
public static function unsupportedDriver(string $driver): static
{
$supportedDrivers = collect(config('database.connections'))->keys();
/** @var array<int, string> $supportedDrivers */
$supportedDrivers = config('database.connections');

$formattedSupportedDrivers = $supportedDrivers
$formattedSupportedDrivers = collect($supportedDrivers)
->keys()
->map(fn (string $supportedDriver) => "`{$supportedDriver}`")

Check failure on line 16 in src/Exceptions/CannotCreateDbDumper.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $callback of method Illuminate\Support\Collection<int,int>::map() expects callable(int, int): string, Closure(string): non-falsy-string given.
->join(glue: ', ', finalGlue: ' or ');

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/NotificationCouldNotBeSent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class NotificationCouldNotBeSent extends Exception
{
public static function noNotificationClassForEvent($event): self
public static function noNotificationClassForEvent(object $event): static
{
$eventClass = $event::class;

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function setCommand(Command $command): void
$this->command = $command;
}

public function __call(string $method, array $arguments)
public function __call(string $method, array $arguments): void
{
$consoleOutput = app(static::class);

Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Backup/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function createForManifest(Manifest $manifest, string $pathToZip):
return $zip;
}

protected static function determineNameOfFileInZip(string $pathToFile, string $pathToZip, string $relativePath)
protected static function determineNameOfFileInZip(string $pathToFile, string $pathToZip, string $relativePath): string
{
$fileDirectory = pathinfo($pathToFile, PATHINFO_DIRNAME).DIRECTORY_SEPARATOR;

Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Cleanup/CleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function run(): void
});
}

protected function sendNotification($notification): void
protected function sendNotification(string|object $notification): void
{
if ($this->sendNotifications) {
rescue(
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Cleanup/CleanupStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
) {
}

abstract public function deleteOldBackups(BackupCollection $backups);
abstract public function deleteOldBackups(BackupCollection $backups): void;

public function setBackupDestination(BackupDestination $backupDestination): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Monitor/HealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

abstract class HealthCheck
{
abstract public function checkHealth(BackupDestination $backupDestination);
abstract public function checkHealth(BackupDestination $backupDestination): void;

public function name(): string
{
Expand Down
10 changes: 5 additions & 5 deletions src/Traits/Retryable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait Retryable

protected int $currentTry = 1;

protected function shouldRetry()
protected function shouldRetry(): bool
{
if ($this->tries <= 1) {
return false;
Expand All @@ -19,17 +19,17 @@ protected function shouldRetry()
return $this->currentTry < $this->tries;
}

protected function hasRetryDelay(string $type)
protected function hasRetryDelay(string $type): bool
{
return ! empty($this->getRetryDelay($type));
}

protected function sleepFor(int $seconds = 0)
protected function sleepFor(int $seconds = 0): void
{
Sleep::for($seconds)->seconds();
}

protected function setTries(string $type)
protected function setTries(string $type): void
{
if ($this->option('tries')) {
$this->tries = (int) $this->option('tries');
Expand All @@ -40,7 +40,7 @@ protected function setTries(string $type)
$this->tries = (int) config('backup.'.$type.'.tries', 1);
}

protected function getRetryDelay(string $type)
protected function getRetryDelay(string $type): int
{
return (int) config('backup.'.$type.'.retry_delay', 0);
}
Expand Down

0 comments on commit 0243c5a

Please sign in to comment.