Completed
Push — master ( 22fa00...44c771 )
by ARCANEDEV
07:45
created

PermissionsGroupsComposer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

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 5
rs 9.4285
ccs 0
cts 4
cp 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php namespace Arcanesoft\Auth\ViewComposers;
2
3
use Arcanesoft\Contracts\Auth\Models\Permission;
4
use Arcanesoft\Contracts\Auth\Models\PermissionsGroup;
5
use Illuminate\Contracts\View\View;
6
7
/**
8
 * Class     PermissionsGroupsComposer
9
 *
10
 * @package  Arcanesoft\Auth\ViewComposers
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class PermissionsGroupsComposer extends ViewComposer
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Main Functions
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Compose the view.
21
     *
22
     * @param  \Illuminate\Contracts\View\View  $view
23
     */
24
    public function composeFilters(View $view)
25
    {
26
        $filters = collect();
27
28
        // Permission groups
29
        //----------------------------------
30
        $groups = $this->cacheResults('permissions-groups.filters', function () {
31
            return PermissionsGroup::has('permissions')->get();
0 ignored issues
show
Bug introduced by
The method has() does not seem to exist on object<Arcanesoft\Contra...odels\PermissionsGroup>.

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...
32
        });
33
34
        foreach ($groups as $group) {
35
            /** @var  \Arcanesoft\Auth\Models\PermissionsGroup  $group */
36
            $filters->put($group->slug, link_to_route('auth::foundation.permissions.group', $group->name, [
37
                $group->hashed_id
38
            ]));
39
        }
40
41
        // Custom Permission group
42
        //----------------------------------
43
        if (Permission::where('group_id', 0)->count()) {
0 ignored issues
show
Bug introduced by
The method where() does not seem to exist on object<Arcanesoft\Contra...Auth\Models\Permission>.

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...
44
            $filters->put('custom', link_to_route('auth::foundation.permissions.group', 'Custom', [
45
                hasher()->encode(0)
46
            ]));
47
        }
48
49
        $view->with('groupFilters', $filters->toArray()); // TODO: return a collection instead of simple array
50
    }
51
}
52