Permission::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 4
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 Longman\Platfourm\Contracts\Auth\AuthUserService as AuthUserServiceContract;
15
16 View Code Duplication
class Permission
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * The Guard implementation.
20
     *
21
     * @var Guard
22
     */
23
    protected $authService;
24
25
    /**
26
     * Create a new filter instance.
27
     *
28
     * @param  Guard $auth
0 ignored issues
show
Bug introduced by
There is no parameter named $auth. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
29
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
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<Longman\Platfourm\Auth\Middleware\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                           $permissions
42
     * @return mixed
43
     */
44
    public function handle($request, Closure $next, $permissions)
45
    {
46
        if ($this->authService->guest() || !$request->user()->can(explode('|', $permissions))) {
47
            if ($request->wantsJson()) {
48
                return response('Forbidden.', 403);
49
            } else {
50
                abort(403);
51
            }
52
        }
53
54
        return $next($request);
55
    }
56
}
57