Code Duplication    Length = 48-49 lines in 2 locations

src/Notifications/Notifications/BackupHasFailed.php 1 location

@@ 11-59 (lines=49) @@
8
use Spatie\Backup\Events\BackupHasFailed as BackupHasFailedEvent;
9
use Spatie\Backup\Notifications\BaseNotification;
10
11
class BackupHasFailed extends BaseNotification
12
{
13
    /** @var \Spatie\Backup\Events\BackupHasFailed */
14
    protected $event;
15
16
    public function toMail(): MailMessage
17
    {
18
        $mailMessage = (new MailMessage)
19
            ->error()
20
            ->subject("Failed back up of `{$this->applicationName()}`")
21
            ->line("Important: An error occurred while backing up `{$this->applicationName()}`")
22
            ->line("Exception message: `{$this->event->exception->getMessage()}`")
23
            ->line("Exception trace: `{$this->event->exception->getTraceAsString()}`");
24
25
26
        $this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
27
            $mailMessage->line("{$name}: $value");
28
        });
29
30
        return $mailMessage;
31
    }
32
33
    public function toSlack(): SlackMessage
34
    {
35
        return (new SlackMessage)
36
            ->error()
37
            ->content("Failed back up of `{$this->applicationName()}`")
38
            ->attachment(function (SlackAttachment $attachment) {
39
                $attachment
40
                    ->title('Exception message')
41
                    ->content($this->event->exception->getMessage());
42
            })
43
            ->attachment(function (SlackAttachment $attachment) {
44
                $attachment
45
                    ->title('Exception trace')
46
                    ->content($this->event->exception->getTraceAsString());
47
            })
48
            ->attachment(function (SlackAttachment $attachment) {
49
                $attachment->fields($this->backupDestinationProperties()->toArray());
50
            });
51
    }
52
53
    public function setEvent(BackupHasFailedEvent $event)
54
    {
55
        $this->event = $event;
56
57
        return $this;
58
    }
59
}
60

src/Notifications/Notifications/CleanupHasFailed.php 1 location

@@ 11-58 (lines=48) @@
8
use Spatie\Backup\Events\CleanupHasFailed as CleanupHasFailedEvent;
9
use Spatie\Backup\Notifications\BaseNotification;
10
11
class CleanupHasFailed extends BaseNotification
12
{
13
    /** @var \Spatie\Backup\Events\CleanupHasFailed */
14
    protected $event;
15
16
    public function toMail(): MailMessage
17
    {
18
        $mailMessage = (new MailMessage)
19
            ->error()
20
            ->subject("Cleaning up the backups of `{$this->applicationName()}` failed.")
21
            ->line("An error occurred while cleaning up the backups of `{$this->applicationName()}`")
22
            ->line("Exception message: `{$this->event->exception->getMessage()}`")
23
            ->line("Exception trace: `{$this->event->exception->getTraceAsString()}`");
24
25
        $this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
26
            $mailMessage->line("{$name}: $value");
27
        });
28
29
        return $mailMessage;
30
    }
31
32
    public function toSlack(): SlackMessage
33
    {
34
        return (new SlackMessage)
35
            ->error()
36
            ->content("An error occurred while cleaning up the backups of `{$this->applicationName()}`")
37
            ->attachment(function (SlackAttachment $attachment) {
38
                $attachment
39
                    ->title('Exception message')
40
                    ->content($this->event->exception->getMessage());
41
            })
42
            ->attachment(function (SlackAttachment $attachment) {
43
                $attachment
44
                    ->title('Exception trace')
45
                    ->content($this->event->exception->getTraceAsString());
46
            })
47
            ->attachment(function (SlackAttachment $attachment) {
48
                $attachment->fields($this->backupDestinationProperties()->toArray());
49
            });
50
    }
51
52
    public function setEvent(CleanupHasFailedEvent $event)
53
    {
54
        $this->event = $event;
55
56
        return $this;
57
    }
58
}
59