Completed
Push — master ( ac047e...863ff8 )
by Sheela
06:46
created

ProcessMonday   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 65
ccs 0
cts 25
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 2
A sendReporterEmail() 0 7 2
A getDutyList() 0 11 1
1
<?php
2
3
namespace SET\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Mail;
7
use SET\Duty;
8
use SET\Handlers\Duty\DutyList;
9
use SET\Mail\EmailAdminSummary;
10
use SET\Setting;
11
12
class ProcessMonday extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'emails:monday';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Process all commands for monday & send single email to Reporter';
27
28
    protected $classesToProcess = [
29
        'notes'     => SendReminders::class,
30
        'visits'    => ExpiringVisits::class,
31
        'records'   => RenewTraining::class,
32
        'destroyed' => DeleteUsers::class,
33
    ];
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function handle()
41
    {
42
        $mailArray = [];
43
44
        foreach ($this->classesToProcess as $key => $class) {
45
            $mailArray[$key] = (new $class())->handle()->getList();
46
        }
47
48
        $mailArray['dutyLists'] = $this->getDutyList();
49
50
        //Send FSO a summary email with all the lists we retrieved.
51
        $this->sendReporterEmail($mailArray);
52
    }
53
54
    private function sendReporterEmail($array)
55
    {
56
        $reportAddress = Setting::get('summary_recipient', null);
57
        if ($reportAddress !== null) {
58
            Mail::to($reportAddress)->send(new EmailAdminSummary($array));
59
        }
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    private function getDutyList()
66
    {
67
        $duties = Duty::all();
68
69
        return $duties->map(function ($item) {
70
            $userDateArray = (new DutyList($item))->emailOutput();
71
            $userDateArray->put('duty', $item);
72
73
            return $userDateArray;
74
        });
75
    }
76
}
77