Completed
Push — master ( a9ddd3...a92467 )
by Freek
16:04 queued 13:41
created

src/Notifications/BaseNotification.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Spatie\Backup\Notifications;
4
5
use Spatie\Backup\Helpers\Format;
6
use Illuminate\Support\Collection;
7
use Illuminate\Notifications\Notification;
8
use Spatie\Backup\BackupDestination\BackupDestination;
9
10
abstract class BaseNotification extends Notification
11
{
12
    public function via(): array
13
    {
14
        $notificationChannels = config('backup.notifications.notifications.'.static::class);
15
16
        return array_filter($notificationChannels);
17
    }
18
19
    public function applicationName(): string
20
    {
21
        return config('app.name') ?? config('app.url') ?? 'Laravel application';
22
    }
23
24
    public function backupName(): string
25
    {
26
        return $this->backupDestination()->backupName();
27
    }
28
29
    public function diskName(): string
30
    {
31
        return $this->backupDestination()->diskName();
32
    }
33
34
    protected function backupDestinationProperties(): Collection
35
    {
36
        $backupDestination = $this->backupDestination();
37
38
        if (! $backupDestination) {
39
            return collect();
40
        }
41
42
        $backupDestination->fresh();
43
44
        $newestBackup = $backupDestination->newestBackup();
45
        $oldestBackup = $backupDestination->oldestBackup();
46
47
        return collect([
48
            'Application name' => $this->applicationName(),
49
            'Backup name' => $this->backupName(),
50
            'Disk' => $backupDestination->diskName(),
51
            'Newest backup size' => $newestBackup ? Format::humanReadableSize($newestBackup->size()) : 'No backups were made yet',
52
            'Number of backups' => (string) $backupDestination->backups()->count(),
53
            'Total storage used' => Format::humanReadableSize($backupDestination->backups()->size()),
54
            'Newest backup date' => $newestBackup ? $newestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet',
55
            'Oldest backup date' => $oldestBackup ? $oldestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet',
56
        ])->filter();
57
    }
58
59
    public function backupDestination(): ?BackupDestination
60
    {
61
        if (isset($this->event->backupDestination)) {
62
            return $this->event->backupDestination;
0 ignored issues
show
The property event does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63
        }
64
65
        if (isset($this->event->backupDestinationStatus)) {
66
            return $this->event->backupDestinationStatus->backupDestination();
67
        }
68
69
        return null;
70
    }
71
}
72