Completed
Push — master ( f62f21...f72c97 )
by Freek
05:09
created

MonitorCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 7
Bugs 1 Features 1
Metric Value
wmc 2
c 7
b 1
f 1
lcom 0
cbo 6
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 2
1
<?php
2
3
namespace Spatie\Backup\Commands;
4
5
use Spatie\Backup\Events\HealthyBackupWasFound;
6
use Spatie\Backup\Events\UnhealthyBackupWasFound;
7
use Spatie\Backup\Tasks\Monitor\BackupDestinationStatus;
8
use Spatie\Backup\Tasks\Monitor\BackupDestinationStatusFactory;
9
10
class MonitorCommand extends BaseCommand
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $signature = 'backup:monitor';
16
17
    /**
18
     * @var string
19
     */
20
    protected $description = 'Monitor the health of all backups.';
21
22
    public function handle()
23
    {
24
        $statuses = BackupDestinationStatusFactory::createForMonitorConfig(config('laravel-backup.monitorBackups'));
25
26
        $statuses->each(function (BackupDestinationStatus $backupDestinationStatus) {
27
28
           if ($backupDestinationStatus->isHealthy()) {
29
               event(new HealthyBackupWasFound($backupDestinationStatus));
30
31
               return;
32
           }
33
34
            event(new UnHealthyBackupWasFound($backupDestinationStatus));
35
        });
36
    }
37
}
38