LeadStatusController::update()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 24
rs 9.8333
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Events\LeadStatusUpdatedEvent;
6
use App\Models\Student;
7
use Illuminate\Http\Request;
8
9
class LeadStatusController extends Controller
10
{
11
    public function update(Request $request)
12
    {
13
        $listId = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $listId is dead and can be removed.
Loading history...
14
        // create or update the lead status record for the selected student
15
        $student = Student::findOrFail($request->input('student'));
16
        $student->lead_type_id = $request->input('status');
17
        $student->save();
18
19
        // if the sync with external mailing system is enabled
20
        if (config('mailing-system.external_mailing_enabled') == true) {
21
            match ($request->input('status')) {
22
                1 => $listId = config('mailing-system.mailerlite.activeStudentsListId'),
23
                2, 3 => $listId = config('mailing-system.mailerlite.inactiveStudentsListId'),
24
                default => abort(422, 'List ID not found'),
25
            };
26
27
            LeadStatusUpdatedEvent::dispatch($student, $listId);
28
29
            foreach ($student->contacts as $contact) {
30
                LeadStatusUpdatedEvent::dispatch($contact, $listId);
31
            }
32
        }
33
34
        return $student->lead_type_id;
35
    }
36
}
37