LastMovies   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 1 Features 3
Metric Value
wmc 4
c 4
b 1
f 3
lcom 0
cbo 2
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 21 3
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Http\Models\Movies;
6
use Carbon\Carbon;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\Mail;
9
10
/**
11
 * Task to send an email to user favoris
12
 * Class LastMovies.
13
 */
14
class LastMovies extends Command
15
{
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'movies:newsletter';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Send an email for suscribers to last movies this last month';
29
30
    /**
31
     * Create a new command instance.
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return mixed
42
     */
43
    public function handle()
44
    {
45
        // SQL query
46
        $results = Movies::where('date_release', '>=', new Carbon('-1 month'))
47
                        ->where('date_release', '<=', new Carbon('now'))
48
                        ->get();
49
50
        // je parcours mes films
51
        foreach ($results as $movie) {
52
            $users = $movie->actors();
53
            foreach ($users as $user) {
54
                //send an email
55
                Mail::send('Emails/newsletter', [], function ($m) {
56
57
                    $m->from('[email protected]', 'Florent Boyer');
58
                    $m->to('[email protected]', 'Boyer Julien')
59
                        ->subject('Welcome to newsletter');
60
                });
61
            }
62
        }
63
    }
64
}
65