diff --git a/rector.php b/rector.php index a81f8384..836677e8 100644 --- a/rector.php +++ b/rector.php @@ -15,6 +15,7 @@ use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; +use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector; return RectorConfig::configure() ->withPaths(['config', 'resources', 'src']) @@ -33,4 +34,5 @@ PostIncDecToPreIncDecRector::class, NullableCompareToNullRector::class, AddArrowFunctionReturnTypeRector::class, + AddClosureVoidReturnTypeWhereNoReturnRector::class, ]); diff --git a/src/BackupDestination/BackupCollection.php b/src/BackupDestination/BackupCollection.php index dc998fdf..b3564010 100644 --- a/src/BackupDestination/BackupCollection.php +++ b/src/BackupDestination/BackupCollection.php @@ -16,7 +16,7 @@ public static function createFromFiles(?FileSystem $disk, array $files): self { return (new static($files)) ->filter(fn (string $path) => (new File())->isZipFile($disk, $path)) - ->map(fn (string $path) => new Backup($disk, $path)) + ->map(fn (string $path): \Spatie\Backup\BackupDestination\Backup => new Backup($disk, $path)) ->sortByDesc(fn (Backup $backup) => $backup->date()->timestamp) ->values(); } diff --git a/src/BackupServiceProvider.php b/src/BackupServiceProvider.php index bf1559e3..92e10d75 100644 --- a/src/BackupServiceProvider.php +++ b/src/BackupServiceProvider.php @@ -52,7 +52,7 @@ public function packageRegistered(): void $this->registerDiscordChannel(); - $this->app->scoped(Config::class, function () { + $this->app->scoped(Config::class, function (): \Spatie\Backup\Config\Config { return Config::fromArray(config('backup')); }); } @@ -60,7 +60,7 @@ public function packageRegistered(): void protected function registerDiscordChannel(): void { Notification::resolved(function (ChannelManager $service) { - $service->extend('discord', function ($app) { + $service->extend('discord', function ($app): \Spatie\Backup\Notifications\Channels\Discord\DiscordChannel { return new DiscordChannel(); }); }); diff --git a/src/Commands/ListCommand.php b/src/Commands/ListCommand.php index ac024e50..7e226eeb 100644 --- a/src/Commands/ListCommand.php +++ b/src/Commands/ListCommand.php @@ -39,7 +39,7 @@ protected function displayOverview(Collection $backupDestinationStatuses): stati { $headers = ['Name', 'Disk', 'Reachable', 'Healthy', '# of backups', 'Newest backup', 'Used storage']; - $rows = $backupDestinationStatuses->map(function (BackupDestinationStatus $backupDestinationStatus) { + $rows = $backupDestinationStatuses->map(function (BackupDestinationStatus $backupDestinationStatus): array { return $this->convertToRow($backupDestinationStatus); }); @@ -83,10 +83,10 @@ public function convertToRow(BackupDestinationStatus $backupDestinationStatus): protected function displayFailures(Collection $backupDestinationStatuses): static { $failed = $backupDestinationStatuses - ->filter(function (BackupDestinationStatus $backupDestinationStatus) { + ->filter(function (BackupDestinationStatus $backupDestinationStatus): bool { return $backupDestinationStatus->getHealthCheckFailure() !== null; }) - ->map(function (BackupDestinationStatus $backupDestinationStatus) { + ->map(function (BackupDestinationStatus $backupDestinationStatus): array { return [ $backupDestinationStatus->backupDestination()->backupName(), $backupDestinationStatus->backupDestination()->diskName(), diff --git a/src/Config/Config.php b/src/Config/Config.php index b3667476..e99baa30 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -17,7 +17,7 @@ protected function __construct( /** @internal used for testing */ public static function rebind(): void { - app()->scoped(Config::class, function () { + app()->scoped(Config::class, function (): \Spatie\Backup\Config\Config { return self::fromArray(config('backup')); }); } diff --git a/src/Config/DestinationConfig.php b/src/Config/DestinationConfig.php index e983edff..9894f727 100644 --- a/src/Config/DestinationConfig.php +++ b/src/Config/DestinationConfig.php @@ -17,7 +17,11 @@ protected function __construct( public string $filenamePrefix, public array $disks, ) { - if ($compressionLevel > 9 || $compressionLevel < 0) { + if ($compressionLevel > 9) { + throw InvalidConfig::integerMustBeBetween('compression_level', 0, 9); + } + + if ($compressionLevel < 0) { throw InvalidConfig::integerMustBeBetween('compression_level', 0, 9); } } diff --git a/src/Tasks/Backup/BackupJob.php b/src/Tasks/Backup/BackupJob.php index ad702f87..ad3c0453 100644 --- a/src/Tasks/Backup/BackupJob.php +++ b/src/Tasks/Backup/BackupJob.php @@ -254,7 +254,7 @@ protected function createZipContainingEveryFileInManifest(Manifest $manifest): s protected function dumpDatabases(): array { return $this->dbDumpers - ->map(function (DbDumper $dbDumper, $key) { + ->map(function (DbDumper $dbDumper, string $key): string { consoleOutput()->info("Dumping database {$dbDumper->getDbName()}..."); $dbType = mb_strtolower(basename(str_replace('\\', '/', $dbDumper::class))); diff --git a/src/Tasks/Backup/BackupJobFactory.php b/src/Tasks/Backup/BackupJobFactory.php index 67e98355..a047f6e0 100644 --- a/src/Tasks/Backup/BackupJobFactory.php +++ b/src/Tasks/Backup/BackupJobFactory.php @@ -33,7 +33,7 @@ protected static function createFileSelection(SourceFilesConfig $sourceFiles): F protected static function createDbDumpers(array $dbConnectionNames): Collection { return collect($dbConnectionNames)->mapWithKeys( - fn (string $dbConnectionName) => [$dbConnectionName => DbDumperFactory::createFromConnection($dbConnectionName)] + fn (string $dbConnectionName): array => [$dbConnectionName => DbDumperFactory::createFromConnection($dbConnectionName)] ); } } diff --git a/src/Tasks/Backup/Zip.php b/src/Tasks/Backup/Zip.php index 3fd66167..41181481 100644 --- a/src/Tasks/Backup/Zip.php +++ b/src/Tasks/Backup/Zip.php @@ -111,13 +111,11 @@ public function add(string|iterable $files, ?string $nameInZip = null): self if (is_file($file)) { $this->zipFile->addFile($file, ltrim((string) $nameInZip, DIRECTORY_SEPARATOR)); - if (is_int($compressionMethod)) { - $this->zipFile->setCompressionName( - ltrim($nameInZip ?: $file, DIRECTORY_SEPARATOR), - $compressionMethod, - $compressionLevel - ); - } + $this->zipFile->setCompressionName( + ltrim($nameInZip ?: $file, DIRECTORY_SEPARATOR), + $compressionMethod, + $compressionLevel + ); } $this->fileCount++; diff --git a/src/Tasks/Monitor/BackupDestinationStatusFactory.php b/src/Tasks/Monitor/BackupDestinationStatusFactory.php index 46e47cc0..42c0c6ec 100644 --- a/src/Tasks/Monitor/BackupDestinationStatusFactory.php +++ b/src/Tasks/Monitor/BackupDestinationStatusFactory.php @@ -26,7 +26,7 @@ public static function createForMonitorConfig(MonitoredBackupsConfig $monitorCon public static function createForSingleMonitor(array $monitorConfig): Collection { return collect($monitorConfig['disks']) - ->map(function ($diskName) use ($monitorConfig) { + ->map(function ($diskName) use ($monitorConfig): \Spatie\Backup\Tasks\Monitor\BackupDestinationStatus { $backupDestination = BackupDestination::create($diskName, $monitorConfig['name']); return new BackupDestinationStatus($backupDestination, static::buildHealthChecks($monitorConfig)); @@ -40,7 +40,7 @@ public static function createForSingleMonitor(array $monitorConfig): Collection protected static function buildHealthChecks(array $monitorConfig): array { return collect($monitorConfig['healthChecks']) - ->map(function ($options, $class) { + ->map(function ($options, $class): \Spatie\Backup\Tasks\Monitor\HealthCheck { if (is_int($class)) { $class = $options; $options = [];