CBBackend::handle()   B
last analyzed

Complexity

Conditions 11
Paths 10

Size

Total Lines 34
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 34
rs 7.3166
c 0
b 0
f 0
cc 11
nc 10
nop 2

How to fix   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
3
namespace crocodicstudio\crudbooster\middlewares;
4
5
use Closure;
6
use CRUDBooster;
0 ignored issues
show
Bug introduced by
The type CRUDBooster 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...
7
use DB;
8
9
class CBBackend
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request $request
15
     * @param  \Closure $next
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        $admin_path = config('crudbooster.ADMIN_PATH') ?: 'admin';
21
22
        if (CRUDBooster::myId() == '') {
23
            $url = url($admin_path.'/login');
24
25
            return redirect($url)->with('message', trans('crudbooster.not_logged_in'));
26
        }
27
        if (CRUDBooster::isLocked()) {
28
            $url = url($admin_path.'/lock-screen');
29
30
            return redirect($url);
31
        }
32
        if($request->url()==CRUDBooster::adminPath('')){
33
            $menus=DB::table('cms_menus')->whereRaw("cms_menus.id IN (select id_cms_menus from cms_menus_privileges where id_cms_privileges = '".CRUDBooster::myPrivilegeId()."')")->where('is_dashboard', 1)->where('is_active', 1)->first();
34
            if ($menus) {
35
                if ($menus->type == 'Statistic') {
36
                    return redirect()->action('\crocodicstudio\crudbooster\controllers\StatisticBuilderController@getDashboard');
37
                } elseif ($menus->type == 'Module') {
38
                    $module = CRUDBooster::first('cms_moduls', ['path' => $menus->path]);
39
                    return redirect()->action( $module->controller.'@getIndex');
40
                } elseif ($menus->type == 'Route') {
41
                    $action = str_replace("Controller", "Controller@", $menus->path);
42
                    $action = str_replace(['Get', 'Post'], ['get', 'post'], $action);
43
                    return redirect()->action($action);
44
                } elseif ($menus->type == 'Controller & Method') {
45
                    return redirect()->action($menus->path);
46
                } elseif ($menus->type == 'URL') {
47
                    return redirect($menus->path);
48
                }
49
            }
50
        }
51
        return $next($request);
52
    }
53
}
54