Passed
Push — develop ( a18085...de8258 )
by Francisco
14:47
created

CourseController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 39.29 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 11
loc 28
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Judite\Models\Course;
6
use Illuminate\Support\Facades\DB;
7
8
class CourseController extends Controller
9
{
10
    /**
11
     * Create a new controller instance.
12
     */
13
    public function __construct()
14
    {
15
        $this->middleware('auth');
16
        $this->middleware('can.student');
17
        $this->middleware('student.verified');
18
    }
19
20
    /**
21
     * Display a listing of the resource.
22
     *
23
     * @return \Illuminate\Http\Response
24
     */
25 View Code Duplication
    public function index()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $courses = DB::transaction(function () {
28
            return Course::orderedList()->get();
29
        });
30
31
        $courses = $courses->groupBy(function ($course) {
32
            return $course->present()->getOrdinalYear();
33
        });
34
35
        return view('courses.index', compact('courses'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('courses.index', compact('courses')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
36
    }
37
}
38