Conditions | 7 |
Paths | 32 |
Total Lines | 74 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
96 | public function boot(Router $router): void |
||
97 | { |
||
98 | // Attach request macro |
||
99 | $this->attachRequestMacro(); |
||
100 | |||
101 | // Map bouncer models |
||
102 | Bouncer::useRoleModel(config('cortex.auth.models.role')); |
||
103 | Bouncer::useUserModel(config('cortex.auth.models.member')); |
||
104 | Bouncer::useAbilityModel(config('cortex.auth.models.ability')); |
||
105 | |||
106 | // Map bouncer tables (users, roles, abilities tables are set through their models) |
||
107 | Bouncer::tables([ |
||
108 | 'permissions' => config('cortex.auth.tables.permissions'), |
||
109 | 'assigned_roles' => config('cortex.auth.tables.assigned_roles'), |
||
110 | ]); |
||
111 | |||
112 | // Bind route models and constrains |
||
113 | $router->pattern('role', '[0-9]+'); |
||
114 | $router->pattern('ability', '[0-9]+'); |
||
115 | $router->pattern('session', '[a-zA-Z0-9]+'); |
||
116 | $router->pattern('admin', '[a-zA-Z0-9_-]+'); |
||
117 | $router->pattern('member', '[a-zA-Z0-9_-]+'); |
||
118 | $router->pattern('manager', '[a-zA-Z0-9_-]+'); |
||
119 | $router->model('role', config('cortex.auth.models.role')); |
||
120 | $router->model('admin', config('cortex.auth.models.admin')); |
||
121 | $router->model('member', config('cortex.auth.models.member')); |
||
122 | $router->model('manager', config('cortex.auth.models.manager')); |
||
123 | $router->model('guardian', config('cortex.auth.models.guardian')); |
||
124 | $router->model('ability', config('cortex.auth.models.ability')); |
||
125 | $router->model('session', config('cortex.auth.models.session')); |
||
126 | |||
127 | // Map relations |
||
128 | Relation::morphMap([ |
||
129 | 'role' => config('cortex.auth.models.role'), |
||
130 | 'admin' => config('cortex.auth.models.admin'), |
||
131 | 'member' => config('cortex.auth.models.member'), |
||
132 | 'manager' => config('cortex.auth.models.manager'), |
||
133 | 'guardian' => config('cortex.auth.models.guardian'), |
||
134 | 'ability' => config('cortex.auth.models.ability'), |
||
135 | ]); |
||
136 | |||
137 | // Load resources |
||
138 | require __DIR__.'/../../routes/breadcrumbs.php'; |
||
139 | $this->loadRoutesFrom(__DIR__.'/../../routes/web.php'); |
||
140 | $this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/auth'); |
||
141 | $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/auth'); |
||
142 | ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); |
||
143 | $this->app->afterResolving('blade.compiler', function () { |
||
144 | require __DIR__.'/../../routes/menus.php'; |
||
145 | }); |
||
146 | |||
147 | // Publish Resources |
||
148 | ! $this->app->runningInConsole() || $this->publishResources(); |
||
149 | |||
150 | // Register event handlers |
||
151 | $this->app['events']->subscribe(GenericHandler::class); |
||
152 | |||
153 | // Register attributes entities |
||
154 | ! app()->bound('rinvex.attributes.entities') || app('rinvex.attributes.entities')->push('admin'); |
||
155 | ! app()->bound('rinvex.attributes.entities') || app('rinvex.attributes.entities')->push('member'); |
||
156 | ! app()->bound('rinvex.attributes.entities') || app('rinvex.attributes.entities')->push('manager'); |
||
157 | |||
158 | // Override middlware |
||
159 | $this->overrideMiddleware($router); |
||
160 | |||
161 | // Register menus |
||
162 | $this->registerMenus(); |
||
163 | |||
164 | // Share current user instance with all views |
||
165 | $this->app['view']->composer('*', function ($view) { |
||
166 | ! config('rinvex.tenants.active') || $view->with('currentTenant', config('rinvex.tenants.active')); |
||
167 | $view->with('currentUser', auth()->guard(request()->route('guard'))->user()); |
||
168 | }); |
||
169 | } |
||
170 | |||
240 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.