Passed
Pull Request — develop (#18)
by
unknown
07:13
created

GroupStudentController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Judite\Models\Group;
6
use Illuminate\Support\Facades\DB;
7
use Illuminate\Support\Facades\Auth;
8
9
class GroupStudentController extends Controller
10
{
11
    /**
12
     * Create a new controller instance.
13
     */
14
    public function __construct()
15
    {
16
        $this->middleware('auth');
17
        $this->middleware('can.group');
18
        $this->middleware('can.student');
19
        $this->middleware('student.verified');
20
    }
21
22
    /**
23
     * Confirm joining a group.
24
     *
25
     * @param \App\Judite\Models\Group  $group
26
     * 
27
     * @return \Illuminate\Http\RedirectResponse
28
     */
29
    public function confirm(Group $group)
30
    {
31
        $student = DB::transaction(function () {
32
            return Auth::user()->student;
0 ignored issues
show
Bug introduced by
Accessing student on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
33
        });
34
35
        $this->authorize('reply-group', [$student, $group]);
36
37
        DB::transaction(function () use ($student, $group) {
38
            return $student->confirmGroup($group);
39
        });
40
        flash('The group request was successfully confirmed.')->success();
41
42
        return redirect()->back();
43
    }
44
45
    /**
46
     * Decline joining a group.
47
     * 
48
     * @param \App\Judite\Models\Group  $group
49
     * 
50
     * @return \Illuminate\Http\RedirectResponse
51
     */
52
    public function decline(Group $group)
53
    {
54
        $student = Auth::user()->student;
0 ignored issues
show
Bug introduced by
Accessing student on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
55
56
        $this->authorize('reply-group', [$student, $group]);
57
58
        DB::transaction(function () use ($student, $group) {
59
            return $student->declineGroup($group);
60
        });
61
        flash('The group request was successfully declined.')->success();
62
63
        return redirect()->back();
64
    }
65
}
66