Completed
Push — master ( d1ecb8...6399e4 )
by Julien
03:46 queued 23s
created

LastMovies   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 38 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
class LastMovies extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'movies:newsletter';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Send an email for suscribers to last movies this last month';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
        /*
44
         *  php5-cli php5-common php5-curl php5-gd
45
         *  php5-imap php5-intl php5-json php5-mcrypt php5-mysql php5-pspell
46
         *  php5-readline php5-sqlite
47
         */
48
49
        // SQL query
50
        $results = Movies::where('date_release','>=', new Carbon('-1 month'))
51
                        ->where('date_release','<=', new Carbon('now'))
52
                        ->get();
53
54
        // je parcours mes films
55
        foreach($results as $movie){
56
57
            dump($movie->id);
58
            $users = $movie->actors();
0 ignored issues
show
Unused Code introduced by
$users is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
59
            exit(dump(($movie->actors())));
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
60
61
            // je parcours les favoris(user) de chaque film
62
            foreach($users as $user){
0 ignored issues
show
Unused Code introduced by
// je parcours les favor...er); die('stop'); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
63
                dump($user);
64
                exit('stop');
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
65
66
            }
67
68
        }
69
        exit('TOP');
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
70
71
        //send an email
72
        Mail::send('Emails/newsletter', [], function ($m) {
0 ignored issues
show
Unused Code introduced by
//send an email \Illumin...me to newsletter'); }); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
73
74
            $m->from('[email protected]', 'Florent Boyer');
75
            $m->to("[email protected]", "Boyer Julien")
76
                ->subject('Welcome to newsletter');
77
        });
78
    }
79
}
80