Completed
Push — master ( 1ae7e9...b1d075 )
by Martin
06:18
created

EventController::index()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
nc 5
nop 0
dl 0
loc 22
rs 9.7998
c 1
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Event;
6
use App\Http\Controllers\Controller;
7
use App\Project;
8
use Illuminate\Database\Eloquent\Builder;
9
use Illuminate\Http\Request;
10
11
class EventController extends Controller
12
{
13
    //
14
    public function index()
15
    {
16
        $projects = Project::where('is_archived', false)->get();
17
        $archive = Project::where('is_archived', true)->get();
18
        foreach( $archive as $project )
19
        {
20
            // Set the time range of the project by selecting the last and first dates of its events
21
            // if no events are associated with the project, set the dates to '-'
22
            $firstEvent = $project->events()->orderBy('start_date', 'ASC')->first();
23
            $project->start_date = $firstEvent === null ? '-' : $firstEvent->start_date;
1 ignored issue
show
Bug introduced by
The property start_date does not seem to exist on App\Project. 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...
24
            $lastEvent = $project->events()->orderBy('end_date', 'DESC')->first();
25
            $project->end_date = $lastEvent === null ? '-' : $lastEvent->end_date;
1 ignored issue
show
Bug introduced by
The property end_date does not seem to exist on App\Project. 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...
26
        }
27
28
        $events = Event::whereHas('project', function(Builder $query) {
29
            $query->where('is_archived', false);
30
        })->get();
31
32
        return view('admin.events.index', [
33
            'projects' => $projects,
34
            'events'   => $events,
35
            'archived' => $archive
36
        ]);
37
    }
38
39
    public function create()
40
    {
41
        return "TODO";
42
    }
43
44
    public function get(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
    public function get(/** @scrutinizer ignore-unused */ Event $event)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        return "TODO";
47
    }
48
49
    public function update(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
    public function update(/** @scrutinizer ignore-unused */ Event $event)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        return "TODO";
52
    }
53
54
    public function delete(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

54
    public function delete(/** @scrutinizer ignore-unused */ Event $event)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        return "TODO";
57
    }
58
}
59