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

PermissionsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
crap 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
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /** @var int */
20
    protected $perPage = 30;
21
22
    /* ------------------------------------------------------------------------------------------------
23
     |  Constructor
24
     | ------------------------------------------------------------------------------------------------
25
     */
26
    /**
27
     * Instantiate the controller.
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
33
        $this->setCurrentPage('auth-permissions');
34
        $this->addBreadcrumbRoute('Permissions', 'auth::foundation.permissions.index');
35
    }
36
37
    /* ------------------------------------------------------------------------------------------------
38
     |  Main Functions
39
     | ------------------------------------------------------------------------------------------------
40
     */
41
    public function index(Permission $permission)
42
    {
43
        $permissions = $permission->with('group', 'roles')
44
            ->orderBy('group_id')
45
            ->paginate($this->perPage);
46
47
        $title = 'List of permissions';
48
        $this->setTitle($title);
49
        $this->addBreadcrumb($title);
50
51
        return $this->view('foundation.permissions.list', compact('permissions'));
52
    }
53
54
    public function group(Permission $permission, PermissionsGroup $group)
55
    {
56
        $groupId = $group->id ? $group->id : 0;
57
58
        $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...
59
            ->with('group', 'roles')
60
            ->paginate($this->perPage);
61
62
        $this->addBreadcrumbRoute('List of permissions', 'auth::foundation.permissions.index');
63
64
        $groupName = $groupId == 0 ? 'Custom' : $group->name;
65
        $title     = "List of permissions - $groupName";
66
        $this->setTitle($title);
67
        $this->addBreadcrumb($groupName);
68
69
        return $this->view('foundation.permissions.list', compact('permissions'));
70
    }
71
72
    public function show(Permission $permission)
73
    {
74
        $permission->load(['roles', 'roles.users']);
75
76
        $title = 'Permission details';
77
        $this->setTitle($title);
78
        $this->addBreadcrumb($title);
79
80
        return $this->view('foundation.permissions.show', compact('permission'));
81
    }
82
}
83