Completed
Pull Request — master (#736)
by
unknown
59:12 queued 56:55
created

OAuthUserOwnerMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 40
loc 40
ccs 0
cts 8
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handle() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of OAuth 2.0 Laravel.
5
 *
6
 * (c) Luca Degasperi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LucaDegasperi\OAuth2Server\Middleware;
13
14
use Closure;
15
use League\OAuth2\Server\Exception\AccessDeniedException;
16
use LucaDegasperi\OAuth2Server\Authorizer;
17
18
/**
19
 * This is the oauth user middleware class.
20
 *
21
 * @author Vincent Klaiber <[email protected]>
22
 */
23 View Code Duplication
class OAuthUserOwnerMiddleware
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...
24
{
25
    /**
26
     * The Authorizer instance.
27
     *
28
     * @var \LucaDegasperi\OAuth2Server\Authorizer
29
     */
30
    protected $authorizer;
31
32
    /**
33
     * Create a new oauth user middleware instance.
34
     *
35
     * @param \LucaDegasperi\OAuth2Server\Authorizer $authorizer
36
     */
37
    public function __construct(Authorizer $authorizer)
38
    {
39
        $this->authorizer = $authorizer;
40
    }
41
42
    /**
43
     * Handle an incoming request.
44
     *
45
     * @param \Illuminate\Http\Request $request
46
     * @param \Closure $next
47
     *
48
     * @throws \League\OAuth2\Server\Exception\AccessDeniedException
49
     *
50
     * @return mixed
51
     */
52
    public function handle($request, Closure $next)
53
    {
54
        $this->authorizer->setRequest($request);
55
56
        if ($this->authorizer->getResourceOwnerType() !== 'user') {
57
            throw new AccessDeniedException();
58
        }
59
60
        return $next($request);
61
    }
62
}
63