IsUserAdminTask   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 9 2
1
<?php
2
3
namespace App\Containers\Authorization\Tasks;
4
5
use App\Containers\Authorization\Exceptions\UserNotAdminException;
6
use App\Containers\User\Models\User;
7
use App\Ship\Parents\Tasks\Task;
8
9
/**
10
 * Class IsUserAdminTask.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class IsUserAdminTask extends Task
15
{
16
    /**
17
     * @param \App\Containers\User\Models\User|null $user
18
     *
19
     * @return  bool
20
     */
21
    public function run(User $user = null)
22
    {
23
        // check if is Admin
24
        if (!$user->hasAdminRole()) {
0 ignored issues
show
Bug introduced by
It seems like $user is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
25
            throw new UserNotAdminException();
26
        }
27
28
        return true;
29
    }
30
31
}
32