Completed
Push — master ( ebed0b...7356ba )
by Jeremy
04:47
created

UserServices::checkIsUserAdminOrHigher()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace App\Services;
4
5
use App\Models\User;
6
7
class UserServices
8
{
9
    /**
10
     * Gets the user.
11
     *
12
     * @param int $userId  The user identifier
13
     *
14
     * @return collection The user.
0 ignored issues
show
Bug introduced by
The type App\Services\collection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
     */
16
    public static function getUser($userId)
17
    {
18
        return User::findOrFail($userId);
19
    }
20
21
    /**
22
     * Check is user is admin or super admin
23
     *
24
     * @param int $userId  The user identifier
25
     */
26
    public static function checkIsUserAdminOrHigher($userId)
27
    {
28
        $user = self::getUser($userId);
29
        if (!$user->hasRole(['admin', 'super.admin'])) {
30
            abort(401);
31
        }
32
    }
33
}
34