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

CheckAdministrators   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 42
ccs 0
cts 11
cp 0
rs 10
c 2
b 0
f 0
wmc 5
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 3
A isAllowed() 0 4 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