HomeController::index()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 5
eloc 13
c 2
b 0
f 1
nc 16
nop 0
dl 0
loc 28
rs 9.5222
1
<?php
2
declare(strict_types = 1);
3
4
namespace App\Http\Controllers;
5
6
use App\Models\Compilation;
7
use App\Models\Location;
8
use App\Models\Ward;
9
use App\User;
10
use Illuminate\Support\Facades\Auth;
11
12
class HomeController extends Controller
13
{
14
15
    /**
16
     * Show the application dashboard.
17
     *
18
     * @return \Illuminate\View\View
19
     */
20
    public function index()
21
    {
22
    
23
        $data = [
24
            "number_of_locations" => Location::count(),
25
            "number_of_wards" => Ward::count(),
26
            "number_of_compilations" => Compilation::count(),
27
        ];
28
29
        if (Auth::user()->cannot("viewAll", Compilation::class)) {
30
            // If the current user cannot view all compilations,
31
            // it's automatically a student.
32
            $data["number_of_compilations"] = Auth::user()->student->compilations->count();
33
        }
34
        
35
        if (Auth::user()->can("viewStudents", User::class)) {
36
            $data["number_of_students"] = User::students()->count();
37
        }
38
        
39
        if (Auth::user()->can("viewViewers", User::class)) {
40
            $data["number_of_viewers"] = User::viewers()->count();
41
        }
42
        
43
        if (Auth::user()->can("viewAdministrators", User::class)) {
44
            $data["number_of_administrators"] = User::administrators()->count();
45
        }
46
47
        return view("home", $data);
48
49
    }
50
51
}
52