Completed
Push — master ( f40498...e3ae3a )
by ARCANEDEV
03:17
created

PermissionsGroupsComposer::composeFilters()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 30
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 30
ccs 0
cts 19
cp 0
rs 8.8571
cc 3
eloc 12
nc 4
nop 1
crap 12
1
<?php namespace Arcanesoft\Auth\ViewComposers;
2
3
use Arcanesoft\Auth\Bases\ViewComposer;
4
use Arcanesoft\Contracts\Auth\Models\PermissionsGroup;
5
use Arcanesoft\Contracts\Auth\Models\Permission;
6
use Illuminate\Contracts\View\View;
7
8
/**
9
 * Class     PermissionsGroupsComposer
10
 *
11
 * @package  Arcanesoft\Auth\ViewComposers
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class PermissionsGroupsComposer extends ViewComposer
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Properties
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * The permissions group model.
22
     *
23
     * @var  \Arcanesoft\Contracts\Auth\Models\PermissionsGroup
24
     */
25
    protected $permissionsGroup;
26
27
    /**
28
     * The permission model.
29
     *
30
     * @var  \Arcanesoft\Contracts\Auth\Models\Permission
31
     */
32
    protected $permission;
33
34
    /* ------------------------------------------------------------------------------------------------
35
     |  Constructor
36
     | ------------------------------------------------------------------------------------------------
37
     */
38
    /**
39
     * PermissionsGroupsComposer constructor.
40
     *
41
     * @param  \Arcanesoft\Contracts\Auth\Models\PermissionsGroup  $permissionsGroup
42
     * @param  \Arcanesoft\Contracts\Auth\Models\Permission        $permission
43
     */
44
    public function __construct(PermissionsGroup $permissionsGroup, Permission $permission)
45
    {
46
        $this->permissionsGroup = $permissionsGroup;
47
        $this->permission       = $permission;
48
    }
49
50
    /* ------------------------------------------------------------------------------------------------
51
     |  Main Functions
52
     | ------------------------------------------------------------------------------------------------
53
     */
54
    /**
55
     * Compose the view.
56
     *
57
     * @param  \Illuminate\Contracts\View\View  $view
58
     */
59
    public function composeFilters(View $view)
60
    {
61
        $filters        = [];
62
63
        // All Permission group
64
        //----------------------------------
65
        $filters['all'] = link_to_route('auth::foundation.permissions.index', 'All');
66
67
        // Permission groups
68
        //----------------------------------
69
        $groups      = $this->cacheResults('permissions-groups.filters', function () {
70
            return $this->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...
71
        });
72
        foreach ($groups as $group) {
73
            /** @var  PermissionsGroup  $group */
74
            $filters[$group->slug] = link_to_route('auth::foundation.permissions.group', $group->name, [
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Arcanesoft\Contracts\Auth\Models\PermissionsGroup suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing name on the interface Arcanesoft\Contracts\Auth\Models\PermissionsGroup suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
75
                $group->hashed_id
0 ignored issues
show
Bug introduced by
Accessing hashed_id on the interface Arcanesoft\Contracts\Auth\Models\PermissionsGroup suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
76
            ]);
77
        }
78
79
        // Custom Permission group
80
        //----------------------------------
81
        if ($this->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...
82
            $filters['custom'] = link_to_route('auth::foundation.permissions.group', 'Custom', [
83
                hasher()->encode(0)
84
            ]);
85
        }
86
87
        $view->with('groupFilters', $filters);
88
    }
89
}
90