Completed
Push — master ( 5a5893...f6c5ff )
by Mahmoud
03:48
created

ValidateUserIsAdminTask::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace App\Containers\Authentication\Tasks;
4
5
use App\Containers\Authentication\Exceptions\UserNotAdminException;
6
use App\Containers\User\Models\User;
7
8
/**
9
 * Class ValidateUserIsAdminTask.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
class ValidateUserIsAdminTask
14
{
15
16
    /**
17
     * @param \App\Containers\User\Models\User $user
18
     *
19
     * @return  bool
20
     */
21
    public function run(User $user)
22
    {
23
        // check if is Admin
24
        $isAdmin = $user->hasRole('admin');
25
26
        if (!$isAdmin) {
27
            throw new UserNotAdminException();
28
        }
29
30
        return true;
31
    }
32
33
}
34