ThemeComposer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 12
c 3
b 1
f 0
dl 0
loc 39
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compose() 0 17 4
A __construct() 0 3 1
1
<?php
2
3
namespace App\Http\ViewComposers;
4
5
use App\Models\Theme;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\View\View;
8
9
class ThemeComposer
10
{
11
    protected $user;
12
    protected $theme;
13
14
    /**
15
     * Create a new instance.
16
     *
17
     * @return void
18
     */
19
    public function __construct()
20
    {
21
        $this->user = Auth::user();
22
    }
23
24
    /**
25
     * Bind data to the view.
26
     *
27
     * @param View $view
28
     *
29
     * @return void
30
     */
31
    public function compose(View $view)
32
    {
33
        $theme = null;
34
35
        if (Auth::check()) {
36
            $user = $this->user;
37
38
            if ($user->profile) {
39
                $theme = Theme::find($user->profile->theme_id);
40
41
                if ($theme->status === 0) {
0 ignored issues
show
introduced by
The condition $theme->status === 0 is always false.
Loading history...
42
                    $theme = Theme::find(Theme::default);
43
                }
44
            }
45
        }
46
47
        $view->with('theme', $theme);
48
    }
49
}
50