Completed
Pull Request — master (#2)
by ARCANEDEV
01:58
created

CheckAdministrators::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php namespace Arcanesoft\Core\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Http\Request;
5
6
/**
7
 * Class     AdminMiddleware
8
 *
9
 * @package  Arcanesoft\Foundation\Http\Middleware
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class CheckAdministrators
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Main Functions
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * Run the request filter.
20
     *
21
     * @param  \Illuminate\Http\Request  $request
22
     * @param  \Closure                  $next
23
     *
24
     * @return mixed
25
     */
26
    public function handle(Request $request, Closure $next)
27
    {
28
        /** @var  \Arcanesoft\Contracts\Auth\Models\User  $user */
29
        $user = auth()->user();
30
31
        if (is_null($user) || ! $this->isAllowed($user)) {
32
            abort(404, "You're not allowed !");
33
        }
34
35
        return $next($request);
36
    }
37
38
    /* ------------------------------------------------------------------------------------------------
39
     |  Other Functions
40
     | ------------------------------------------------------------------------------------------------
41
     */
42
    /**
43
     * Check if the user is allowed.
44
     *
45
     * @param  \Arcanesoft\Contracts\Auth\Models\User  $user
46
     *
47
     * @return bool
48
     */
49
    private function isAllowed($user)
50
    {
51
        return $user->isAdmin() || $user->isModerator();
0 ignored issues
show
Bug introduced by
The method isModerator() does not seem to exist on object<Arcanesoft\Contracts\Auth\Models\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
    }
53
}
54