Completed
Push — dev ( 2ed1fc...18be1d )
by Tristan
12:56 queued 06:13
created

MenuComposer::compose()   F

Complexity

Conditions 35
Paths 126

Size

Total Lines 119
Code Lines 96

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1141.6524

Importance

Changes 0
Metric Value
eloc 96
dl 0
loc 119
ccs 3
cts 90
cp 0.0333
rs 3.95
c 0
b 0
f 0
cc 35
nc 126
nop 1
crap 1141.6524

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Http\ViewComposers;
4
5
use Illuminate\View\View;
6
use Illuminate\Support\Facades\Lang;
7
use Illuminate\Support\Facades\Route;
8
use Illuminate\Support\Facades\Auth;
9
use Facades\App\Services\WhichPortal;
0 ignored issues
show
Bug introduced by
The type Facades\App\Services\WhichPortal was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class MenuComposer
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class MenuComposer
Loading history...
12
{
13
    /**
14
     * Bind data to the view.
15
     *
16
     * @param  View  $view
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
17
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
18
     */
19 2
    public function compose(View $view)
20
    {
21 2
        if (WhichPortal::isApplicantPortal()) {
22 2
            $menuItems = Lang::get('applicant/menu');
23
24
            //Set active on the proper item
25
            switch(Route::currentRouteName()) {
26
                case 'home':
27
                    $menuItems['home']['active'] = true;
28
                    break;
29
                case 'jobs.index':
30
                case 'jobs.show':
31
                case 'managers.show':
32
                    $menuItems['jobs']['active'] = true;
33
                    break;
34
                case 'applications.index':
35
                case 'applications.edit':
36
                case 'applications.edit.1':
37
                case 'applications.edit.2':
38
                case 'applications.edit.3':
39
                case 'applications.edit.4':
40
                case 'applications.edit.5':
41
                    $menuItems['applications']['active'] = true;
42
                    break;
43
                case 'profile':
44
                case 'profile.edit':
45
                case 'profile.show':
46
                    $menuItems['profile']['active'] = true;
47
                    break;
48
                case 'register':
49
                    $menuItems['register']['active'] = true;
50
                    break;
51
                case 'login':
52
                    $menuItems['login']['active'] = true;
53
                    break;
54
                case 'logout':
55
                    $menuItems['logout']['active'] = true;
56
                    break;
57
                default:
58
                    //No menu item will be active
59
                    break;
60
            }
61
62
            //Check if use is logged in, and remove invalid menu items
63
            if (Auth::check()) {
64
                unset($menuItems['login']);
65
                unset($menuItems['register']);
66
                //TODO set profile like using user slug
67
            } else {
68
                unset($menuItems['logout']);
69
                unset($menuItems['applications']);
70
                unset($menuItems['profile']);
71
            }
72
        } else if (WhichPortal::isManagerPortal()) {
73
            $menuItems = Lang::get('manager/menu');
74
75
            //Set active on the proper item
76
            switch(Route::currentRouteName()) {
77
                case 'manager.home':
78
                    $menuItems['home']['active'] = true;
79
                    break;
80
                case 'manager.jobs.index':
81
                case 'manager.jobs.show':
82
                    $menuItems['jobs']['active'] = true;
83
                    break;
84
                case 'manager.jobs.create':
85
                case 'manager.jobs.edit':
86
                case 'manager.jobs.update':
87
                    $menuItems['create_job']['active'] = true;
88
                    break;
89
                case 'manager.profile':
90
                case 'manager.profile.edit':
91
                case 'manager.profile.show':
92
                    $menuItems['profile']['active'] = true;
93
                    break;
94
                case 'register':
95
                    $menuItems['register']['active'] = true;
96
                    break;
97
                case 'login':
98
                    $menuItems['login']['active'] = true;
99
                    break;
100
                case 'logout':
101
                    $menuItems['logout']['active'] = true;
102
                    break;
103
                default:
104
                    //No menu item will be active
105
                    break;
106
            }
107
108
            //Check if use is logged in, and remove invalid menu items
109
            if (Auth::check()) {
110
                unset($menuItems['login']);
111
                unset($menuItems['register']);
112
                //TODO set profile like using user slug
113
            } else {
114
                unset($menuItems['logout']);
115
                unset($menuItems['jobs']);
116
                unset($menuItems['create_job']);
117
                unset($menuItems['profile']);
118
            }
119
        }
120
        if (WhichPortal::isManagerPortal()) {
121
            $loginModals = [
122
                'modals' => Lang::get('common/login_modals'),
123
                'register_link' => route('manager.register'),
124
                'login_link' => route('manager.login'),
125
                'logout_link' => route('manager.logout'),
126
            ];
127
        } else {
128
            $loginModals = [
129
                'modals' => Lang::get('common/login_modals'),
130
                'register_link' => route('register'),
131
                'login_link' => route('login'),
132
                'logout_link' => route('logout'),
133
            ];
134
        }
135
136
        $view->with('menu', $menuItems)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $menuItems does not seem to be defined for all execution paths leading up to this point.
Loading history...
137
            ->with('login_modals', $loginModals);
138
    }
139
}
140