Passed
Push — feature/permission-manager ( 41e93d )
by
unknown
09:00
created

Permission::handle()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 7
nc 4
nop 2
dl 0
loc 13
rs 8.8333
c 1
b 0
f 0
1
<?php
2
3
namespace A17\Twill\Http\Middleware;
4
5
use Auth;
6
use Closure;
7
use Illuminate\Http\Request;
8
9
class Permission
10
{
11
    public function handle(Request $request, Closure $next)
12
    {
13
        if (config('twill.enabled.permissions-management') && !Auth::user()->isSuperAdmin()) {
0 ignored issues
show
Bug introduced by
The method isSuperAdmin() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        if (config('twill.enabled.permissions-management') && !Auth::user()->/** @scrutinizer ignore-call */ isSuperAdmin()) {
Loading history...
14
            if (config('twill.support_subdomain_admin_routing') && $activeSubdomain = config('twill.active_subdomain')) {
15
                foreach(Auth::user()->groups as $group) {
0 ignored issues
show
Bug introduced by
Accessing groups on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
16
                    if (in_array($activeSubdomain, $group->subdomains_access)) {
17
                        return $next($request);
18
                    }
19
                };
20
                abort(403);
21
            }
22
        }
23
        return $next($request);
24
    }
25
}
26