Completed
Pull Request — master (#467)
by
unknown
02:20
created

BaseNotification::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
9
abstract class BaseNotification extends Notification
10
{
11
    /**
12
     * Get the notification's delivery channels.
13
     *
14
     * @return array
15
     */
16
    public function via()
17
    {
18
        $notificationChannels = config('laravel-backup.notifications.notifications.'.static::class);
19
20
        return array_filter($notificationChannels);
21
    }
22
23
    public function applicationName(): string
24
    {
25
        return config('app.name') ?? config('app.url') ?? 'Laravel application';
26
    }
27
28
    public function backupName(): string
29
    {
30
        return $this->backupDestination()->backupName();
31
    }
32
33
    public function diskName(): string
34
    {
35
        return $this->backupDestination()->diskName();
36
    }
37
    
38
39
    public function toArray($notifiable) {
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
	    return $this->backupDestinationProperties();
41
    }
42
43
    protected function backupDestinationProperties(): Collection
44
    {
45
        $backupDestination = $this->backupDestination();
46
47
        if (! $backupDestination) {
48
            return collect();
49
        }
50
51
        $newestBackup = $backupDestination->newestBackup();
52
        $oldestBackup = $backupDestination->oldestBackup();
53
54
        return collect([
55
            'Application name' => $this->applicationName(),
56
            'Backup name' => $this->backupName(),
57
            'Disk' => $backupDestination->diskName(),
58
            'Newest backup size' => $newestBackup ? Format::humanReadableSize($newestBackup->size()) : 'No backups were made yet',
59
            'Amount of backups' => (string) $backupDestination->backups()->count(),
60
            'Total storage used' => Format::humanReadableSize($backupDestination->backups()->size()),
61
            'Newest backup date' => $newestBackup ? $newestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet',
62
            'Oldest backup date' => $oldestBackup ? $oldestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet',
63
        ])->filter();
64
    }
65
66
    /**
67
     * @return \Spatie\Backup\BackupDestination\BackupDestination|null
68
     */
69
    public function backupDestination()
70
    {
71
        if (isset($this->event->backupDestination)) {
72
            return $this->event->backupDestination;
0 ignored issues
show
Bug introduced by
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...
73
        }
74
75
        if (isset($this->event->backupDestinationStatus)) {
76
            return $this->event->backupDestinationStatus->backupDestination();
77
        }
78
    }
79
}
80