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

AdminareaPolicy::access()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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