Passed
Pull Request — develop (#11)
by
unknown
07:48 queued 03:43
created

GroupController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 17 3
A __construct() 0 4 1
A index() 0 11 1
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Judite\Models\Group;
6
use App\Judite\Models\Course;
7
use Illuminate\Support\Facades\DB;
8
use App\Http\Controllers\Controller;
9
10
class GroupController extends Controller
11
{
12
    /**
13
     * Create a new controller instance.
14
     */
15
    public function __construct()
16
    {
17
        $this->middleware('auth');
18
        $this->middleware('can.admin');
19
    }
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function index()
27
    {
28
        $courses = DB::transaction(function () {
29
            return Course::orderedList()->get();
30
        });
31
32
        $courses = $courses->groupBy(function ($course) {
33
            return $course->present()->getOrdinalYear();
34
        });
35
36
        return view('admin.groups.index', compact('courses'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.group...x', compact('courses')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
37
    }
38
39
    /**
40
     * Display the specified resource.
41
     *
42
     * @param int $id
43
     *
44
     * @return \Illuminate\Http\Response
45
     */
46
    public function show($courseId)
47
    {
48
        $groups = Group::whereCourseId($courseId)->get();
49
50
        foreach ($groups as $group) {
51
            $memberships = $group->memberships()->get();
52
53
            $students = [];
54
            foreach ($memberships as $membershipKey => $membership) {
55
                $student = $membership->student()->first();
56
                $student->name = $student->user()->first()->name;
57
                array_push($students, $student);
58
            }
59
            $group->students = $students;
0 ignored issues
show
Bug introduced by
The property students does not seem to exist on App\Judite\Models\Group. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
60
        }
61
62
        return view('admin.groups.show', compact('groups'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.group...ow', compact('groups')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
63
    }
64
}
65