Passed
Push — master ( 45eca1...10ee28 )
by Thomas
07:06
created

syncLeadStatuses   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 11 3
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Student;
6
use Illuminate\Console\Command;
7
8
class syncLeadStatuses extends Command
9
{
10
    protected $signature = 'academico:resync-statuses';
11
12
    protected $description = 'Student have a computed status, which is stored in the DB for performance reasons. In case statuses get out of sync, this command will resync them.';
13
14
    public function __construct()
15
    {
16
        parent::__construct();
17
    }
18
19
    public function handle()
20
    {
21
        foreach (Student::where('lead_type_id', 1)->get() as $student) {
22
            $student->update(['lead_type_id' => null]);
23
        }
24
25
        foreach (Student::enrolled()->get() as $student) {
26
            $student->update(['lead_type_id' => 1]);
27
        }
28
29
        return Command::SUCCESS;
30
    }
31
}
32