ThemeComposer::compose()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 4
eloc 8
c 2
b 1
f 0
nc 4
nop 1
dl 0
loc 17
rs 10
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