CheckAccessPermission   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 8
c 5
b 0
f 0
dl 0
loc 36
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 2
A __construct() 0 4 1
1
<?php namespace Distilleries\PermissionUtil\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Contracts\Container\Container;
5
use Illuminate\Http\Request;
6
7
class CheckAccessPermission {
8
9
    protected $app;
10
    /**
11
     * The Guard implementation.
12
     *
13
     * @var \Distilleries\PermissionUtil\Helpers\PermissionUtil
14
     */
15
    protected $permission;
16
17
    /**
18
     * Create a new filter instance.
19
     *
20
     */
21 2
    public function __construct(Container $app)
22
    {
23 2
        $this->app        = $app;
24 2
        $this->permission = $app->make('permission-util');
25
    }
26
27
    /**
28
     * Handle an incoming request.
29
     *
30
     * @param  \Illuminate\Http\Request $request
31
     * @param  \Closure $next
32
     * @return mixed
33
     */
34 2
    public function handle(Request $request, Closure $next)
35
    {
36
37 2
        if (!$this->permission->hasAccess($request->route()->getActionName()))
38
        {
39 2
            $this->app->abort(403, $this->app->make('translator')->trans('permission-util::errors.unthorized'));
40
        }
41
42 2
        return $next($request);
43
    }
44
}