Completed
Push — master ( 55e392...61eb83 )
by Ryan
02:30
created

CheckSecurity   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 15.94 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 1
cbo 1
dl 11
loc 69
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A handle() 0 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 namespace Anomaly\UsersModule\Http\Middleware;
2
3
use Anomaly\UsersModule\User\UserSecurity;
4
use Closure;
5
use Illuminate\Contracts\Auth\Guard;
6
use Illuminate\Http\Request;
7
use Illuminate\Routing\Redirector;
8
use Illuminate\Routing\ResponseFactory;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Class CheckSecurityRequest
13
 *
14
 * This class replaces the Laravel version in app/
15
 *
16
 * @link          http://pyrocms.com/
17
 * @author        PyroCMS, Inc. <[email protected]>
18
 * @author        Ryan Thompson <[email protected]>
19
 * @package       Anomaly\UsersModule\Http\Middleware
20
 */
21
class CheckSecurity
22
{
23
24
    /**
25
     * The Guard implementation.
26
     *
27
     * @var Guard
28
     */
29
    protected $guard;
30
31
    /**
32
     * The security utility.
33
     *
34
     * @var UserSecurity
35
     */
36
    protected $security;
37
38
    /**
39
     * The response factory.
40
     *
41
     * @var ResponseFactory
42
     */
43
    protected $response;
44
45
    /**
46
     * The redirector utility.
47
     *
48
     * @var Redirector
49
     */
50
    protected $redirect;
51
52
    /**
53
     * Create a new CheckSecurityRequest instance.
54
     *
55
     * @param Guard           $guard
56
     * @param Redirector      $redirect
57
     * @param ResponseFactory $response
58
     * @param UserSecurity    $security
59
     */
60 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method 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...
61
        Guard $guard,
62
        Redirector $redirect,
63
        ResponseFactory $response,
64
        UserSecurity $security
65
    ) {
66
        $this->guard    = $guard;
67
        $this->redirect = $redirect;
68
        $this->response = $response;
69
        $this->security = $security;
70
    }
71
72
    /**
73
     * Handle an incoming request.
74
     *
75
     * @param  \Illuminate\Http\Request $request
76
     * @param  \Closure                 $next
77
     * @return mixed
78
     */
79
    public function handle(Request $request, Closure $next)
80
    {
81
        $response = $this->security->check($this->guard->user());
82
83
        if ($response instanceof Response) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\HttpFoundation\Response does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
84
            return $response;
85
        }
86
87
        return $next($request);
88
    }
89
}
90