Code Duplication    Length = 35-35 lines in 3 locations

src/Notifications/Notifications/BackupWasSuccessful.php 1 location

@@ 11-45 (lines=35) @@
8
use Spatie\Backup\Events\BackupWasSuccessful as BackupWasSuccessfulEvent;
9
use Spatie\Backup\Notifications\BaseNotification;
10
11
class BackupWasSuccessful extends BaseNotification
12
{
13
    /** @var \Spatie\Backup\Events\BackupWasSuccessful */
14
    protected $event;
15
16
    public function toMail(): MailMessage
17
    {
18
        $mailMessage = (new MailMessage)
19
            ->subject("Successful new backup of `{$this->applicationName()}`")
20
            ->line("Great news, a new backup of {$this->applicationName()} was successfully created on the disk named {$this->diskName()}.");
21
22
        $this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
23
            $mailMessage->line("{$name}: $value");
24
        });
25
26
        return $mailMessage;
27
    }
28
29
    public function toSlack(): SlackMessage
30
    {
31
        return (new SlackMessage)
32
            ->success()
33
            ->content('Successful new backup!')
34
            ->attachment(function (SlackAttachment $attachment) {
35
                $attachment->fields($this->backupDestinationProperties()->toArray());
36
            });
37
    }
38
39
    public function setEvent(BackupWasSuccessfulEvent $event)
40
    {
41
        $this->event = $event;
42
43
        return $this;
44
    }
45
}
46

src/Notifications/Notifications/CleanupWasSuccessful.php 1 location

@@ 11-45 (lines=35) @@
8
use Spatie\Backup\Events\CleanupWasSuccessful as CleanupWasSuccessfulEvent;
9
use Spatie\Backup\Notifications\BaseNotification;
10
11
class CleanupWasSuccessful extends BaseNotification
12
{
13
    /** @var \Spatie\Backup\Events\CleanupWasSuccessful */
14
    protected $event;
15
16
    public function toMail($notifiable): MailMessage
17
    {
18
        $mailMessage = (new MailMessage)
19
            ->subject("Clean up of `{$this->applicationName()}` backups successful")
20
            ->line("The cleaup up of the {$this->applicationName()} backups on the disk named {$this->diskName()} was successful.");
21
22
        $this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
23
            $mailMessage->line("{$name}: $value");
24
        });
25
26
        return $mailMessage;
27
    }
28
29
    public function toSlack($notifiable): SlackMessage
30
    {
31
        return (new SlackMessage)
32
            ->success()
33
            ->content('Clean up of backups successful!')
34
            ->attachment(function (SlackAttachment $attachment) {
35
                $attachment->fields($this->backupDestinationProperties()->toArray());
36
            });
37
    }
38
39
    public function setEvent(CleanupWasSuccessfulEvent $event)
40
    {
41
        $this->event = $event;
42
43
        return $this;
44
    }
45
}
46

src/Notifications/Notifications/HealthyBackupWasFound.php 1 location

@@ 11-45 (lines=35) @@
8
use Spatie\Backup\Events\HealthyBackupWasFound as HealthyBackupWasFoundEvent;
9
use Spatie\Backup\Notifications\BaseNotification;
10
11
class HealthyBackupWasFound extends BaseNotification
12
{
13
    /** @var \Spatie\Backup\Events\HealthyBackupWasFound */
14
    protected $event;
15
16
    public function toMail(): SlackMessage
17
    {
18
        $mailMessage = (new MailMessage)
19
            ->subject("The backups for `{$this->applicationName()}` on disk `{$this->diskName()}` are healthy")
20
            ->line("The backups for `{$this->applicationName()}` are considered healthy. Good job!");
21
22
        $this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
23
            $mailMessage->line("{$name}: $value");
24
        });
25
26
        return $mailMessage;
27
    }
28
29
    public function toSlack(): SlackMessage
30
    {
31
        return (new SlackMessage)
32
            ->success()
33
            ->content("The backups for `{$this->applicationName()}` are healthy")
34
            ->attachment(function (SlackAttachment $attachment) {
35
                $attachment->fields($this->backupDestinationProperties()->toArray());
36
            });
37
    }
38
39
    public function setEvent(HealthyBackupWasFoundEvent $event)
40
    {
41
        $this->event = $event;
42
43
        return $this;
44
    }
45
}
46