GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 928b67...8d8dff )
by Renato
12:32
created

MaintenanceModeMiddleware::getIp()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
1
<?php
2
3
namespace Rdehnhardt\MaintenanceMode\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Foundation\Application;
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Response;
9
use Rdehnhardt\MaintenanceMode\MaintenanceModeService;
10
11
class MaintenanceModeMiddleware
12
{
13
    /**
14
     * Maintenance Mode Service.
15
     *
16
     * @var \Rdehnhardt\MaintenanceMode\MaintenanceModeService
17
     */
18
    protected $maintenance;
19
20
    /**
21
     * Lumen Application Instance.
22
     *
23
     * @var \Laravel\Lumen\Application
24
     */
25
    protected $app;
26
27
    /**
28
     * View Factory.
29
     *
30
     * @var \Illuminate\View\Factory
31
     */
32
    protected $view;
33
34
    public function __construct(MaintenanceModeService $maintenance, Application $app)
35
    {
36
        $this->maintenance = $maintenance;
37
        $this->app = $app;
0 ignored issues
show
Documentation Bug introduced by
It seems like $app of type object<Illuminate\Contra...Foundation\Application> is incompatible with the declared type object<Laravel\Lumen\Application> of property $app.

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...
38
        $this->view = $app['view'];
39
    }
40
41
    /**
42
     * Handle incoming requests.
43
     *
44
     * @param Request $request
45
     * @param \Closure $next
46
     *
47
     * @return \Symfony\Component\HttpFoundation\Response
48
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
49
     * @throws \InvalidArgumentException
50
     */
51
    public function handle($request, Closure $next)
52
    {
53
        if ($this->maintenance->isDownMode() && !$this->maintenance->checkAllowedIp($this->getIp())) {
54
            if ($this->view->exists('errors.503')) {
55
                return new Response($this->view->make('errors.503'), 503);
56
            }
57
58
            return $this->app->abort(503, 'The application is down for maintenance.');
59
        }
60
61
        return $next($request);
62
    }
63
64
    /**
65
     * Get client ip
66
     */
67
    private function getIp()
0 ignored issues
show
Coding Style introduced by
getIp uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
68
    {
69
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
70
            return $_SERVER['HTTP_CLIENT_IP'];
71
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
72
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
73
        } else {
74
            return $_SERVER['REMOTE_ADDR'];
75
        }
76
    }
77
}
78