EventsController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 18 2
1
<?php
2
3
namespace App\Http\Controllers\TicketShop;
4
5
use Illuminate\Http\Request;
6
use App\Http\Controllers\Controller;
7
use App\Project;
8
use Illuminate\Support\Facades\Artisan;
9
use Illuminate\Support\Facades\Cache;
10
11
class EventsController extends Controller
12
{
13
    /**
14
     * Show the starting page of the ticket shop.
15
     * 
16
     * Works for both guests and authenticated users.
17
     * 
18
     * Displays all current projects and events.
19
     */
20
    public function index()
21
    {
22
        // Cleanup lost orders all 5 minutes
23
        if (!Cache::has('deletedLostOrders')) {
24
            $expiresAt = now()->addMinutes(5);
25
            Artisan::call('app:deleteLostOrders');
26
            Cache::put('deletedLostOrders', '1', $expiresAt);
27
        }
28
29
        $projects = Project::where('is_archived', 0)->with(['events' => function ($query) {
30
            $query->where('customer_sell_stop', '>=', new \DateTime())->orderBy('start_date', 'ASC');
31
        }, 'events.location'])->get();
32
33
        $currentProjects = $projects->filter(function ($project) {
34
            return $project->events->count() > 0;
35
        })->all();
36
37
        return view('ticketshop.events', ['projects' => $currentProjects]);
38
    }
39
}
40