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

RolesComposer::composeFilters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 14
cp 0
rs 9.4286
cc 2
eloc 9
nc 2
nop 1
crap 6
1
<?php namespace Arcanesoft\Auth\ViewComposers;
2
3
use Arcanesoft\Auth\Bases\ViewComposer;
4
use Arcanesoft\Contracts\Auth\Models\Role;
5
use Illuminate\Contracts\View\View;
6
7
/**
8
 * Class     RolesComposer
9
 *
10
 * @package  Arcanesoft\Auth\ViewComposers
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class RolesComposer extends ViewComposer
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * The role model.
21
     *
22
     * @var \Arcanesoft\Contracts\Auth\Models\Role
23
     */
24
    private $role;
25
26
    /* ------------------------------------------------------------------------------------------------
27
     |  Constructor
28
     | ------------------------------------------------------------------------------------------------
29
     */
30
    /**
31
     * RolesComposer constructor.
32
     *
33
     * @param Role $role
34
     */
35
    public function __construct(Role $role)
36
    {
37
        $this->role = $role;
38
    }
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Main Functions
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    public function composeFilters(View $view)
45
    {
46
        $filters   = [];
47
48
        $filters['all'] = link_to_route('auth::foundation.users.index', 'All');
49
50
        $roles   = $this->cacheResults('auth::roles.filters', function () {
51
            return $this->role->has('permissions')->get();
0 ignored issues
show
Bug introduced by
The method has() does not seem to exist on object<Arcanesoft\Contracts\Auth\Models\Role>.

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...
52
        });
53
54
        foreach ($roles as $role) {
55
            /** @var  Role  $role */
56
            $filters[$role->slug] = link_to_route('auth::foundation.users.roles-filter.index', $role->name, [
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Arcanesoft\Contracts\Auth\Models\Role 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\Role 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...
57
                $role->hashed_id
0 ignored issues
show
Bug introduced by
Accessing hashed_id on the interface Arcanesoft\Contracts\Auth\Models\Role 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...
58
            ]);
59
        }
60
61
        $view->with('rolesFilters', $filters);
62
    }
63
}
64