Skip to content

Commit

Permalink
rector fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jun 11, 2024
1 parent 230b7b5 commit 9c91993
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -33,4 +34,5 @@
PostIncDecToPreIncDecRector::class,
NullableCompareToNullRector::class,
AddArrowFunctionReturnTypeRector::class,
AddClosureVoidReturnTypeWhereNoReturnRector::class,
]);
2 changes: 1 addition & 1 deletion src/BackupDestination/BackupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/BackupServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ 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'));
});
}

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();
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/Config/DestinationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Backup/BackupJobFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
);
}
}
12 changes: 5 additions & 7 deletions src/Tasks/Backup/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
4 changes: 2 additions & 2 deletions src/Tasks/Monitor/BackupDestinationStatusFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 = [];
Expand Down

0 comments on commit 9c91993

Please sign in to comment.