Completed
Pull Request — master (#2)
by ARCANEDEV
02:54
created

PermissionsController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 8
c 6
b 0
f 0
lcom 1
cbo 4
dl 0
loc 93
ccs 0
cts 50
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 14 1
A group() 0 19 3
A show() 0 12 1
A getGroupsFilters() 0 14 2
1
<?php namespace Arcanesoft\Auth\Http\Controllers\Foundation;
2
3
use Arcanesoft\Auth\Bases\FoundationController;
4
use Arcanesoft\Auth\Models\Permission;
5
use Arcanesoft\Auth\Models\PermissionsGroup;
6
7
/**
8
 * Class     PermissionsController
9
 *
10
 * @package  Arcanesoft\Auth\Http\Controllers\Foundation
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class PermissionsController extends FoundationController
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Constructor
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Instantiate the controller.
21
     */
22
    public function __construct()
23
    {
24
        parent::__construct();
25
26
        $this->setCurrentPage('auth-permissions');
27
        $this->addBreadcrumbRoute('Permissions', 'auth::foundation.permissions.index');
28
    }
29
30
    /* ------------------------------------------------------------------------------------------------
31
     |  Main Functions
32
     | ------------------------------------------------------------------------------------------------
33
     */
34
    public function index(Permission $permission)
35
    {
36
        $permissions = $permission->with('group', 'roles')
37
            ->orderBy('group_id')
38
            ->paginate(30);
39
40
        $groupsLinks = $this->getGroupsFilters();
41
42
        $title = 'List of permissions';
43
        $this->setTitle($title);
44
        $this->addBreadcrumb($title);
45
46
        return $this->view('foundation.permissions.list', compact('permissions', 'groupsLinks'));
47
    }
48
49
    public function group(Permission $permission, PermissionsGroup $group)
50
    {
51
        $groupId = $group->id ? $group->id : 0;
52
53
        $permissions = $permission->where('group_id', $groupId)
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Arcanesoft\Auth\Models\Permission>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54
            ->with('group', 'roles')
55
            ->paginate(30);
56
57
        $groupsLinks = $this->getGroupsFilters();
58
59
        $this->addBreadcrumbRoute('List of permissions', 'auth::foundation.permissions.index');
60
61
        $groupName = $groupId == 0 ? 'Custom' : $group->name;
62
        $title     = "List of permissions - $groupName";
63
        $this->setTitle($title);
64
        $this->addBreadcrumb($groupName);
65
66
        return $this->view('foundation.permissions.list', compact('permissions', 'groupsLinks'));
67
    }
68
69
    public function show(Permission $permission)
70
    {
71
        $permission->load(['roles', 'roles.users']);
72
73
        $groupsLinks = $this->getGroupsFilters();
74
75
        $title = 'Permission details';
76
        $this->setTitle($title);
77
        $this->addBreadcrumb($title);
78
79
        return $this->view('foundation.permissions.show', compact('permission', 'groupsLinks'));
80
    }
81
82
    /* ------------------------------------------------------------------------------------------------
83
     |  Other Functions
84
     | ------------------------------------------------------------------------------------------------
85
     */
86
    /**
87
     * Get the groups filters links.
88
     *
89
     * @return array
90
     */
91
    protected function getGroupsFilters()
92
    {
93
        $filters   = [];
94
        $filters[] = link_to_route('auth::foundation.permissions.index', 'All');
95
96
        foreach (PermissionsGroup::all() as $group) {
97
            /** @var  PermissionsGroup  $group */
98
            $filters[] = link_to_route('auth::foundation.permissions.group', $group->name, [$group->hashed_id]);
99
        }
100
101
        $filters[] = link_to_route('auth::foundation.permissions.group', 'Custom', [hasher()->encode(0)]);
102
103
        return $filters;
104
    }
105
}
106