Ability::__construct()   A
last analyzed

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
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Auth\Middleware;
12
13
use Closure;
14
use Illuminate\Contracts\Auth\Guard;
15
use Longman\Platfourm\Contracts\Auth\AuthUserService as AuthUserServiceContract;
16
17
class Ability
18
{
19
    /**
20
     * The Guard implementation.
21
     *
22
     * @var Guard
23
     */
24
    protected $authService;
25
26
    /**
27
     * Create a new filter instance.
28
     *
29
     * @param  \Longman\Platfourm\Contracts\Auth\AuthUserService $authService
30
     */
31
    public function __construct(AuthUserServiceContract $authService)
32
    {
33
        $this->authService = $authService;
0 ignored issues
show
Documentation Bug introduced by
It seems like $authService of type object<Longman\Platfourm...s\Auth\AuthUserService> is incompatible with the declared type object<Illuminate\Contracts\Auth\Guard> of property $authService.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    /**
37
     * Handle an incoming request.
38
     *
39
     * @param \Illuminate\Http\Request $request
40
     * @param Closure                  $next
41
     * @param                          $roles
42
     * @param                          $permissions
43
     * @param bool                     $validateAll
44
     * @return mixed
45
     */
46
    public function handle($request, Closure $next, $roles, $permissions, $validateAll = false)
47
    {
48
        if ($this->authService->guest() || !$request->user()->ability(
49
            explode('|', $roles),
50
            explode('|', $permissions),
51
            array('validate_all' => $validateAll)
52
        )
53
        ) {
54
            if ($request->wantsJson()) {
55
                return response('Forbidden.', 403);
56
            } else {
57
                abort(403);
58
            }
59
        }
60
61
        return $next($request);
62
    }
63
}
64