Passed
Push — master ( d63a45...8016ac )
by Iman
09:10
created

GetCurrentX   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getModulePath() 0 5 1
A getCurrentMenuId() 0 11 2
A getCurrentModule() 0 6 2
A getCurrentMethod() 0 3 1
A getCurrentId() 0 5 2
A getCurrentDashboardId() 0 10 2
1
<?php
2
3
namespace Crocodicstudio\Crudbooster\Helpers;
4
5
use Crocodicstudio\Crudbooster\Modules\ModuleGenerator\ModulesRepo;
6
use DB;
7
use Request;
8
use Route;
9
10
class GetCurrentX
11
{
12
    public static function getCurrentId() : int
13
    {
14
        $id = session('current_row_id') ?: Request::segment(4);
15
16
        return intval($id);
17
    }
18
19
    public static function getCurrentMethod() : string
20
    {
21
        return str_after(Route::currentRouteAction(), "@");
22
    }
23
24
    public static function getCurrentModule()
25
    {
26
        $modulePath = self::getModulePath();
27
        return cache()->remember('crudbooster_modules_'.$modulePath, 2, function () use ($modulePath) {
28
            $module = app('CbModulesRegistery')->getModule($modulePath);
0 ignored issues
show
Bug introduced by
The method getModule() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
            $module = app('CbModulesRegistery')->/** @scrutinizer ignore-call */ getModule($modulePath);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
            return $module?: ModulesRepo::getByPath($modulePath);
30
        });
31
    }
32
33
    public static function getCurrentDashboardId()
34
    {
35
        if (request('d') == null) {
36
            return session('currentDashboardId');
37
        }
38
        session([
39
            'currentDashboardId' => request('d'),
40
            'currentMenuId' => 0,
41
        ]);
42
        return request('d');
43
    }
44
45
    public static function getCurrentMenuId()
46
    {
47
        if (request('m') == null) {
48
            return session('currentMenuId');
49
        }
50
        session([
51
            'currentMenuId' => request('m'),
52
            'currentDashboardId' => 0,
53
        ]);
54
55
        return request('m');
56
    }
57
58
    private static function getModulePath()
59
    {
60
        $adminPathSegments = count(explode('/', cbConfig('ADMIN_PATH')));
61
62
        return Request::segment(1 + $adminPathSegments);
63
    }
64
}