Passed
Push — master ( 9f15d2...3a106b )
by Darko
10:30
created

GlobalDataComposer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 25
c 1
b 0
f 0
dl 0
loc 43
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A compose() 0 38 3
1
<?php
2
3
namespace App\View\Composers;
4
5
use App\Events\UserLoggedIn;
6
use App\Models\Category;
7
use App\Models\Settings;
8
use App\Models\User;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\View\View;
11
12
class GlobalDataComposer
13
{
14
    /**
15
     * Bind data to the view.
16
     */
17
    public function compose(View $view): void
18
    {
19
        $settings = new Settings;
20
21
        $viewData = [
22
            'serverroot' => url('/'),
23
            'site' => $settings,
24
            'theme' => 'Gentele',
25
        ];
26
27
        if (Auth::check()) {
28
            $userdata = User::find(Auth::id());
29
            $userdata->categoryexclusions = User::getCategoryExclusionById(Auth::id());
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Facades\Auth::id() can also be of type null and string; however, parameter $userID of App\Models\User::getCategoryExclusionById() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

29
            $userdata->categoryexclusions = User::getCategoryExclusionById(/** @scrutinizer ignore-type */ Auth::id());
Loading history...
30
31
            // Update last login every 15 mins.
32
            if (now()->subHours(3) > $userdata->lastlogin) {
33
                event(new UserLoggedIn($userdata));
34
            }
35
36
            $parentcatlist = Category::getForMenu($userdata->categoryexclusions);
37
38
            $viewData = array_merge($viewData, [
39
                'userdata' => $userdata,
40
                'loggedin' => true,
41
                'isadmin' => $userdata->hasRole('Admin'),
42
                'ismod' => $userdata->hasRole('Moderator'),
43
                'parentcatlist' => $parentcatlist,
44
                'header_menu_cat' => request()->input('t', ''),
45
            ]);
46
        } else {
47
            $viewData = array_merge($viewData, [
48
                'isadmin' => false,
49
                'ismod' => false,
50
                'loggedin' => false,
51
            ]);
52
        }
53
54
        $view->with($viewData);
55
    }
56
}
57