Skip to content

Commit

Permalink
Merge pull request #1805 from spatie/feature/use-config-object
Browse files Browse the repository at this point in the history
Feature/use config object
  • Loading branch information
Nielsvanpach authored Jun 28, 2024
2 parents ad228bd + a4eb33a commit 7132981
Show file tree
Hide file tree
Showing 35 changed files with 36 additions and 70 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"test": "vendor/bin/pest --compact",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"analyse": "vendor/bin/phpstan analyse",
"rector": "./vendor/bin/rector --dry-run",
"rector": "vendor/bin/rector --dry-run",
"baseline": "./vendor/bin/phpstan analyse --generate-baseline --memory-limit=2G"
},
"suggest": {
Expand Down
4 changes: 1 addition & 3 deletions src/BackupDestination/BackupDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class BackupDestination

protected ?BackupCollection $backupCollectionCache = null;

public function __construct(protected ?Filesystem $disk, protected string $backupName, protected string $diskName)
{
}
public function __construct(protected ?Filesystem $disk, protected string $backupName, protected string $diskName) {}

public function disk(): Filesystem
{
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 (): \Spatie\Backup\Config\Config {
$this->app->scoped(Config::class, function (): Config {
return Config::fromArray(config('backup'));
});
}

protected function registerDiscordChannel(): void
{
Notification::resolved(function (ChannelManager $service) {
$service->extend('discord', function ($app): \Spatie\Backup\Notifications\Channels\Discord\DiscordChannel {
$service->extend('discord', function ($app): DiscordChannel {
return new DiscordChannel();
});
});
Expand Down
3 changes: 1 addition & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ protected function __construct(
public NotificationsConfig $notifications,
public MonitoredBackupsConfig $monitoredBackups,
public CleanupConfig $cleanup,
) {
}
) {}

/** @internal used for testing */
public static function rebind(): void
Expand Down
3 changes: 1 addition & 2 deletions src/Config/MonitoredBackupConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ protected function __construct(
public string $name,
public array $disks,
public array $healthChecks,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Config/MonitoredBackupsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class MonitoredBackupsConfig extends Data
*/
protected function __construct(
public array $monitorBackups,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Config/NotificationDiscordConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ protected function __construct(
public string $webhookUrl,
public string $username,
public string $avatar_url,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Config/NotificationMailConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class NotificationMailConfig extends Data
protected function __construct(
public string $to,
public NotificationMailSenderConfig $from,
) {
}
) {}

/**
* @param array<mixed> $data
Expand Down
3 changes: 1 addition & 2 deletions src/Config/NotificationMailSenderConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class NotificationMailSenderConfig extends Data
protected function __construct(
public string $address,
public ?string $name,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Config/NotificationSlackConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ protected function __construct(
public ?string $channel,
public ?string $username,
public ?string $icon,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Config/SourceConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class SourceConfig extends Data
protected function __construct(
public SourceFilesConfig $files,
public array $databases,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Config/SourceFilesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ protected function __construct(
public bool $followLinks,
public bool $ignoreUnreadableDirectories,
public ?string $relativePath,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Config/StrategyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ protected function __construct(
public int $keepMonthlyBackupsForMonths,
public int $keepYearlyBackupsForYears,
public int $deleteOldestBackupsWhenUsingMoreMegabytesThan,
) {
}
) {}

/** @param array<mixed> $data */
public static function fromArray(array $data): self
Expand Down
3 changes: 1 addition & 2 deletions src/Events/BackupHasFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class BackupHasFailed
public function __construct(
public Exception $exception,
public ?BackupDestination $backupDestination = null,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/BackupManifestWasCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class BackupManifestWasCreated
{
public function __construct(
public Manifest $manifest,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/BackupWasSuccessful.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class BackupWasSuccessful
{
public function __construct(
public BackupDestination $backupDestination,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/BackupZipWasCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ class BackupZipWasCreated
{
public function __construct(
public string $pathToZip,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/CleanupHasFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class CleanupHasFailed
public function __construct(
public Exception $exception,
public ?BackupDestination $backupDestination = null,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/CleanupWasSuccessful.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class CleanupWasSuccessful
{
public function __construct(
public BackupDestination $backupDestination,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/DumpingDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class DumpingDatabase
{
public function __construct(
public DbDumper $dbDumper
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/HealthyBackupWasFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class HealthyBackupWasFound
{
public function __construct(
public BackupDestinationStatus $backupDestinationStatus,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Events/UnhealthyBackupWasFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class UnhealthyBackupWasFound
{
public function __construct(
public BackupDestinationStatus $backupDestinationStatus
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Notifications/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class EventHandler
{
public function __construct(
protected Repository $config
) {
}
) {}

public function subscribe(Dispatcher $events): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class BackupHasFailedNotification extends BaseNotification
{
public function __construct(
public BackupHasFailed $event,
) {
}
) {}

public function toMail(): MailMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class BackupWasSuccessfulNotification extends BaseNotification
{
public function __construct(
public BackupWasSuccessful $event,
) {
}
) {}

public function toMail(): MailMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class CleanupHasFailedNotification extends BaseNotification
{
public function __construct(
public CleanupHasFailed $event,
) {
}
) {}

public function toMail(): MailMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class CleanupWasSuccessfulNotification extends BaseNotification
{
public function __construct(
public CleanupWasSuccessful $event,
) {
}
) {}

public function toMail(): MailMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class HealthyBackupWasFoundNotification extends BaseNotification
{
public function __construct(
public HealthyBackupWasFound $event,
) {
}
) {}

public function toMail(): MailMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class UnhealthyBackupWasFoundNotification extends BaseNotification
{
public function __construct(
public UnhealthyBackupWasFound $event,
) {
}
) {}

public function toMail(): MailMessage
{
Expand Down
3 changes: 1 addition & 2 deletions src/Tasks/Cleanup/CleanupStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ abstract class CleanupStrategy

public function __construct(
protected Repository $config,
) {
}
) {}

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

Expand Down
3 changes: 1 addition & 2 deletions src/Tasks/Cleanup/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Period
public function __construct(
protected Carbon $startDate,
protected Carbon $endDate
) {
}
) {}

public function startDate(): Carbon
{
Expand Down
3 changes: 1 addition & 2 deletions src/Tasks/Monitor/BackupDestinationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class BackupDestinationStatus
public function __construct(
protected BackupDestination $backupDestination,
protected array $healthChecks = []
) {
}
) {}

public function backupDestination(): BackupDestination
{
Expand Down
3 changes: 1 addition & 2 deletions src/Tasks/Monitor/HealthCheckFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class HealthCheckFailure
public function __construct(
protected HealthCheck $healthCheck,
protected Exception $exception
) {
}
) {}

public function healthCheck(): HealthCheck
{
Expand Down
3 changes: 1 addition & 2 deletions src/Tasks/Monitor/HealthChecks/MaximumAgeInDays.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class MaximumAgeInDays extends HealthCheck
{
public function __construct(
protected int $days = 1
) {
}
) {}

public function checkHealth(BackupDestination $backupDestination): void
{
Expand Down
3 changes: 1 addition & 2 deletions src/Tasks/Monitor/HealthChecks/MaximumStorageInMegabytes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class MaximumStorageInMegabytes extends HealthCheck
{
public function __construct(
protected int $maximumSizeInMegaBytes = 5000
) {
}
) {}

public function checkHealth(BackupDestination $backupDestination): void
{
Expand Down

0 comments on commit 7132981

Please sign in to comment.