Completed
Push — master ( b6e961...8692a9 )
by Abdelrahman
15:05 queued 12:57
created

AdminareaPolicy   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A access() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Fort\Policies;
6
7
use Rinvex\Fort\Contracts\UserContract;
8
use Illuminate\Auth\Access\HandlesAuthorization;
9
10
class AdminareaPolicy
11
{
12
    use HandlesAuthorization;
13
14
    /**
15
     * Determine whether the user can access the adminarea.
16
     *
17
     * @param string                              $ability
18
     * @param \Rinvex\Fort\Contracts\UserContract $user
19
     *
20
     * @return bool
21
     */
22
    public function access($ability, UserContract $user)
23
    {
24
        return $user->allAbilities->pluck('slug')->contains($ability);
0 ignored issues
show
Bug introduced by
Accessing allAbilities on the interface Rinvex\Fort\Contracts\UserContract 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...
25
    }
26
}
27